Class NodeInterpreter
This class extends Interpreter to provide workflow execution
capabilities while delegating SSH operations to a wrapped Node instance.
This demonstrates the three-level architecture of actor-IaC:
- Level 1 (POJO):
Node- pure POJO with SSH functionality - Level 2 (Actor): ActorRef<Node> - actor wrapper for concurrent execution
- Level 3 (Workflow): NodeInterpreter - workflow capabilities + IIActorRef wrapper
Design principle: Node remains a pure POJO, independent of ActorSystem. NodeInterpreter wraps Node to add workflow capabilities without modifying the Node class.
- Author:
- devteam@scivicslab.com
-
Nested Class Summary
Nested classes/interfaces inherited from class com.scivicslab.pojoactor.workflow.Interpreter
com.scivicslab.pojoactor.workflow.Interpreter.Builder -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate IaCStreamingAccumulatorIaCStreamingAccumulator for cowsay display.Set of changed document names detected by workflow.private StringThe current transition YAML snippet (first 10 lines) for accumulator reporting.private static final Loggerprivate final NodeThe wrapped Node POJO that handles actual SSH operations.private StringThe overlay directory path for YAML overlay feature.Fields inherited from class com.scivicslab.pojoactor.workflow.Interpreter
code, currentState, currentTransitionIndex, selfActorRef, system, workflowBaseDir -
Constructor Summary
ConstructorsConstructorDescriptionNodeInterpreter(Node node, com.scivicslab.pojoactor.workflow.IIActorSystem system) Constructs a NodeInterpreter that wraps the specified Node. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddChangedDocument(String docName) Adds a document to the changed list (for testing or manual override).com.scivicslab.pojoactor.core.ActionResultbuildChangedDocuments(String docListPath) Builds changed Docusaurus documents.private StringcheckGitStatus(Path docPath) Checks git status for a document directory.voidClears the changed documents list.com.scivicslab.pojoactor.core.ActionResultcloneChangedDocuments(String docListPath) Clones changed documents from git.com.scivicslab.pojoactor.core.ActionResultdeployChangedDocuments(String docListPath) Copies changed document builds to public_html.com.scivicslab.pojoactor.core.ActionResultdetectDocumentChanges(String docListPath) Detects changed documents and stores them in POJO state.executeCommand(String command) Executes a command on the remote node via SSH.executeCommand(String command, Node.OutputCallback callback) Executes a command on the remote node via SSH with real-time output callback.executeSudoCommand(String command) Executes a command with sudo privileges on the remote node.executeSudoCommand(String command, Node.OutputCallback callback) Executes a command with sudo privileges on the remote node with real-time output callback.Gets the IaCStreamingAccumulator for cowsay display.Gets all changed document names.intGets the number of changed documents.Returns the current transition YAML snippet for accumulator reporting.Gets the hostname of the node.getNode()Gets the wrapped Node instance.Gets the overlay directory path.intgetPort()Gets the SSH port.private StringgetTransitionNote(com.scivicslab.pojoactor.workflow.Transition transition) transitionのnoteを取得する。60文字または最初の行までに制限。 noteがない場合は空文字列を返す。getUser()Gets the username for SSH connections.booleanChecks if there are any changed documents to process.booleanisDocumentChanged(String docName) Checks if a specific document is in the changed list.protected voidonEnterTransition(com.scivicslab.pojoactor.workflow.Transition transition) Hook called when entering a transition during workflow execution.protected voidonExitTransition(com.scivicslab.pojoactor.workflow.Transition transition, boolean success, com.scivicslab.pojoactor.core.ActionResult result) Hook called after a transition completes (success or failure).private StringrunGitCommand(Path workDir, String... command) Runs a git command and returns the output.com.scivicslab.pojoactor.core.ActionResultrunWorkflow(String workflowFile, int maxIterations) Loads and runs a workflow file to completion with overlay support.voidsetAccumulator(IaCStreamingAccumulator accumulator) Sets the IaCStreamingAccumulator for cowsay display.voidsetOverlayDir(String overlayDir) Sets the overlay directory for YAML overlay feature.Methods inherited from class com.scivicslab.pojoactor.workflow.Interpreter
action, addToAccumulator, addToAccumulator, apply, call, execCode, findMatchingActors, findMatchingChildActors, findNextMatchingTransition, generateChildName, getCode, getCurrentState, getCurrentTransitionIndex, getToState, getWorkflowBaseDir, hasCodeLoaded, loadWorkflowFromClasspath, matchesCurrentState, matchesStatePattern, readJson, readXml, readYaml, readYaml, readYaml, removeChildActor, reset, runUntilEnd, runUntilEnd, runWorkflow, setCode, setSelfActorRef, setWorkflowBaseDir, transitionTo
-
Field Details
-
logger
-
node
-
overlayDir
The overlay directory path for YAML overlay feature. -
currentTransitionYaml
The current transition YAML snippet (first 10 lines) for accumulator reporting. -
changedDocuments
Set of changed document names detected by workflow. This replaces the /tmp/changed_docs.txt file-based approach. -
accumulator
IaCStreamingAccumulator for cowsay display. When set, workflow step transitions are displayed using cowsay.
-
-
Constructor Details
-
NodeInterpreter
Constructs a NodeInterpreter that wraps the specified Node.- Parameters:
node- theNodeinstance to wrapsystem- the actor system for workflow execution
-
-
Method Details
-
executeCommand
Executes a command on the remote node via SSH.Delegates to the wrapped
Node.executeCommand(String)method.- Parameters:
command- the command to execute- Returns:
- the result of the command execution
- Throws:
IOException- if SSH connection fails
-
executeCommand
public Node.CommandResult executeCommand(String command, Node.OutputCallback callback) throws IOException Executes a command on the remote node via SSH with real-time output callback.Delegates to the wrapped
Node.executeCommand(String, Node.OutputCallback)method.- Parameters:
command- the command to executecallback- the callback for real-time output (may be null)- Returns:
- the result of the command execution
- Throws:
IOException- if SSH connection fails
-
executeSudoCommand
Executes a command with sudo privileges on the remote node.Delegates to the wrapped
Node.executeSudoCommand(String)method. Requires SUDO_PASSWORD environment variable to be set.- Parameters:
command- the command to execute with sudo- Returns:
- the result of the command execution
- Throws:
IOException- if SSH connection fails or SUDO_PASSWORD is not set
-
executeSudoCommand
public Node.CommandResult executeSudoCommand(String command, Node.OutputCallback callback) throws IOException Executes a command with sudo privileges on the remote node with real-time output callback.Delegates to the wrapped
Node.executeSudoCommand(String, Node.OutputCallback)method. Requires SUDO_PASSWORD environment variable to be set.- Parameters:
command- the command to execute with sudocallback- the callback for real-time output (may be null)- Returns:
- the result of the command execution
- Throws:
IOException- if SSH connection fails or SUDO_PASSWORD is not set
-
getHostname
-
getUser
-
getPort
-
getNode
-
setOverlayDir
Sets the overlay directory for YAML overlay feature.- Parameters:
overlayDir- the path to the overlay directory containing overlay-conf.yaml
-
getOverlayDir
Gets the overlay directory path.- Returns:
- the overlay directory path, or null if not set
-
setAccumulator
Sets the IaCStreamingAccumulator for cowsay display.- Parameters:
accumulator- the accumulator to use for cowsay display
-
getAccumulator
Gets the IaCStreamingAccumulator for cowsay display.- Returns:
- the cowsay accumulator, or null if not set
-
onEnterTransition
Hook called when entering a transition during workflow execution.Displays the workflow name and first 10 lines of the transition definition in YAML format using cowsay to provide visual separation between workflow steps.
- Overrides:
onEnterTransitionin classcom.scivicslab.pojoactor.workflow.Interpreter- Parameters:
transition- the transition being entered
-
onExitTransition
protected void onExitTransition(com.scivicslab.pojoactor.workflow.Transition transition, boolean success, com.scivicslab.pojoactor.core.ActionResult result) Hook called after a transition completes (success or failure).Logs the transition result to the outputMultiplexer for workflow execution reporting.
- Overrides:
onExitTransitionin classcom.scivicslab.pojoactor.workflow.Interpreter- Parameters:
transition- the transition that was attemptedsuccess- true if the transition succeeded, false if it failedresult- the ActionResult from executing the transition's actions
-
getTransitionNote
transitionのnoteを取得する。60文字または最初の行までに制限。 noteがない場合は空文字列を返す。 -
getCurrentTransitionYaml
Returns the current transition YAML snippet for accumulator reporting.- Returns:
- the first 10 lines of the current transition in YAML format
-
runWorkflow
public com.scivicslab.pojoactor.core.ActionResult runWorkflow(String workflowFile, int maxIterations) Loads and runs a workflow file to completion with overlay support.If overlayDir is set, the workflow is loaded with overlay applied. Variables defined in overlay-conf.yaml are substituted before execution.
- Overrides:
runWorkflowin classcom.scivicslab.pojoactor.workflow.Interpreter- Parameters:
workflowFile- the workflow file path (YAML or JSON)maxIterations- maximum number of state transitions allowed- Returns:
- ActionResult with success=true if completed, false otherwise
-
detectDocumentChanges
public com.scivicslab.pojoactor.core.ActionResult detectDocumentChanges(String docListPath) throws IOException Detects changed documents and stores them in POJO state.This method replaces the shell script that wrote to /tmp/changed_docs.txt. It reads the document list, checks git status for each, and stores changed document names in the changedDocuments set.
- Parameters:
docListPath- path to the document list file- Returns:
- ActionResult with detection summary
- Throws:
IOException- if file operations fail
-
checkGitStatus
Checks git status for a document directory.- Parameters:
docPath- path to the document directory- Returns:
- status string like "[CHANGED]", "[UP-TO-DATE]", or "[UNKNOWN]"
-
runGitCommand
Runs a git command and returns the output. -
isDocumentChanged
Checks if a specific document is in the changed list.- Parameters:
docName- the document name to check- Returns:
- true if the document was detected as changed
-
getChangedDocumentsCount
Gets the number of changed documents.- Returns:
- the count of changed documents
-
getChangedDocuments
Gets all changed document names.- Returns:
- unmodifiable set of changed document names
-
hasChangedDocuments
Checks if there are any changed documents to process.- Returns:
- true if at least one document needs processing
-
clearChangedDocuments
Clears the changed documents list. -
addChangedDocument
Adds a document to the changed list (for testing or manual override).- Parameters:
docName- the document name to add
-
cloneChangedDocuments
public com.scivicslab.pojoactor.core.ActionResult cloneChangedDocuments(String docListPath) throws IOException Clones changed documents from git.Only clones documents that are in the changedDocuments set. Removes existing directory and does fresh clone to avoid conflicts.
- Parameters:
docListPath- path to the document list file- Returns:
- ActionResult with clone summary
- Throws:
IOException- if operations fail
-
buildChangedDocuments
public com.scivicslab.pojoactor.core.ActionResult buildChangedDocuments(String docListPath) throws IOException Builds changed Docusaurus documents.Only builds documents that are in the changedDocuments set.
- Parameters:
docListPath- path to the document list file- Returns:
- ActionResult with build summary
- Throws:
IOException- if operations fail
-
deployChangedDocuments
public com.scivicslab.pojoactor.core.ActionResult deployChangedDocuments(String docListPath) throws IOException Copies changed document builds to public_html.Only copies documents that are in the changedDocuments set.
- Parameters:
docListPath- path to the document list file- Returns:
- ActionResult with copy summary
- Throws:
IOException- if operations fail
-