Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: get state for resource, get runner providers endpoints #1730

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions pkg/api/controllers/runner/provider/get.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2024 Daytona Platforms Inc.
// SPDX-License-Identifier: Apache-2.0

package provider

import (
"fmt"
"net/http"

"github.com/daytonaio/daytona/pkg/server"
"github.com/daytonaio/daytona/pkg/stores"
"github.com/gin-gonic/gin"
)

// GetRunnerProviders godoc
//
// @Tags provider
// @Summary Get runner providers
// @Description Get runner providers
// @Param runnerId path string true "Runner ID"
// @Produce json
// @Success 200 {array} ProviderInfo
// @Router /runner/{runnerId}/provider [get]
//
// @id GetRunnerProviders
func GetRunnerProviders(ctx *gin.Context) {
runnerId := ctx.Param("runnerId")

server := server.GetInstance(nil)

r, err := server.RunnerService.Find(ctx.Request.Context(), runnerId)
if err != nil {
statusCode := http.StatusInternalServerError
if stores.IsRunnerNotFound(err) {
statusCode = http.StatusNotFound
}
ctx.AbortWithError(statusCode, fmt.Errorf("failed to get runner: %w", err))
return
}

ctx.JSON(200, r.Metadata.Providers)
}
29 changes: 29 additions & 0 deletions pkg/api/controllers/target/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,35 @@ func FindTarget(ctx *gin.Context) {
ctx.JSON(200, t)
}

// GetTargetState godoc
//
// @Tags target
// @Summary Get target state
// @Description Get target state
// @Produce json
// @Param targetId path string true "Target ID or Name"
// @Success 200 {object} ResourceState
// @Router /target/{targetId}/state [get]
//
// @id GetTargetState
func GetTargetState(ctx *gin.Context) {
targetId := ctx.Param("targetId")

server := server.GetInstance(nil)

t, err := server.TargetService.Find(ctx.Request.Context(), &stores.TargetFilter{IdOrName: &targetId}, services.TargetRetrievalParams{})
if err != nil {
statusCode := http.StatusInternalServerError
if stores.IsTargetNotFound(err) || services.IsTargetDeleted(err) {
statusCode = http.StatusNotFound
}
ctx.AbortWithError(statusCode, fmt.Errorf("failed to find target: %w", err))
return
}

ctx.JSON(200, t.State)
}

// ListTargets godoc
//
// @Tags target
Expand Down
28 changes: 28 additions & 0 deletions pkg/api/controllers/workspace/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,34 @@ func FindWorkspace(ctx *gin.Context) {
ctx.JSON(200, w)
}

// GetWorkspaceState godoc
//
// @Tags workspace
// @Summary Get workspace state
// @Description Get workspace state
// @Produce json
// @Param workspaceId path string true "Workspace ID or Name"
// @Success 200 {object} ResourceState
// @Router /workspace/{workspaceId}/state [get]
//
// @id GetWorkspaceState
func GetWorkspaceState(ctx *gin.Context) {
workspaceId := ctx.Param("workspaceId")
server := server.GetInstance(nil)

w, err := server.WorkspaceService.Find(ctx.Request.Context(), workspaceId, services.WorkspaceRetrievalParams{})
if err != nil {
statusCode := http.StatusInternalServerError
if stores.IsWorkspaceNotFound(err) || services.IsWorkspaceDeleted(err) {
statusCode = http.StatusNotFound
}
ctx.AbortWithError(statusCode, fmt.Errorf("failed to find workspace: %w", err))
return
}

ctx.JSON(200, w.State)
}

// ListWorkspaces godoc
//
// @Tags workspace
Expand Down
93 changes: 93 additions & 0 deletions pkg/api/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,39 @@ const docTemplate = `{
}
}
},
"/runner/{runnerId}/provider": {
"get": {
"description": "Get runner providers",
"produces": [
"application/json"
],
"tags": [
"provider"
],
"summary": "Get runner providers",
"operationId": "GetRunnerProviders",
"parameters": [
{
"type": "string",
"description": "Runner ID",
"name": "runnerId",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/ProviderInfo"
}
}
}
}
}
},
"/runner/{runnerId}/provider/install": {
"post": {
"description": "Install provider",
Expand Down Expand Up @@ -1806,6 +1839,36 @@ const docTemplate = `{
}
}
},
"/target/{targetId}/state": {
"get": {
"description": "Get target state",
"produces": [
"application/json"
],
"tags": [
"target"
],
"summary": "Get target state",
"operationId": "GetTargetState",
"parameters": [
{
"type": "string",
"description": "Target ID or Name",
"name": "targetId",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/ResourceState"
}
}
}
}
},
"/target/{targetId}/stop": {
"post": {
"description": "Stop target",
Expand Down Expand Up @@ -2461,6 +2524,36 @@ const docTemplate = `{
}
}
},
"/workspace/{workspaceId}/state": {
"get": {
"description": "Get workspace state",
"produces": [
"application/json"
],
"tags": [
"workspace"
],
"summary": "Get workspace state",
"operationId": "GetWorkspaceState",
"parameters": [
{
"type": "string",
"description": "Workspace ID or Name",
"name": "workspaceId",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/ResourceState"
}
}
}
}
},
"/workspace/{workspaceId}/stop": {
"post": {
"description": "Stop workspace",
Expand Down
93 changes: 93 additions & 0 deletions pkg/api/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,39 @@
}
}
},
"/runner/{runnerId}/provider": {
"get": {
"description": "Get runner providers",
"produces": [
"application/json"
],
"tags": [
"provider"
],
"summary": "Get runner providers",
"operationId": "GetRunnerProviders",
"parameters": [
{
"type": "string",
"description": "Runner ID",
"name": "runnerId",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/ProviderInfo"
}
}
}
}
}
},
"/runner/{runnerId}/provider/install": {
"post": {
"description": "Install provider",
Expand Down Expand Up @@ -1803,6 +1836,36 @@
}
}
},
"/target/{targetId}/state": {
"get": {
"description": "Get target state",
"produces": [
"application/json"
],
"tags": [
"target"
],
"summary": "Get target state",
"operationId": "GetTargetState",
"parameters": [
{
"type": "string",
"description": "Target ID or Name",
"name": "targetId",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/ResourceState"
}
}
}
}
},
"/target/{targetId}/stop": {
"post": {
"description": "Stop target",
Expand Down Expand Up @@ -2458,6 +2521,36 @@
}
}
},
"/workspace/{workspaceId}/state": {
"get": {
"description": "Get workspace state",
"produces": [
"application/json"
],
"tags": [
"workspace"
],
"summary": "Get workspace state",
"operationId": "GetWorkspaceState",
"parameters": [
{
"type": "string",
"description": "Workspace ID or Name",
"name": "workspaceId",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/ResourceState"
}
}
}
}
},
"/workspace/{workspaceId}/stop": {
"post": {
"description": "Stop workspace",
Expand Down
Loading