Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
MathieuMoalic committed Oct 3, 2024
1 parent c1ea367 commit 121cb4f
Show file tree
Hide file tree
Showing 108 changed files with 532 additions and 743 deletions.
38 changes: 0 additions & 38 deletions frontend/README.md

This file was deleted.

4 changes: 2 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ build-frontend:
docker.io/node:18.20.4-alpine3.20 -c 'npm install && npm run build && mv dist ../src/api/static'

build:
podman run --rm -v $PWD:/src matmoa/amumax:build
podman run --rm -v $PWD/src:/src matmoa/amumax:build

test:
podman run --rm -v $PWD:/src -it --device=nvidia.com/gpu=all -p 35367:35367 matmoa/amumax:build /src/build/amumax -d -i /src/mytest/t2.mx3
podman run --rm -v $PWD/src:/src -it --device=nvidia.com/gpu=all -p 35367:35367 matmoa/amumax:build /src/build/amumax -d -i /src/mytest/t2.mx3

release: image build_cuda build-frontend build
VERSION=$(date -u +'%Y.%m.%d') && \
Expand Down
12 changes: 6 additions & 6 deletions src/api/echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"strconv"
"time"

"github.com/MathieuMoalic/amumax/src/log"
"github.com/MathieuMoalic/amumax/src/script"
"github.com/MathieuMoalic/amumax/src/util"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
)
Expand Down Expand Up @@ -75,9 +75,9 @@ func startGuiServer(e *echo.Echo, host string, port int, tunnel string) {
// Find an available port
addr, port, err := findAvailablePort(host, port)
if err != nil {
util.Log.ErrAndExit("Failed to find available port: %v", err)
log.Log.ErrAndExit("Failed to find available port: %v", err)
}
util.Log.Info("Serving the web UI at http://%s", addr)
log.Log.Info("Serving the web UI at http://%s", addr)

if tunnel != "" {
go startTunnel(tunnel)
Expand All @@ -95,17 +95,17 @@ func startGuiServer(e *echo.Echo, host string, port int, tunnel string) {
continue
}
// If the error is not related to the port being busy, exit
util.Log.Err("Failed to start server: %v", err)
log.Log.Err("Failed to start server: %v", err)
break
}

// If the server started successfully, break out of the loop
util.Log.Info("Successfully started server at http://%s", addr)
log.Log.Info("Successfully started server at http://%s", addr)
return
}

// If the loop completes without successfully starting the server
util.Log.Err("Failed to start server after multiple attempts")
log.Log.Err("Failed to start server after multiple attempts")
}

func findAvailablePort(host string, startPort int) (string, string, error) {
Expand Down
4 changes: 2 additions & 2 deletions src/api/sec_console.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strings"

"github.com/MathieuMoalic/amumax/src/engine"
"github.com/MathieuMoalic/amumax/src/util"
"github.com/MathieuMoalic/amumax/src/log"
"github.com/labstack/echo/v4"
)

Expand All @@ -15,7 +15,7 @@ type Console struct {

func newConsole() *Console {
return &Console{
Hist: util.Log.Hist,
Hist: log.Log.Hist,
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/api/sec_parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"net/http"

"github.com/MathieuMoalic/amumax/src/engine"
"github.com/MathieuMoalic/amumax/src/util"
"github.com/MathieuMoalic/amumax/src/log"
"github.com/labstack/echo/v4"
)

Expand Down Expand Up @@ -59,7 +59,7 @@ func postSelectParameterRegion(c echo.Context) error {
}
req := new(Request)
if err := c.Bind(req); err != nil {
util.Log.Err("%v", err)
log.Log.Err("%v", err)
return c.JSON(http.StatusBadRequest, echo.Map{"error": "Invalid request payload"})
}

Expand Down
18 changes: 9 additions & 9 deletions src/api/sec_preview.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/MathieuMoalic/amumax/src/cuda"
"github.com/MathieuMoalic/amumax/src/data"
"github.com/MathieuMoalic/amumax/src/engine"
"github.com/MathieuMoalic/amumax/src/util"
"github.com/MathieuMoalic/amumax/src/log"
"github.com/labstack/echo/v4"
)

Expand Down Expand Up @@ -57,7 +57,7 @@ type Preview struct {
func (p *Preview) GetQuantity() engine.Quantity {
quantity, exists := engine.Quantities[p.Quantity]
if !exists {
util.Log.Err("Quantity not found: %v", p.Quantity)
log.Log.Err("Quantity not found: %v", p.Quantity)
}
return quantity
}
Expand Down Expand Up @@ -215,7 +215,7 @@ func (p *Preview) UpdateScalarField(scalarField [][][]float32) {
}
}
if len(valArray) == 0 {
util.Log.Warn("No data in scalar field")
log.Log.Warn("No data in scalar field")
}

p.Min = min
Expand Down Expand Up @@ -271,7 +271,7 @@ func compStringToIndex(comp string) int {
case "None":
return 0
}
util.Log.ErrAndExit("Invalid component string")
log.Log.ErrAndExit("Invalid component string")
return -2
}

Expand Down Expand Up @@ -304,7 +304,7 @@ func validateComponent() {
preview.Component = "3D"
}
default:
util.Log.Err("Invalid number of components")
log.Log.Err("Invalid number of components")
// reset to default
preview.Quantity = "m"
preview.Component = "3D"
Expand All @@ -317,7 +317,7 @@ func postPreviewComponent(c echo.Context) error {
}
req := new(Request)
if err := c.Bind(req); err != nil {
util.Log.Err("%v", err)
log.Log.Err("%v", err)
return c.JSON(http.StatusBadRequest, echo.Map{"error": "Invalid request payload"})
}
preview.Component = req.Component
Expand All @@ -334,7 +334,7 @@ func postPreviewQuantity(c echo.Context) error {
}
req := new(Request)
if err := c.Bind(req); err != nil {
util.Log.Err("%v", err)
log.Log.Err("%v", err)
return c.JSON(http.StatusBadRequest, echo.Map{"error": "Invalid request payload"})
}
_, exists := engine.Quantities[req.Quantity]
Expand All @@ -355,7 +355,7 @@ func postPreviewLayer(c echo.Context) error {
}
req := new(Request)
if err := c.Bind(req); err != nil {
util.Log.Err("%v", err)
log.Log.Err("%v", err)
return c.JSON(http.StatusBadRequest, echo.Map{"error": "Invalid request payload"})
}

Expand All @@ -371,7 +371,7 @@ func postPreviewMaxPoints(c echo.Context) error {
}
req := new(Request)
if err := c.Bind(req); err != nil {
util.Log.Err("%v", err)
log.Log.Err("%v", err)
return c.JSON(http.StatusBadRequest, echo.Map{"error": "Invalid request payload"})
}
if req.MaxPoints < 8 {
Expand Down
6 changes: 3 additions & 3 deletions src/api/sec_table_plot.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"net/http"

"github.com/MathieuMoalic/amumax/src/engine"
"github.com/MathieuMoalic/amumax/src/util"
"github.com/MathieuMoalic/amumax/src/log"
"github.com/labstack/echo/v4"
)

Expand Down Expand Up @@ -189,7 +189,7 @@ func postTablePlotMaxPoints(c echo.Context) error {
}
req := new(Request)
if err := c.Bind(req); err != nil {
util.Log.Err("%v", err)
log.Log.Err("%v", err)
return c.JSON(http.StatusBadRequest, echo.Map{"error": "Invalid request payload"})
}
tablePlot.MaxPoints = req.MaxPoints
Expand All @@ -204,7 +204,7 @@ func postTablePlotStep(c echo.Context) error {
}
req := new(Request)
if err := c.Bind(req); err != nil {
util.Log.Err("%v", err)
log.Log.Err("%v", err)
return c.JSON(http.StatusBadRequest, echo.Map{"error": "Invalid request payload"})
}
if req.Step < 1 {
Expand Down
28 changes: 14 additions & 14 deletions src/api/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"path/filepath"

"github.com/MathieuMoalic/amumax/src/engine"
"github.com/MathieuMoalic/amumax/src/log"
"github.com/MathieuMoalic/amumax/src/script"
"github.com/MathieuMoalic/amumax/src/util"
"github.com/kevinburke/ssh_config"
"golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/agent"
Expand Down Expand Up @@ -51,7 +51,7 @@ func loadPrivateKeys() []ssh.AuthMethod {
}
signer, err := ssh.ParsePrivateKey(key)
if err != nil {
util.Log.Debug("Error parsing private key %s: %v", keyFile, err)
log.Log.Debug("Error parsing private key %s: %v", keyFile, err)
continue
}
methods = append(methods, ssh.PublicKeys(signer))
Expand Down Expand Up @@ -85,7 +85,7 @@ func fromConfig(host string, localPort, remotePort uint16) (tunnel SSHTunnel) {

// Start the SSH reverse tunnel
func (tunnel *SSHTunnel) Start() {
util.Log.Debug("Starting SSH tunnel")
log.Log.Debug("Starting SSH tunnel")
// Create SSH config
authMethods := []ssh.AuthMethod{}

Expand All @@ -99,7 +99,7 @@ func (tunnel *SSHTunnel) Start() {

// If no SSH key is available, fallback to password authentication
if len(authMethods) == 0 {
util.Log.Err("No SSH keys found, please add one to ~/.ssh/id_rsa, ~/.ssh/id_ed25519 or use an SSH agent")
log.Log.Err("No SSH keys found, please add one to ~/.ssh/id_rsa, ~/.ssh/id_ed25519 or use an SSH agent")
}

config := &ssh.ClientConfig{
Expand All @@ -111,40 +111,40 @@ func (tunnel *SSHTunnel) Start() {
// Connect to the SSH server
sshConn, err := ssh.Dial("tcp", tunnel.SSHHost+":"+tunnel.SSHPort, config)
if err != nil {
util.Log.Err("failed to dial SSH: %v", err)
log.Log.Err("failed to dial SSH: %v", err)
return
}
defer sshConn.Close()

listener, err := sshConn.Listen("tcp", tunnel.remoteIP+":"+uint16ToString(tunnel.remotePort))
if err != nil {
util.Log.Err("failed to start reverse tunnel: %v", err)
log.Log.Err("failed to start reverse tunnel: %v", err)
return
}
defer listener.Close()
if tunnel.remotePort == 0 {
tunnel.remotePort, err = stringToUint16(strings.Split(listener.Addr().String(), ":")[1])
if err != nil {
util.Log.Err("failed to parse remote port: %v", err)
log.Log.Err("failed to parse remote port: %v", err)
return
}
}

// Retrieve the dynamically assigned port from listener.Addr()
util.Log.Info("Tunnel started: http://%s:%d -> http://%s:%d", tunnel.remoteIP, tunnel.remotePort, tunnel.remoteIP, tunnel.localPort)
log.Log.Info("Tunnel started: http://%s:%d -> http://%s:%d", tunnel.remoteIP, tunnel.remotePort, tunnel.remoteIP, tunnel.localPort)

// Handle connections
for {
clientConn, err := listener.Accept()
if err != nil {
util.Log.Debug("Error accepting connection: %v", err)
log.Log.Debug("Error accepting connection: %v", err)
continue
}

// Connect to the local WebUI (on worker)
remoteConn, err := net.Dial("tcp", net.JoinHostPort(tunnel.remoteIP, uint16ToString(tunnel.localPort)))
if err != nil {
util.Log.Debug("Error connecting to remote: %v", err)
log.Log.Debug("Error connecting to remote: %v", err)
clientConn.Close()
continue
}
Expand All @@ -168,18 +168,18 @@ func startTunnel(hostAndPort string) {
go func() {
localPort, err := getLocalPortWithRetry(5, 2*time.Second)
if err != nil {
util.Log.Err("Failed to get the local port: %v", err)
log.Log.Err("Failed to get the local port: %v", err)
return
}

remoteHost, remotePort, err := parseHostAndPort(hostAndPort)
if err != nil {
util.Log.Err("Failed to parse host and port: %v", err)
log.Log.Err("Failed to parse host and port: %v", err)
return
}
tunnel := fromConfig(remoteHost, localPort, remotePort)
if tunnel.SSHHost == "" {
util.Log.Err("No SSH host found in ~/.ssh/config for %s", remoteHost)
log.Log.Err("No SSH host found in ~/.ssh/config for %s", remoteHost)
return
}
tunnel.Start()
Expand All @@ -199,7 +199,7 @@ func getLocalPortWithRetry(maxRetries int, retryInterval time.Duration) (uint16,
return localPort, nil // Successfully retrieved the port
}
}
util.Log.Debug("Failed to get or parse port, retrying in %v...", retryInterval)
log.Log.Debug("Failed to get or parse port, retrying in %v...", retryInterval)
time.Sleep(retryInterval)
}

Expand Down
Loading

0 comments on commit 121cb4f

Please sign in to comment.