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@scivics-lab.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 TypeFieldDescriptionSet of changed document names detected by workflow.private StringThe current vertex 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, currentVertexIndex, 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.executeSudoCommand(String command) Executes a command with sudo privileges on the remote node.Gets all changed document names.intGets the number of changed documents.Returns the current vertex 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.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 voidonEnterVertex(com.scivicslab.pojoactor.workflow.Vertex vertex) Hook called when entering a vertex during workflow execution.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.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, findNextMatchingVertex, generateChildName, getCode, getCurrentState, getCurrentVertexIndex, 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. -
currentVertexYaml
The current vertex 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.
-
-
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
-
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
-
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
-
onEnterVertex
Hook called when entering a vertex during workflow execution.Displays the workflow name and first 10 lines of the vertex definition in YAML format using cowsay to provide visual separation between workflow steps.
- Overrides:
onEnterVertexin classcom.scivicslab.pojoactor.workflow.Interpreter- Parameters:
vertex- the vertex being entered
-
getCurrentVertexYaml
Returns the current vertex YAML snippet for accumulator reporting.- Returns:
- the first 10 lines of the current vertex 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
-