001/*
002 * Copyright 2025 devteam@scivicslab.com
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing,
011 * software distributed under the License is distributed on an
012 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
013 * either express or implied.  See the License for the
014 * specific language governing permissions and limitations
015 * under the License.
016 */
017
018package com.scivicslab.actoriac.mixin;
019
020import java.io.IOException;
021
022import com.scivicslab.actoriac.Node;
023
024/**
025 * Command executor that executes commands on a remote node via SSH.
026 *
027 * <p>Delegates all operations to the wrapped {@link Node} instance.</p>
028 *
029 * @author devteam@scivicslab.com
030 * @since 2.15.0
031 */
032public class SshCommandExecutor implements CommandExecutor {
033
034    private final Node node;
035
036    /**
037     * Constructs an SSH command executor wrapping the given node.
038     *
039     * @param node the node to execute commands on
040     */
041    public SshCommandExecutor(Node node) {
042        this.node = node;
043    }
044
045    @Override
046    public Node.CommandResult execute(String command) throws IOException {
047        return node.executeCommand(command);
048    }
049
050    @Override
051    public Node.CommandResult execute(String command, Node.OutputCallback callback) throws IOException {
052        return node.executeCommand(command, callback);
053    }
054
055    @Override
056    public Node.CommandResult executeSudo(String command) throws IOException {
057        return node.executeSudoCommand(command);
058    }
059
060    @Override
061    public Node.CommandResult executeSudo(String command, Node.OutputCallback callback) throws IOException {
062        return node.executeSudoCommand(command, callback);
063    }
064
065    @Override
066    public String getIdentifier() {
067        return node.getHostname();
068    }
069
070    /**
071     * Gets the wrapped Node instance.
072     *
073     * @return the node
074     */
075    public Node getNode() {
076        return node;
077    }
078}