From e1d7d03d543af8f22152c6102a373e8dacf83747 Mon Sep 17 00:00:00 2001 From: Toma Puljak Date: Thu, 11 Apr 2024 14:45:18 +0000 Subject: [PATCH] feat: project uptime Uptime is set periodically by the agent. Additionally, removed unnecessary properties from the ProjectInfo struct. Signed-off-by: Toma Puljak --- internal/util/time.go | 23 +-- pkg/agent/agent.go | 36 ++++ pkg/agent/types.go | 3 + pkg/api/controllers/workspace/dto/dto.go | 4 + pkg/api/controllers/workspace/project.go | 52 ++++++ pkg/api/docs/docs.go | 68 +++++++- pkg/api/docs/swagger.json | 68 +++++++- pkg/api/docs/swagger.yaml | 45 ++++- pkg/api/server.go | 10 +- pkg/db/dto/project.go | 38 ++++- pkg/server/workspaces/service.go | 17 ++ pkg/serverapiclient/README.md | 3 + pkg/serverapiclient/api/openapi.yaml | 80 +++++++-- pkg/serverapiclient/api_workspace.go | 108 ++++++++++++ pkg/serverapiclient/docs/Project.md | 26 +++ pkg/serverapiclient/docs/ProjectInfo.md | 52 ------ pkg/serverapiclient/docs/ProjectState.md | 82 +++++++++ pkg/serverapiclient/docs/SetProjectState.md | 56 ++++++ pkg/serverapiclient/docs/WorkspaceAPI.md | 74 ++++++++ pkg/serverapiclient/model_project.go | 36 ++++ pkg/serverapiclient/model_project_info.go | 72 -------- pkg/serverapiclient/model_project_state.go | 160 ++++++++++++++++++ .../model_set_project_state.go | 124 ++++++++++++++ pkg/views/workspace/list/view.go | 24 +-- pkg/views/workspace/selection/view.go | 10 +- pkg/views/workspace/selection/workspace.go | 8 +- pkg/workspace/workspace.go | 8 +- 27 files changed, 1088 insertions(+), 199 deletions(-) create mode 100644 pkg/api/controllers/workspace/project.go create mode 100644 pkg/serverapiclient/docs/ProjectState.md create mode 100644 pkg/serverapiclient/docs/SetProjectState.md create mode 100644 pkg/serverapiclient/model_project_state.go create mode 100644 pkg/serverapiclient/model_set_project_state.go diff --git a/internal/util/time.go b/internal/util/time.go index fc26bb845d..f4c9b5917c 100644 --- a/internal/util/time.go +++ b/internal/util/time.go @@ -41,33 +41,28 @@ func FormatCreatedTime(input string) string { } } -func FormatStatusTime(input string) string { - t, err := time.Parse(timeLayout, input) - if err != nil { - return "stopped" - } - - duration := time.Since(t) +func FormatUptime(uptime int32) string { + duration := time.Duration(uptime) * time.Second if duration < time.Minute { - return "up < 1 minute" + return "< 1 minute" } else if duration < time.Hour { minutes := int(duration.Minutes()) if minutes == 1 { - return "up 1 minute" + return "1 minute" } - return fmt.Sprintf("up %d minutes", minutes) + return fmt.Sprintf("%d minutes", minutes) } else if duration < 24*time.Hour { hours := int(duration.Hours()) if hours == 1 { - return "up 1 hour" + return "1 hour" } - return fmt.Sprintf("up %d hours", hours) + return fmt.Sprintf("%d hours", hours) } else { days := int(duration.Hours() / 24) if days == 1 { - return "up 1 day" + return "1 day" } - return fmt.Sprintf("up %d days", days) + return fmt.Sprintf("%d days", days) } } diff --git a/pkg/agent/agent.go b/pkg/agent/agent.go index 5d5506e610..d60135e7e6 100644 --- a/pkg/agent/agent.go +++ b/pkg/agent/agent.go @@ -8,6 +8,7 @@ import ( "errors" "fmt" "net/url" + "time" "github.com/daytonaio/daytona/cmd/daytona/config" "github.com/daytonaio/daytona/internal/util/apiclient" @@ -19,6 +20,8 @@ import ( func (a *Agent) Start() error { log.Info("Starting Daytona Agent") + a.startTime = time.Now() + err := a.setDefaultConfig() if err != nil { return err @@ -78,6 +81,17 @@ func (a *Agent) Start() error { } }() + go func() { + for { + err := a.updateProjectState() + if err != nil { + log.Error(fmt.Sprintf("failed to update project state: %s", err)) + } + + time.Sleep(2 * time.Second) + } + }() + return a.Tailscale.Start() } @@ -162,3 +176,25 @@ func (a *Agent) setDefaultConfig() error { return config.Save() } + +// Agent uptime in seconds +func (a *Agent) uptime() int32 { + return int32(time.Since(a.startTime).Seconds()) +} + +func (a *Agent) updateProjectState() error { + apiClient, err := server.GetApiClient(nil) + if err != nil { + return err + } + + uptime := a.uptime() + res, err := apiClient.WorkspaceAPI.SetProjectState(context.Background(), a.Config.WorkspaceId, a.Config.ProjectName).SetState(serverapiclient.SetProjectState{ + Uptime: &uptime, + }).Execute() + if err != nil { + return apiclient.HandleErrorResponse(res, err) + } + + return nil +} diff --git a/pkg/agent/types.go b/pkg/agent/types.go index 0b6c50c241..e0b8b233ff 100644 --- a/pkg/agent/types.go +++ b/pkg/agent/types.go @@ -4,6 +4,8 @@ package agent import ( + "time" + "github.com/daytonaio/daytona/pkg/agent/config" "github.com/daytonaio/daytona/pkg/serverapiclient" ) @@ -27,4 +29,5 @@ type Agent struct { Git GitService Ssh SshServer Tailscale TailscaleServer + startTime time.Time } diff --git a/pkg/api/controllers/workspace/dto/dto.go b/pkg/api/controllers/workspace/dto/dto.go index a04d31293f..d0dbc500bb 100644 --- a/pkg/api/controllers/workspace/dto/dto.go +++ b/pkg/api/controllers/workspace/dto/dto.go @@ -13,3 +13,7 @@ type CreateWorkspace struct { Target string Repositories []gitprovider.GitRepository } // @name CreateWorkspace + +type SetProjectState struct { + Uptime uint64 `json:"uptime"` +} // @name SetProjectState diff --git a/pkg/api/controllers/workspace/project.go b/pkg/api/controllers/workspace/project.go new file mode 100644 index 0000000000..a988f7e6b5 --- /dev/null +++ b/pkg/api/controllers/workspace/project.go @@ -0,0 +1,52 @@ +// Copyright 2024 Daytona Platforms Inc. +// SPDX-License-Identifier: Apache-2.0 + +package workspace + +import ( + "fmt" + "net/http" + "time" + + "github.com/daytonaio/daytona/pkg/api/controllers/workspace/dto" + "github.com/daytonaio/daytona/pkg/server" + "github.com/daytonaio/daytona/pkg/workspace" + "github.com/gin-gonic/gin" +) + +// SetProjectState godoc +// +// @Tags workspace +// @Summary Set project state +// @Description Set project state +// @Param workspaceId path string true "Workspace ID or Name" +// @Param projectId path string true "Project ID" +// @Param setState body SetProjectState true "Set State" +// @Success 200 +// @Router /workspace/{workspaceId}/{projectId}/state [post] +// +// @id SetProjectState +func SetProjectState(ctx *gin.Context) { + workspaceId := ctx.Param("workspaceId") + projectId := ctx.Param("projectId") + + var setProjectStateDTO dto.SetProjectState + err := ctx.BindJSON(&setProjectStateDTO) + if err != nil { + ctx.AbortWithError(http.StatusBadRequest, fmt.Errorf("invalid request body: %s", err.Error())) + return + } + + server := server.GetInstance(nil) + + _, err = server.WorkspaceService.SetProjectState(workspaceId, projectId, &workspace.ProjectState{ + Uptime: setProjectStateDTO.Uptime, + UpdatedAt: time.Now().Format(time.RFC1123), + }) + if err != nil { + ctx.AbortWithError(http.StatusInternalServerError, fmt.Errorf("failed to stop workspace %s: %s", workspaceId, err.Error())) + return + } + + ctx.Status(200) +} diff --git a/pkg/api/docs/docs.go b/pkg/api/docs/docs.go index 9e28c3a4e1..e617f9ae64 100644 --- a/pkg/api/docs/docs.go +++ b/pkg/api/docs/docs.go @@ -873,6 +873,46 @@ const docTemplate = `{ } } }, + "/workspace/{workspaceId}/{projectId}/state": { + "post": { + "description": "Set project state", + "tags": [ + "workspace" + ], + "summary": "Set project state", + "operationId": "SetProjectState", + "parameters": [ + { + "type": "string", + "description": "Workspace ID or Name", + "name": "workspaceId", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Project ID", + "name": "projectId", + "in": "path", + "required": true + }, + { + "description": "Set State", + "name": "setState", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/SetProjectState" + } + } + ], + "responses": { + "200": { + "description": "OK" + } + } + } + }, "/workspace/{workspaceId}/{projectId}/stop": { "post": { "description": "Stop project", @@ -1085,6 +1125,9 @@ const docTemplate = `{ "repository": { "$ref": "#/definitions/GitRepository" }, + "state": { + "$ref": "#/definitions/ProjectState" + }, "target": { "type": "string" }, @@ -1099,9 +1142,6 @@ const docTemplate = `{ "created": { "type": "string" }, - "finished": { - "type": "string" - }, "isRunning": { "type": "boolean" }, @@ -1111,14 +1151,22 @@ const docTemplate = `{ "providerMetadata": { "type": "string" }, - "started": { - "type": "string" - }, "workspaceId": { "type": "string" } } }, + "ProjectState": { + "type": "object", + "properties": { + "updatedAt": { + "type": "string" + }, + "uptime": { + "type": "integer" + } + } + }, "Provider": { "type": "object", "properties": { @@ -1183,6 +1231,14 @@ const docTemplate = `{ } } }, + "SetProjectState": { + "type": "object", + "properties": { + "uptime": { + "type": "integer" + } + } + }, "Workspace": { "type": "object", "properties": { diff --git a/pkg/api/docs/swagger.json b/pkg/api/docs/swagger.json index 196b362707..7979dee121 100644 --- a/pkg/api/docs/swagger.json +++ b/pkg/api/docs/swagger.json @@ -870,6 +870,46 @@ } } }, + "/workspace/{workspaceId}/{projectId}/state": { + "post": { + "description": "Set project state", + "tags": [ + "workspace" + ], + "summary": "Set project state", + "operationId": "SetProjectState", + "parameters": [ + { + "type": "string", + "description": "Workspace ID or Name", + "name": "workspaceId", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Project ID", + "name": "projectId", + "in": "path", + "required": true + }, + { + "description": "Set State", + "name": "setState", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/SetProjectState" + } + } + ], + "responses": { + "200": { + "description": "OK" + } + } + } + }, "/workspace/{workspaceId}/{projectId}/stop": { "post": { "description": "Stop project", @@ -1082,6 +1122,9 @@ "repository": { "$ref": "#/definitions/GitRepository" }, + "state": { + "$ref": "#/definitions/ProjectState" + }, "target": { "type": "string" }, @@ -1096,9 +1139,6 @@ "created": { "type": "string" }, - "finished": { - "type": "string" - }, "isRunning": { "type": "boolean" }, @@ -1108,14 +1148,22 @@ "providerMetadata": { "type": "string" }, - "started": { - "type": "string" - }, "workspaceId": { "type": "string" } } }, + "ProjectState": { + "type": "object", + "properties": { + "updatedAt": { + "type": "string" + }, + "uptime": { + "type": "integer" + } + } + }, "Provider": { "type": "object", "properties": { @@ -1180,6 +1228,14 @@ } } }, + "SetProjectState": { + "type": "object", + "properties": { + "uptime": { + "type": "integer" + } + } + }, "Workspace": { "type": "object", "properties": { diff --git a/pkg/api/docs/swagger.yaml b/pkg/api/docs/swagger.yaml index 3a3636555e..76f99b6080 100644 --- a/pkg/api/docs/swagger.yaml +++ b/pkg/api/docs/swagger.yaml @@ -116,6 +116,8 @@ definitions: type: string repository: $ref: '#/definitions/GitRepository' + state: + $ref: '#/definitions/ProjectState' target: type: string workspaceId: @@ -125,19 +127,22 @@ definitions: properties: created: type: string - finished: - type: string isRunning: type: boolean name: type: string providerMetadata: type: string - started: - type: string workspaceId: type: string type: object + ProjectState: + properties: + updatedAt: + type: string + uptime: + type: integer + type: object Provider: properties: name: @@ -180,6 +185,11 @@ definitions: serverDownloadUrl: type: string type: object + SetProjectState: + properties: + uptime: + type: integer + type: object Workspace: properties: id: @@ -825,6 +835,33 @@ paths: summary: Start project tags: - workspace + /workspace/{workspaceId}/{projectId}/state: + post: + description: Set project state + operationId: SetProjectState + parameters: + - description: Workspace ID or Name + in: path + name: workspaceId + required: true + type: string + - description: Project ID + in: path + name: projectId + required: true + type: string + - description: Set State + in: body + name: setState + required: true + schema: + $ref: '#/definitions/SetProjectState' + responses: + "200": + description: OK + summary: Set project state + tags: + - workspace /workspace/{workspaceId}/{projectId}/stop: post: description: Stop project diff --git a/pkg/api/server.go b/pkg/api/server.go index 25ed099328..932d596a19 100644 --- a/pkg/api/server.go +++ b/pkg/api/server.go @@ -80,9 +80,6 @@ func (a *ApiServer) Start() error { protected := a.router.Group("/") protected.Use(middlewares.AuthMiddleware()) - project := protected.Group("/") - project.Use(middlewares.ProjectAuthMiddleware()) - serverController := protected.Group("/server") { serverController.GET("/config", server.GetConfig) @@ -149,7 +146,12 @@ func (a *ApiServer) Start() error { apiKeyController.DELETE("/:apiKeyName", apikey.RevokeApiKey) } - project.GET(gitProviderController.BasePath()+"/for-url/:url", middlewares.ProjectAuthMiddleware(), gitprovider.GetGitProviderForUrl) + projectGroup := protected.Group("/") + projectGroup.Use(middlewares.ProjectAuthMiddleware()) + { + projectGroup.POST(workspaceController.BasePath()+"/:workspaceId/:projectId/state", workspace.SetProjectState) + projectGroup.GET(gitProviderController.BasePath()+"/for-url/:url", gitprovider.GetGitProviderForUrl) + } a.httpServer = &http.Server{ Addr: fmt.Sprintf(":%d", a.apiPort), diff --git a/pkg/db/dto/project.go b/pkg/db/dto/project.go index de10d9c728..a4376a7f2c 100644 --- a/pkg/db/dto/project.go +++ b/pkg/db/dto/project.go @@ -18,11 +18,17 @@ type RepositoryDTO struct { Path *string `json:"path,omitempty"` } +type ProjectStateDTO struct { + UpdatedAt string `json:"updatedAt"` + Uptime uint64 `json:"uptime"` +} + type ProjectDTO struct { - Name string `json:"name"` - Repository RepositoryDTO `json:"repository"` - WorkspaceId string `json:"workspaceId"` - Target string `json:"target"` + Name string `json:"name"` + Repository RepositoryDTO `json:"repository"` + WorkspaceId string `json:"workspaceId"` + Target string `json:"target"` + State *ProjectStateDTO `json:"state,omitempty" gorm:"serializer:json"` } func ToProjectDTO(project *workspace.Project, workspace *workspace.Workspace) ProjectDTO { @@ -31,6 +37,7 @@ func ToProjectDTO(project *workspace.Project, workspace *workspace.Workspace) Pr Repository: ToRepositoryDTO(project.Repository), WorkspaceId: project.WorkspaceId, Target: project.Target, + State: ToProjectStateDTO(project.State), } } @@ -55,12 +62,35 @@ func ToRepositoryDTO(repo *gitprovider.GitRepository) RepositoryDTO { return repoDTO } +func ToProjectStateDTO(state *workspace.ProjectState) *ProjectStateDTO { + if state == nil { + return nil + } + + return &ProjectStateDTO{ + UpdatedAt: state.UpdatedAt, + Uptime: state.Uptime, + } +} + func ToProject(projectDTO ProjectDTO) *workspace.Project { return &workspace.Project{ Name: projectDTO.Name, Repository: ToRepository(projectDTO.Repository), WorkspaceId: projectDTO.WorkspaceId, Target: projectDTO.Target, + State: ToProjectState(projectDTO.State), + } +} + +func ToProjectState(stateDTO *ProjectStateDTO) *workspace.ProjectState { + if stateDTO == nil { + return nil + } + + return &workspace.ProjectState{ + UpdatedAt: stateDTO.UpdatedAt, + Uptime: stateDTO.Uptime, } } diff --git a/pkg/server/workspaces/service.go b/pkg/server/workspaces/service.go index 8da79f1752..934f4ac943 100644 --- a/pkg/server/workspaces/service.go +++ b/pkg/server/workspaces/service.go @@ -4,6 +4,7 @@ package workspaces import ( + "errors" "io" "github.com/daytonaio/daytona/pkg/logger" @@ -54,3 +55,19 @@ type WorkspaceService struct { newProjectLogger func(workspaceId, projectName string) logger.Logger NewWorkspaceLogReader func(workspaceId string) (io.Reader, error) } + +func (s *WorkspaceService) SetProjectState(workspaceId, projectName string, state *workspace.ProjectState) (*workspace.Workspace, error) { + ws, err := s.workspaceStore.Find(workspaceId) + if err != nil { + return nil, err + } + + for _, project := range ws.Projects { + if project.Name == projectName { + project.State = state + return ws, s.workspaceStore.Save(ws) + } + } + + return nil, errors.New("project not found") +} diff --git a/pkg/serverapiclient/README.md b/pkg/serverapiclient/README.md index ba1441cebb..e1f2d2309f 100644 --- a/pkg/serverapiclient/README.md +++ b/pkg/serverapiclient/README.md @@ -104,6 +104,7 @@ Class | Method | HTTP request | Description *WorkspaceAPI* | [**GetWorkspace**](docs/WorkspaceAPI.md#getworkspace) | **Get** /workspace/{workspaceId} | Get workspace info *WorkspaceAPI* | [**ListWorkspaces**](docs/WorkspaceAPI.md#listworkspaces) | **Get** /workspace | List workspaces *WorkspaceAPI* | [**RemoveWorkspace**](docs/WorkspaceAPI.md#removeworkspace) | **Delete** /workspace/{workspaceId} | Remove workspace +*WorkspaceAPI* | [**SetProjectState**](docs/WorkspaceAPI.md#setprojectstate) | **Post** /workspace/{workspaceId}/{projectId}/state | Set project state *WorkspaceAPI* | [**StartProject**](docs/WorkspaceAPI.md#startproject) | **Post** /workspace/{workspaceId}/{projectId}/start | Start project *WorkspaceAPI* | [**StartWorkspace**](docs/WorkspaceAPI.md#startworkspace) | **Post** /workspace/{workspaceId}/start | Start workspace *WorkspaceAPI* | [**StopProject**](docs/WorkspaceAPI.md#stopproject) | **Post** /workspace/{workspaceId}/{projectId}/stop | Stop project @@ -126,12 +127,14 @@ Class | Method | HTTP request | Description - [NetworkKey](docs/NetworkKey.md) - [Project](docs/Project.md) - [ProjectInfo](docs/ProjectInfo.md) + - [ProjectState](docs/ProjectState.md) - [Provider](docs/Provider.md) - [ProviderProviderInfo](docs/ProviderProviderInfo.md) - [ProviderProviderTargetProperty](docs/ProviderProviderTargetProperty.md) - [ProviderProviderTargetPropertyType](docs/ProviderProviderTargetPropertyType.md) - [ProviderTarget](docs/ProviderTarget.md) - [ServerConfig](docs/ServerConfig.md) + - [SetProjectState](docs/SetProjectState.md) - [Workspace](docs/Workspace.md) - [WorkspaceDTO](docs/WorkspaceDTO.md) - [WorkspaceInfo](docs/WorkspaceInfo.md) diff --git a/pkg/serverapiclient/api/openapi.yaml b/pkg/serverapiclient/api/openapi.yaml index e32bb8043d..f600eaa0a5 100644 --- a/pkg/serverapiclient/api/openapi.yaml +++ b/pkg/serverapiclient/api/openapi.yaml @@ -614,6 +614,38 @@ paths: summary: Start project tags: - workspace + /workspace/{workspaceId}/{projectId}/state: + post: + description: Set project state + operationId: SetProjectState + parameters: + - description: Workspace ID or Name + in: path + name: workspaceId + required: true + schema: + type: string + - description: Project ID + in: path + name: projectId + required: true + schema: + type: string + requestBody: + content: + '*/*': + schema: + $ref: '#/components/schemas/SetProjectState' + description: Set State + required: true + responses: + "200": + content: {} + description: OK + summary: Set project state + tags: + - workspace + x-codegen-request-body-name: setState /workspace/{workspaceId}/{projectId}/stop: post: description: Stop project @@ -819,6 +851,9 @@ components: Project: example: name: name + state: + updatedAt: updatedAt + uptime: 0 repository: owner: owner path: path @@ -836,6 +871,8 @@ components: type: string repository: $ref: '#/components/schemas/GitRepository' + state: + $ref: '#/components/schemas/ProjectState' target: type: string workspaceId: @@ -847,25 +884,29 @@ components: isRunning: true created: created name: name - finished: finished - started: started workspaceId: workspaceId properties: created: type: string - finished: - type: string isRunning: type: boolean name: type: string providerMetadata: type: string - started: - type: string workspaceId: type: string type: object + ProjectState: + example: + updatedAt: updatedAt + uptime: 0 + properties: + updatedAt: + type: string + uptime: + type: integer + type: object Provider: example: name: name @@ -930,10 +971,20 @@ components: serverDownloadUrl: type: string type: object + SetProjectState: + example: + uptime: 0 + properties: + uptime: + type: integer + type: object Workspace: example: projects: - name: name + state: + updatedAt: updatedAt + uptime: 0 repository: owner: owner path: path @@ -947,6 +998,9 @@ components: target: target workspaceId: workspaceId - name: name + state: + updatedAt: updatedAt + uptime: 0 repository: owner: owner path: path @@ -978,6 +1032,9 @@ components: example: projects: - name: name + state: + updatedAt: updatedAt + uptime: 0 repository: owner: owner path: path @@ -991,6 +1048,9 @@ components: target: target workspaceId: workspaceId - name: name + state: + updatedAt: updatedAt + uptime: 0 repository: owner: owner path: path @@ -1011,15 +1071,11 @@ components: isRunning: true created: created name: name - finished: finished - started: started workspaceId: workspaceId - providerMetadata: providerMetadata isRunning: true created: created name: name - finished: finished - started: started workspaceId: workspaceId providerMetadata: providerMetadata name: name @@ -1045,15 +1101,11 @@ components: isRunning: true created: created name: name - finished: finished - started: started workspaceId: workspaceId - providerMetadata: providerMetadata isRunning: true created: created name: name - finished: finished - started: started workspaceId: workspaceId providerMetadata: providerMetadata name: name diff --git a/pkg/serverapiclient/api_workspace.go b/pkg/serverapiclient/api_workspace.go index 57359e30ef..a96f6f506d 100644 --- a/pkg/serverapiclient/api_workspace.go +++ b/pkg/serverapiclient/api_workspace.go @@ -440,6 +440,114 @@ func (a *WorkspaceAPIService) RemoveWorkspaceExecute(r ApiRemoveWorkspaceRequest return localVarHTTPResponse, nil } +type ApiSetProjectStateRequest struct { + ctx context.Context + ApiService *WorkspaceAPIService + workspaceId string + projectId string + setState *SetProjectState +} + +// Set State +func (r ApiSetProjectStateRequest) SetState(setState SetProjectState) ApiSetProjectStateRequest { + r.setState = &setState + return r +} + +func (r ApiSetProjectStateRequest) Execute() (*http.Response, error) { + return r.ApiService.SetProjectStateExecute(r) +} + +/* +SetProjectState Set project state + +Set project state + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param workspaceId Workspace ID or Name + @param projectId Project ID + @return ApiSetProjectStateRequest +*/ +func (a *WorkspaceAPIService) SetProjectState(ctx context.Context, workspaceId string, projectId string) ApiSetProjectStateRequest { + return ApiSetProjectStateRequest{ + ApiService: a, + ctx: ctx, + workspaceId: workspaceId, + projectId: projectId, + } +} + +// Execute executes the request +func (a *WorkspaceAPIService) SetProjectStateExecute(r ApiSetProjectStateRequest) (*http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "WorkspaceAPIService.SetProjectState") + if err != nil { + return nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/workspace/{workspaceId}/{projectId}/state" + localVarPath = strings.Replace(localVarPath, "{"+"workspaceId"+"}", url.PathEscape(parameterValueToString(r.workspaceId, "workspaceId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"projectId"+"}", url.PathEscape(parameterValueToString(r.projectId, "projectId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + if r.setState == nil { + return nil, reportError("setState is required and must be specified") + } + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + // body params + localVarPostBody = r.setState + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + return localVarHTTPResponse, newErr + } + + return localVarHTTPResponse, nil +} + type ApiStartProjectRequest struct { ctx context.Context ApiService *WorkspaceAPIService diff --git a/pkg/serverapiclient/docs/Project.md b/pkg/serverapiclient/docs/Project.md index 33965a34c4..21a2bea19f 100644 --- a/pkg/serverapiclient/docs/Project.md +++ b/pkg/serverapiclient/docs/Project.md @@ -6,6 +6,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **Name** | Pointer to **string** | | [optional] **Repository** | Pointer to [**GitRepository**](GitRepository.md) | | [optional] +**State** | Pointer to [**ProjectState**](ProjectState.md) | | [optional] **Target** | Pointer to **string** | | [optional] **WorkspaceId** | Pointer to **string** | | [optional] @@ -78,6 +79,31 @@ SetRepository sets Repository field to given value. HasRepository returns a boolean if a field has been set. +### GetState + +`func (o *Project) GetState() ProjectState` + +GetState returns the State field if non-nil, zero value otherwise. + +### GetStateOk + +`func (o *Project) GetStateOk() (*ProjectState, bool)` + +GetStateOk returns a tuple with the State field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetState + +`func (o *Project) SetState(v ProjectState)` + +SetState sets State field to given value. + +### HasState + +`func (o *Project) HasState() bool` + +HasState returns a boolean if a field has been set. + ### GetTarget `func (o *Project) GetTarget() string` diff --git a/pkg/serverapiclient/docs/ProjectInfo.md b/pkg/serverapiclient/docs/ProjectInfo.md index ec0c8d1912..b16a143ec3 100644 --- a/pkg/serverapiclient/docs/ProjectInfo.md +++ b/pkg/serverapiclient/docs/ProjectInfo.md @@ -5,11 +5,9 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **Created** | Pointer to **string** | | [optional] -**Finished** | Pointer to **string** | | [optional] **IsRunning** | Pointer to **bool** | | [optional] **Name** | Pointer to **string** | | [optional] **ProviderMetadata** | Pointer to **string** | | [optional] -**Started** | Pointer to **string** | | [optional] **WorkspaceId** | Pointer to **string** | | [optional] ## Methods @@ -56,31 +54,6 @@ SetCreated sets Created field to given value. HasCreated returns a boolean if a field has been set. -### GetFinished - -`func (o *ProjectInfo) GetFinished() string` - -GetFinished returns the Finished field if non-nil, zero value otherwise. - -### GetFinishedOk - -`func (o *ProjectInfo) GetFinishedOk() (*string, bool)` - -GetFinishedOk returns a tuple with the Finished field if it's non-nil, zero value otherwise -and a boolean to check if the value has been set. - -### SetFinished - -`func (o *ProjectInfo) SetFinished(v string)` - -SetFinished sets Finished field to given value. - -### HasFinished - -`func (o *ProjectInfo) HasFinished() bool` - -HasFinished returns a boolean if a field has been set. - ### GetIsRunning `func (o *ProjectInfo) GetIsRunning() bool` @@ -156,31 +129,6 @@ SetProviderMetadata sets ProviderMetadata field to given value. HasProviderMetadata returns a boolean if a field has been set. -### GetStarted - -`func (o *ProjectInfo) GetStarted() string` - -GetStarted returns the Started field if non-nil, zero value otherwise. - -### GetStartedOk - -`func (o *ProjectInfo) GetStartedOk() (*string, bool)` - -GetStartedOk returns a tuple with the Started field if it's non-nil, zero value otherwise -and a boolean to check if the value has been set. - -### SetStarted - -`func (o *ProjectInfo) SetStarted(v string)` - -SetStarted sets Started field to given value. - -### HasStarted - -`func (o *ProjectInfo) HasStarted() bool` - -HasStarted returns a boolean if a field has been set. - ### GetWorkspaceId `func (o *ProjectInfo) GetWorkspaceId() string` diff --git a/pkg/serverapiclient/docs/ProjectState.md b/pkg/serverapiclient/docs/ProjectState.md new file mode 100644 index 0000000000..c23028eb39 --- /dev/null +++ b/pkg/serverapiclient/docs/ProjectState.md @@ -0,0 +1,82 @@ +# ProjectState + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**UpdatedAt** | Pointer to **string** | | [optional] +**Uptime** | Pointer to **int32** | | [optional] + +## Methods + +### NewProjectState + +`func NewProjectState() *ProjectState` + +NewProjectState instantiates a new ProjectState object +This constructor will assign default values to properties that have it defined, +and makes sure properties required by API are set, but the set of arguments +will change when the set of required properties is changed + +### NewProjectStateWithDefaults + +`func NewProjectStateWithDefaults() *ProjectState` + +NewProjectStateWithDefaults instantiates a new ProjectState object +This constructor will only assign default values to properties that have it defined, +but it doesn't guarantee that properties required by API are set + +### GetUpdatedAt + +`func (o *ProjectState) GetUpdatedAt() string` + +GetUpdatedAt returns the UpdatedAt field if non-nil, zero value otherwise. + +### GetUpdatedAtOk + +`func (o *ProjectState) GetUpdatedAtOk() (*string, bool)` + +GetUpdatedAtOk returns a tuple with the UpdatedAt field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetUpdatedAt + +`func (o *ProjectState) SetUpdatedAt(v string)` + +SetUpdatedAt sets UpdatedAt field to given value. + +### HasUpdatedAt + +`func (o *ProjectState) HasUpdatedAt() bool` + +HasUpdatedAt returns a boolean if a field has been set. + +### GetUptime + +`func (o *ProjectState) GetUptime() int32` + +GetUptime returns the Uptime field if non-nil, zero value otherwise. + +### GetUptimeOk + +`func (o *ProjectState) GetUptimeOk() (*int32, bool)` + +GetUptimeOk returns a tuple with the Uptime field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetUptime + +`func (o *ProjectState) SetUptime(v int32)` + +SetUptime sets Uptime field to given value. + +### HasUptime + +`func (o *ProjectState) HasUptime() bool` + +HasUptime returns a boolean if a field has been set. + + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/pkg/serverapiclient/docs/SetProjectState.md b/pkg/serverapiclient/docs/SetProjectState.md new file mode 100644 index 0000000000..79554d12d6 --- /dev/null +++ b/pkg/serverapiclient/docs/SetProjectState.md @@ -0,0 +1,56 @@ +# SetProjectState + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**Uptime** | Pointer to **int32** | | [optional] + +## Methods + +### NewSetProjectState + +`func NewSetProjectState() *SetProjectState` + +NewSetProjectState instantiates a new SetProjectState object +This constructor will assign default values to properties that have it defined, +and makes sure properties required by API are set, but the set of arguments +will change when the set of required properties is changed + +### NewSetProjectStateWithDefaults + +`func NewSetProjectStateWithDefaults() *SetProjectState` + +NewSetProjectStateWithDefaults instantiates a new SetProjectState object +This constructor will only assign default values to properties that have it defined, +but it doesn't guarantee that properties required by API are set + +### GetUptime + +`func (o *SetProjectState) GetUptime() int32` + +GetUptime returns the Uptime field if non-nil, zero value otherwise. + +### GetUptimeOk + +`func (o *SetProjectState) GetUptimeOk() (*int32, bool)` + +GetUptimeOk returns a tuple with the Uptime field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetUptime + +`func (o *SetProjectState) SetUptime(v int32)` + +SetUptime sets Uptime field to given value. + +### HasUptime + +`func (o *SetProjectState) HasUptime() bool` + +HasUptime returns a boolean if a field has been set. + + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/pkg/serverapiclient/docs/WorkspaceAPI.md b/pkg/serverapiclient/docs/WorkspaceAPI.md index be7155cc43..d628573fbf 100644 --- a/pkg/serverapiclient/docs/WorkspaceAPI.md +++ b/pkg/serverapiclient/docs/WorkspaceAPI.md @@ -8,6 +8,7 @@ Method | HTTP request | Description [**GetWorkspace**](WorkspaceAPI.md#GetWorkspace) | **Get** /workspace/{workspaceId} | Get workspace info [**ListWorkspaces**](WorkspaceAPI.md#ListWorkspaces) | **Get** /workspace | List workspaces [**RemoveWorkspace**](WorkspaceAPI.md#RemoveWorkspace) | **Delete** /workspace/{workspaceId} | Remove workspace +[**SetProjectState**](WorkspaceAPI.md#SetProjectState) | **Post** /workspace/{workspaceId}/{projectId}/state | Set project state [**StartProject**](WorkspaceAPI.md#StartProject) | **Post** /workspace/{workspaceId}/{projectId}/start | Start project [**StartWorkspace**](WorkspaceAPI.md#StartWorkspace) | **Post** /workspace/{workspaceId}/start | Start workspace [**StopProject**](WorkspaceAPI.md#StopProject) | **Post** /workspace/{workspaceId}/{projectId}/stop | Stop project @@ -285,6 +286,79 @@ No authorization required [[Back to README]](../README.md) +## SetProjectState + +> SetProjectState(ctx, workspaceId, projectId).SetState(setState).Execute() + +Set project state + + + +### Example + +```go +package main + +import ( + "context" + "fmt" + "os" + openapiclient "github.com/GIT_USER_ID/GIT_REPO_ID/serverapiclient" +) + +func main() { + workspaceId := "workspaceId_example" // string | Workspace ID or Name + projectId := "projectId_example" // string | Project ID + setState := *openapiclient.NewSetProjectState() // SetProjectState | Set State + + configuration := openapiclient.NewConfiguration() + apiClient := openapiclient.NewAPIClient(configuration) + r, err := apiClient.WorkspaceAPI.SetProjectState(context.Background(), workspaceId, projectId).SetState(setState).Execute() + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `WorkspaceAPI.SetProjectState``: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } +} +``` + +### Path Parameters + + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- +**ctx** | **context.Context** | context for authentication, logging, cancellation, deadlines, tracing, etc. +**workspaceId** | **string** | Workspace ID or Name | +**projectId** | **string** | Project ID | + +### Other Parameters + +Other parameters are passed through a pointer to a apiSetProjectStateRequest struct via the builder pattern + + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + + + **setState** | [**SetProjectState**](SetProjectState.md) | Set State | + +### Return type + + (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: Not defined + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) +[[Back to Model list]](../README.md#documentation-for-models) +[[Back to README]](../README.md) + + ## StartProject > StartProject(ctx, workspaceId, projectId).Execute() diff --git a/pkg/serverapiclient/model_project.go b/pkg/serverapiclient/model_project.go index 0de32682f8..f86e4fe3ef 100644 --- a/pkg/serverapiclient/model_project.go +++ b/pkg/serverapiclient/model_project.go @@ -21,6 +21,7 @@ var _ MappedNullable = &Project{} type Project struct { Name *string `json:"name,omitempty"` Repository *GitRepository `json:"repository,omitempty"` + State *ProjectState `json:"state,omitempty"` Target *string `json:"target,omitempty"` WorkspaceId *string `json:"workspaceId,omitempty"` } @@ -106,6 +107,38 @@ func (o *Project) SetRepository(v GitRepository) { o.Repository = &v } +// GetState returns the State field value if set, zero value otherwise. +func (o *Project) GetState() ProjectState { + if o == nil || IsNil(o.State) { + var ret ProjectState + return ret + } + return *o.State +} + +// GetStateOk returns a tuple with the State field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Project) GetStateOk() (*ProjectState, bool) { + if o == nil || IsNil(o.State) { + return nil, false + } + return o.State, true +} + +// HasState returns a boolean if a field has been set. +func (o *Project) HasState() bool { + if o != nil && !IsNil(o.State) { + return true + } + + return false +} + +// SetState gets a reference to the given ProjectState and assigns it to the State field. +func (o *Project) SetState(v ProjectState) { + o.State = &v +} + // GetTarget returns the Target field value if set, zero value otherwise. func (o *Project) GetTarget() string { if o == nil || IsNil(o.Target) { @@ -186,6 +219,9 @@ func (o Project) ToMap() (map[string]interface{}, error) { if !IsNil(o.Repository) { toSerialize["repository"] = o.Repository } + if !IsNil(o.State) { + toSerialize["state"] = o.State + } if !IsNil(o.Target) { toSerialize["target"] = o.Target } diff --git a/pkg/serverapiclient/model_project_info.go b/pkg/serverapiclient/model_project_info.go index b72672b78d..cba51c8446 100644 --- a/pkg/serverapiclient/model_project_info.go +++ b/pkg/serverapiclient/model_project_info.go @@ -20,11 +20,9 @@ var _ MappedNullable = &ProjectInfo{} // ProjectInfo struct for ProjectInfo type ProjectInfo struct { Created *string `json:"created,omitempty"` - Finished *string `json:"finished,omitempty"` IsRunning *bool `json:"isRunning,omitempty"` Name *string `json:"name,omitempty"` ProviderMetadata *string `json:"providerMetadata,omitempty"` - Started *string `json:"started,omitempty"` WorkspaceId *string `json:"workspaceId,omitempty"` } @@ -77,38 +75,6 @@ func (o *ProjectInfo) SetCreated(v string) { o.Created = &v } -// GetFinished returns the Finished field value if set, zero value otherwise. -func (o *ProjectInfo) GetFinished() string { - if o == nil || IsNil(o.Finished) { - var ret string - return ret - } - return *o.Finished -} - -// GetFinishedOk returns a tuple with the Finished field value if set, nil otherwise -// and a boolean to check if the value has been set. -func (o *ProjectInfo) GetFinishedOk() (*string, bool) { - if o == nil || IsNil(o.Finished) { - return nil, false - } - return o.Finished, true -} - -// HasFinished returns a boolean if a field has been set. -func (o *ProjectInfo) HasFinished() bool { - if o != nil && !IsNil(o.Finished) { - return true - } - - return false -} - -// SetFinished gets a reference to the given string and assigns it to the Finished field. -func (o *ProjectInfo) SetFinished(v string) { - o.Finished = &v -} - // GetIsRunning returns the IsRunning field value if set, zero value otherwise. func (o *ProjectInfo) GetIsRunning() bool { if o == nil || IsNil(o.IsRunning) { @@ -205,38 +171,6 @@ func (o *ProjectInfo) SetProviderMetadata(v string) { o.ProviderMetadata = &v } -// GetStarted returns the Started field value if set, zero value otherwise. -func (o *ProjectInfo) GetStarted() string { - if o == nil || IsNil(o.Started) { - var ret string - return ret - } - return *o.Started -} - -// GetStartedOk returns a tuple with the Started field value if set, nil otherwise -// and a boolean to check if the value has been set. -func (o *ProjectInfo) GetStartedOk() (*string, bool) { - if o == nil || IsNil(o.Started) { - return nil, false - } - return o.Started, true -} - -// HasStarted returns a boolean if a field has been set. -func (o *ProjectInfo) HasStarted() bool { - if o != nil && !IsNil(o.Started) { - return true - } - - return false -} - -// SetStarted gets a reference to the given string and assigns it to the Started field. -func (o *ProjectInfo) SetStarted(v string) { - o.Started = &v -} - // GetWorkspaceId returns the WorkspaceId field value if set, zero value otherwise. func (o *ProjectInfo) GetWorkspaceId() string { if o == nil || IsNil(o.WorkspaceId) { @@ -282,9 +216,6 @@ func (o ProjectInfo) ToMap() (map[string]interface{}, error) { if !IsNil(o.Created) { toSerialize["created"] = o.Created } - if !IsNil(o.Finished) { - toSerialize["finished"] = o.Finished - } if !IsNil(o.IsRunning) { toSerialize["isRunning"] = o.IsRunning } @@ -294,9 +225,6 @@ func (o ProjectInfo) ToMap() (map[string]interface{}, error) { if !IsNil(o.ProviderMetadata) { toSerialize["providerMetadata"] = o.ProviderMetadata } - if !IsNil(o.Started) { - toSerialize["started"] = o.Started - } if !IsNil(o.WorkspaceId) { toSerialize["workspaceId"] = o.WorkspaceId } diff --git a/pkg/serverapiclient/model_project_state.go b/pkg/serverapiclient/model_project_state.go new file mode 100644 index 0000000000..1049ab94cf --- /dev/null +++ b/pkg/serverapiclient/model_project_state.go @@ -0,0 +1,160 @@ +/* +Daytona Server API + +Daytona Server API + +API version: 0.1.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package serverapiclient + +import ( + "encoding/json" +) + +// checks if the ProjectState type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &ProjectState{} + +// ProjectState struct for ProjectState +type ProjectState struct { + UpdatedAt *string `json:"updatedAt,omitempty"` + Uptime *int32 `json:"uptime,omitempty"` +} + +// NewProjectState instantiates a new ProjectState object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewProjectState() *ProjectState { + this := ProjectState{} + return &this +} + +// NewProjectStateWithDefaults instantiates a new ProjectState object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewProjectStateWithDefaults() *ProjectState { + this := ProjectState{} + return &this +} + +// GetUpdatedAt returns the UpdatedAt field value if set, zero value otherwise. +func (o *ProjectState) GetUpdatedAt() string { + if o == nil || IsNil(o.UpdatedAt) { + var ret string + return ret + } + return *o.UpdatedAt +} + +// GetUpdatedAtOk returns a tuple with the UpdatedAt field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ProjectState) GetUpdatedAtOk() (*string, bool) { + if o == nil || IsNil(o.UpdatedAt) { + return nil, false + } + return o.UpdatedAt, true +} + +// HasUpdatedAt returns a boolean if a field has been set. +func (o *ProjectState) HasUpdatedAt() bool { + if o != nil && !IsNil(o.UpdatedAt) { + return true + } + + return false +} + +// SetUpdatedAt gets a reference to the given string and assigns it to the UpdatedAt field. +func (o *ProjectState) SetUpdatedAt(v string) { + o.UpdatedAt = &v +} + +// GetUptime returns the Uptime field value if set, zero value otherwise. +func (o *ProjectState) GetUptime() int32 { + if o == nil || IsNil(o.Uptime) { + var ret int32 + return ret + } + return *o.Uptime +} + +// GetUptimeOk returns a tuple with the Uptime field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ProjectState) GetUptimeOk() (*int32, bool) { + if o == nil || IsNil(o.Uptime) { + return nil, false + } + return o.Uptime, true +} + +// HasUptime returns a boolean if a field has been set. +func (o *ProjectState) HasUptime() bool { + if o != nil && !IsNil(o.Uptime) { + return true + } + + return false +} + +// SetUptime gets a reference to the given int32 and assigns it to the Uptime field. +func (o *ProjectState) SetUptime(v int32) { + o.Uptime = &v +} + +func (o ProjectState) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o ProjectState) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.UpdatedAt) { + toSerialize["updatedAt"] = o.UpdatedAt + } + if !IsNil(o.Uptime) { + toSerialize["uptime"] = o.Uptime + } + return toSerialize, nil +} + +type NullableProjectState struct { + value *ProjectState + isSet bool +} + +func (v NullableProjectState) Get() *ProjectState { + return v.value +} + +func (v *NullableProjectState) Set(val *ProjectState) { + v.value = val + v.isSet = true +} + +func (v NullableProjectState) IsSet() bool { + return v.isSet +} + +func (v *NullableProjectState) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableProjectState(val *ProjectState) *NullableProjectState { + return &NullableProjectState{value: val, isSet: true} +} + +func (v NullableProjectState) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableProjectState) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/pkg/serverapiclient/model_set_project_state.go b/pkg/serverapiclient/model_set_project_state.go new file mode 100644 index 0000000000..1f2200fe59 --- /dev/null +++ b/pkg/serverapiclient/model_set_project_state.go @@ -0,0 +1,124 @@ +/* +Daytona Server API + +Daytona Server API + +API version: 0.1.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package serverapiclient + +import ( + "encoding/json" +) + +// checks if the SetProjectState type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &SetProjectState{} + +// SetProjectState struct for SetProjectState +type SetProjectState struct { + Uptime *int32 `json:"uptime,omitempty"` +} + +// NewSetProjectState instantiates a new SetProjectState object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewSetProjectState() *SetProjectState { + this := SetProjectState{} + return &this +} + +// NewSetProjectStateWithDefaults instantiates a new SetProjectState object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewSetProjectStateWithDefaults() *SetProjectState { + this := SetProjectState{} + return &this +} + +// GetUptime returns the Uptime field value if set, zero value otherwise. +func (o *SetProjectState) GetUptime() int32 { + if o == nil || IsNil(o.Uptime) { + var ret int32 + return ret + } + return *o.Uptime +} + +// GetUptimeOk returns a tuple with the Uptime field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *SetProjectState) GetUptimeOk() (*int32, bool) { + if o == nil || IsNil(o.Uptime) { + return nil, false + } + return o.Uptime, true +} + +// HasUptime returns a boolean if a field has been set. +func (o *SetProjectState) HasUptime() bool { + if o != nil && !IsNil(o.Uptime) { + return true + } + + return false +} + +// SetUptime gets a reference to the given int32 and assigns it to the Uptime field. +func (o *SetProjectState) SetUptime(v int32) { + o.Uptime = &v +} + +func (o SetProjectState) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o SetProjectState) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Uptime) { + toSerialize["uptime"] = o.Uptime + } + return toSerialize, nil +} + +type NullableSetProjectState struct { + value *SetProjectState + isSet bool +} + +func (v NullableSetProjectState) Get() *SetProjectState { + return v.value +} + +func (v *NullableSetProjectState) Set(val *SetProjectState) { + v.value = val + v.isSet = true +} + +func (v NullableSetProjectState) IsSet() bool { + return v.isSet +} + +func (v *NullableSetProjectState) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableSetProjectState(val *SetProjectState) *NullableSetProjectState { + return &NullableSetProjectState{value: val, isSet: true} +} + +func (v NullableSetProjectState) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableSetProjectState) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/pkg/views/workspace/list/view.go b/pkg/views/workspace/list/view.go index 6ff4f37f87..e6e07577f7 100644 --- a/pkg/views/workspace/list/view.go +++ b/pkg/views/workspace/list/view.go @@ -27,7 +27,7 @@ type RowData struct { Branch string Target string Created string - Status string + Uptime string } type model struct { @@ -42,7 +42,7 @@ var columns = []table.Column{ {Title: "BRANCH", Width: defaultColumnWidth}, {Title: "TARGET", Width: defaultColumnWidth}, {Title: "CREATED", Width: defaultColumnWidth}, - {Title: "STATUS", Width: defaultColumnWidth}, + {Title: "UPTIME", Width: defaultColumnWidth}, } func (m model) Init() tea.Cmd { @@ -82,7 +82,7 @@ func renderWorkspaceList(workspaceList []serverapiclient.WorkspaceDTO, specifyGi adjustColumsFormatting(rowData) row = table.Row{rowData.WorkspaceName, rowData.Repository, rowData.Branch, rowData.Target} if workspace.Info != nil && len(workspace.Info.Projects) > 0 { - row = append(row, rowData.Created, rowData.Status) + row = append(row, rowData.Created, rowData.Uptime) } rows = append(rows, row) } else { @@ -93,7 +93,7 @@ func renderWorkspaceList(workspaceList []serverapiclient.WorkspaceDTO, specifyGi adjustColumsFormatting(rowData) row = table.Row{rowData.WorkspaceName, rowData.Repository, rowData.Branch, rowData.Target} if workspace.Info != nil && len(workspace.Info.Projects) > 0 { - row = append(row, rowData.Created, rowData.Status) + row = append(row, rowData.Created, rowData.Uptime) } rows = append(rows, row) } @@ -133,7 +133,7 @@ func adjustColumsFormatting(rowData RowData) { adjustColumnWidth("BRANCH", rowData) adjustColumnWidth("TARGET", rowData) adjustColumnWidth("CREATED", rowData) - adjustColumnWidth("STATUS", rowData) + adjustColumnWidth("UPTIME", rowData) } func adjustColumnWidth(title string, rowData RowData) { @@ -156,8 +156,8 @@ func adjustColumnWidth(title string, rowData RowData) { currentField = rowData.Target case "CREATED": currentField = rowData.Created - case "STATUS": - currentField = rowData.Status + case "UPTIME": + currentField = rowData.Uptime } if len(currentField) > column.Width { @@ -182,8 +182,8 @@ func getWorkspaceTableRowData(workspace serverapiclient.WorkspaceDTO, specifyGit if workspace.Info != nil && workspace.Info.Projects != nil && len(workspace.Info.Projects) > 0 && workspace.Info.Projects[0].Created != nil { rowData.Created = util.FormatCreatedTime(*workspace.Info.Projects[0].Created) } - if workspace.Info != nil && workspace.Info.Projects != nil && len(workspace.Info.Projects) > 0 && workspace.Info.Projects[0].Started != nil { - rowData.Status = util.FormatStatusTime(*workspace.Info.Projects[0].Started) + if len(workspace.Projects) > 0 && workspace.Projects[0].State != nil && workspace.Projects[0].State.Uptime != nil { + rowData.Uptime = util.FormatUptime(*workspace.Projects[0].State.Uptime) } return rowData } @@ -196,7 +196,6 @@ func getProjectTableRowData(workspaceDTO serverapiclient.WorkspaceDTO, project s currentProjectInfo = &workspace.ProjectInfo{ Name: *projectInfo.Name, Created: *projectInfo.Created, - Started: *projectInfo.Started, } break } @@ -206,7 +205,6 @@ func getProjectTableRowData(workspaceDTO serverapiclient.WorkspaceDTO, project s currentProjectInfo = &workspace.ProjectInfo{ Name: *project.Name, Created: "/", - Started: "/", } } @@ -224,7 +222,9 @@ func getProjectTableRowData(workspaceDTO serverapiclient.WorkspaceDTO, project s rowData.Target = *project.Target } rowData.Created = util.FormatCreatedTime(currentProjectInfo.Created) - rowData.Status = util.FormatStatusTime(currentProjectInfo.Started) + if project.State.Uptime != nil { + rowData.Uptime = util.FormatUptime(*project.State.Uptime) + } return rowData } diff --git a/pkg/views/workspace/selection/view.go b/pkg/views/workspace/selection/view.go index 4342cc1a96..6b0daccac8 100644 --- a/pkg/views/workspace/selection/view.go +++ b/pkg/views/workspace/selection/view.go @@ -20,8 +20,8 @@ import ( var CustomRepoIdentifier = "" type item[T any] struct { - id, title, desc, createdTime, statusTime, target string - choiceProperty T + id, title, desc, createdTime, uptime, target string + choiceProperty T } func (i item[T]) Title() string { return i.title } @@ -29,7 +29,7 @@ func (i item[T]) Id() string { return i.id } func (i item[T]) Description() string { return i.desc } func (i item[T]) FilterValue() string { return i.title } func (i item[T]) CreatedTime() string { return i.createdTime } -func (i item[T]) StatusTime() string { return i.statusTime } +func (i item[T]) Uptime() string { return i.uptime } func (i item[T]) Target() string { return i.target } type model[T any] struct { @@ -105,8 +105,8 @@ func (d ItemDelegate[T]) Render(w io.Writer, m list.Model, index int, listItem l Align(lipgloss.Right). Width(timeWidth) timeString := timeStyles.Render("") - if i.StatusTime() != "" { - timeString = timeStyles.Render(i.StatusTime()) + if i.Uptime() != "" { + timeString = timeStyles.Render(i.Uptime()) } else if i.CreatedTime() != "" { timeString = timeStyles.Render(fmt.Sprintf("created %s", i.CreatedTime())) } diff --git a/pkg/views/workspace/selection/workspace.go b/pkg/views/workspace/selection/workspace.go index 54640e7b96..3730e062de 100644 --- a/pkg/views/workspace/selection/workspace.go +++ b/pkg/views/workspace/selection/workspace.go @@ -29,13 +29,13 @@ func selectWorkspacePrompt(workspaces []serverapiclient.WorkspaceDTO, actionVerb } // Get the time if available - statusTime := "" + uptime := "" createdTime := "" if workspace.Info != nil && workspace.Info.Projects != nil && len(workspace.Info.Projects) > 0 && workspace.Info.Projects[0].Created != nil { createdTime = util.FormatCreatedTime(*workspace.Info.Projects[0].Created) } - if workspace.Info != nil && workspace.Info.Projects != nil && len(workspace.Info.Projects) > 0 && workspace.Info.Projects[0].Started != nil { - statusTime = util.FormatStatusTime(*workspace.Info.Projects[0].Started) + if len(workspace.Projects) > 0 && workspace.Projects[0].State != nil && workspace.Projects[0].State.Uptime != nil { + uptime = fmt.Sprintf("up %s", util.FormatUptime(*workspace.Projects[0].State.Uptime)) } newItem := item[serverapiclient.WorkspaceDTO]{ @@ -43,7 +43,7 @@ func selectWorkspacePrompt(workspaces []serverapiclient.WorkspaceDTO, actionVerb id: *workspace.Id, desc: strings.Join(projectNames, ", "), createdTime: createdTime, - statusTime: statusTime, + uptime: uptime, target: *workspace.Target, choiceProperty: workspace, } diff --git a/pkg/workspace/workspace.go b/pkg/workspace/workspace.go index 6b3b04f31c..0224fc7900 100644 --- a/pkg/workspace/workspace.go +++ b/pkg/workspace/workspace.go @@ -17,6 +17,7 @@ type Project struct { ApiKey string `json:"-"` Target string `json:"target"` EnvVars map[string]string `json:"-"` + State *ProjectState `json:"state,omitempty"` } // @name Project type Workspace struct { @@ -35,11 +36,14 @@ func (w *Workspace) GetProject(projectName string) (*Project, error) { return nil, errors.New("project not found") } +type ProjectState struct { + UpdatedAt string `json:"updatedAt"` + Uptime uint64 `json:"uptime"` +} // @name ProjectState + type ProjectInfo struct { Name string `json:"name"` Created string `json:"created"` - Started string `json:"started"` - Finished string `json:"finished"` IsRunning bool `json:"isRunning"` ProviderMetadata string `json:"providerMetadata,omitempty"` WorkspaceId string `json:"workspaceId"`