/version

GET ASYNC

Gets the software version of each server in the RAIDA network.

GET /api/v1/version
Alias: /get-raida-server-versions

Description

This endpoint initiates a check across the entire RAIDA network to retrieve the software version of each of the 25 servers. Because this operation involves making multiple parallel network requests, it is handled as an asynchronous task to avoid long waiting times on the client side.

Asynchronous Operation

This is an asynchronous API call. It creates a task to perform the network queries in the background and returns a task ID immediately. You must poll the /tasks/{id} endpoint to get the final result.

Request

This endpoint does not require any URL parameters or request body.

Response

Upon successful completion of the task, the task status endpoint will return a `200 OK` response. The `data` field within the payload will contain an array of objects, each representing a RAIDA server and its version.

Response Properties (for each object in the `data` array)

raida_indexinteger
The index of the RAIDA server, from 0 to 24.
versionstring
The version string reported by that RAIDA server.
statusstring
The result of the query for this specific server (e.g., "pass", "fail").

Example Response (from task endpoint after completion)

{
    "status": "success",
    "payload": {
        "id": "b2c3d4e5-f6g7-8901-2345-67890abcdef1",
        "status": "completed",
        "progress": 100,
        "message": "Command Completed",
        "data": [
            { "raida_index": 0, "version": "2.0.1", "status": "pass" },
            { "raida_index": 1, "version": "2.0.1", "status": "pass" },
            { "raida_index": 2, "version": "2.0.1", "status": "pass" }
        ]
    }
}

Examples

JavaScript Example

const apiHost = 'http://localhost:8006';

async function pollTask(taskId) {
    const response = await fetch(`${apiHost}/api/v1/tasks/${taskId}`);
    const taskData = await response.json();
    const task = taskData.payload;

    console.log(`Task ${taskId} progress: ${task.progress}% - ${task.message}`);

    if (task.status === 'completed') {
        console.log('RAIDA Version Check Complete:');
        task.data.forEach(raida => {
            console.log(`  RAIDA #${raida.raida_index}: Version ${raida.version} (${raida.status})`);
        });
        return true;
    } else if (task.status === 'error') {
        console.error('Task failed:', task.message);
        return true;
    }
    return false;
}

async function checkRaidaVersions() {
    try {
        const response = await fetch(`${apiHost}/api/v1/version`);
        const taskInfo = await response.json();
        const taskId = taskInfo.payload.id;
        console.log(`Version check task created with ID: ${taskId}`);

        const pollInterval = setInterval(async () => {
            const isDone = await pollTask(taskId);
            if (isDone) {
                clearInterval(pollInterval);
            }
        }, 2000);
    } catch (error) {
        console.error('Error initiating version check:', error);
    }
}

checkRaidaVersions();

cURL Example

# Step 1: Initiate the version check task
TASK_ID=$(curl -s -X GET "http://localhost:8006/api/v1/version" | jq -r '.payload.id')
echo "Version check task started with ID: $TASK_ID"

# Step 2: Poll the task endpoint until finished
while true; do
  RESPONSE=$(curl -s "http://localhost:8006/api/v1/tasks/$TASK_ID")
  STATUS=$(echo $RESPONSE | jq -r '.payload.status')
  echo "Polling task.. Status: $STATUS"
  
  if [[ "$STATUS" == "completed" ]] || [[ "$STATUS" == "error" ]]; then
    echo "Final Response:"
    echo $RESPONSE | jq
    break
  fi
  
  sleep 2
done

Go Example

package main

import (
    "encoding/json"
    "fmt"
    "log"
    "net/http"
    "time"
)

const apiHost = "http://localhost:8006/api/v1"

type TaskResponse struct {
    Payload struct {
        ID       string      `json:"id"`
        Status   string      `json:"status"`
        Progress int         `json:"progress"`
        Message  string      `json:"message"`
        Data     interface{} `json:"data"`
    } `json:"payload"`
}

func pollTask(taskId string) {
    for {
        resp, err := http.Get(fmt.Sprintf("%s/tasks/%s", apiHost, taskId))
        if err != nil {
            log.Printf("Error polling task: %v\n", err)
            return
        }
        defer resp.Body.Close()

        var taskResp TaskResponse
        json.NewDecoder(resp.Body).Decode(&taskResp)

        fmt.Printf("Polling... Status: %s, Progress: %d%%\n", taskResp.Payload.Status, taskResp.Payload.Progress)

        if taskResp.Payload.Status == "completed" {
            fmt.Printf("Task completed successfully.\nResult: %+v\n", taskResp.Payload.Data)
            return
        } else if taskResp.Payload.Status == "error" {
            fmt.Printf("Task failed: %s\n", taskResp.Payload.Message)
            return
        }
        time.Sleep(2 * time.Second)
    }
}

func checkRaidaVersions() {
    resp, err := http.Get(fmt.Sprintf("%s/version", apiHost))
    if err != nil {
        log.Fatalf("Failed to start version check: %v", err)
    }
    defer resp.Body.Close()

    var taskResp TaskResponse
    if err := json.NewDecoder(resp.Body).Decode(&taskResp); err != nil {
        log.Fatalf("Failed to decode initial task response: %v", err)
    }
    
    fmt.Printf("Version check task created with ID: %s\n", taskResp.Payload.ID)
    pollTask(taskResp.Payload.ID)
}

func main() {
    checkRaidaVersions()
}