This repository was archived by the owner on Feb 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Added custom scripts functionality for plugins with the cli(…
…Deprecate custom scripts) (#517)
- Loading branch information
1 parent
07ac9b7
commit c98df7d
Showing
16 changed files
with
284 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,71 @@ | ||
from aztk.error import InvalidPluginConfigurationError, InvalidModelError | ||
import os | ||
|
||
from aztk.error import InvalidModelError | ||
from aztk.internal import ConfigurationBase | ||
from aztk.models import PluginConfiguration | ||
from aztk.models.plugins import PluginFile, PluginTarget, PluginTargetRole | ||
|
||
from .plugin_manager import plugin_manager | ||
|
||
|
||
class PluginReference(ConfigurationBase): | ||
""" | ||
Contains the configuration to use a plugin | ||
Args: | ||
name (str): Name of the plugin(Must be the name of one of the provided plugins if no script provided) | ||
script (str): Path to a custom script to run as the plugin | ||
target_role (PluginTarget): Target for the plugin. Default to SparkContainer. | ||
This can only be used if providing a script | ||
target_role (PluginTargetRole): Target role default to All nodes. This can only be used if providing a script | ||
args: (dict): If using name this is the arguments to pass to the plugin | ||
""" | ||
def __init__(self, name, args: dict = None): | ||
def __init__(self, | ||
name: str = None, | ||
script: str = None, | ||
target: PluginTarget = None, | ||
target_role: PluginTargetRole = None, | ||
args: dict = None): | ||
super().__init__() | ||
self.name = name | ||
self.script = script | ||
self.target = target | ||
self.target_role = target_role | ||
self.args = args or dict() | ||
|
||
@classmethod | ||
def _from_dict(cls, args: dict): | ||
if "target" in args: | ||
args["target"] = PluginTarget(args["target"]) | ||
if "target_role" in args: | ||
args["target_role"] = PluginTargetRole(args["target_role"]) | ||
|
||
return super()._from_dict(args) | ||
|
||
def get_plugin(self) -> PluginConfiguration: | ||
self.validate() | ||
|
||
if self.script: | ||
return self._plugin_from_script() | ||
|
||
return plugin_manager.get_plugin(self.name, self.args) | ||
|
||
def validate(self) -> bool: | ||
if not self.name: | ||
raise InvalidModelError("Plugin is missing a name") | ||
if not self.name and not self.script: | ||
raise InvalidModelError("Plugin must either specify a name of an existing plugin or the path to a script.") | ||
|
||
if self.script and not os.path.isfile(self.script): | ||
raise InvalidModelError("Plugin script file doesn't exists: '{0}'".format(self.script)) | ||
|
||
def _plugin_from_script(self): | ||
script_filename = os.path.basename(self.script) | ||
name = self.name or os.path.splitext(script_filename)[0] | ||
return PluginConfiguration( | ||
name=name, | ||
execute=script_filename, | ||
target=self.target, | ||
target_role=self.target_role or PluginConfiguration, | ||
files=[ | ||
PluginFile(script_filename, self.script), | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import argparse | ||
import os | ||
import typing | ||
|
||
import aztk.spark | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.