-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
1,162 additions
and
828 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// Copyright (c) 2022 Gitpod GmbH. All rights reserved. | ||
// Licensed under the GNU Affero General Public License (AGPL). | ||
// See License-AGPL.txt in the project root for license information. | ||
|
||
package apiv1 | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
connect "github.com/bufbuild/connect-go" | ||
v1 "github.com/gitpod-io/gitpod/components/public-api/go/experimental/v1" | ||
"github.com/gitpod-io/gitpod/components/public-api/go/experimental/v1/v1connect" | ||
protocol "github.com/gitpod-io/gitpod/gitpod-protocol" | ||
"github.com/gitpod-io/gitpod/public-api-server/pkg/proxy" | ||
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" | ||
) | ||
|
||
func NewIDEClientService(pool proxy.ServerConnectionPool) *IDEClientService { | ||
return &IDEClientService{ | ||
connectionPool: pool, | ||
} | ||
} | ||
|
||
var _ v1connect.IDEClientServiceHandler = (*IDEClientService)(nil) | ||
|
||
type IDEClientService struct { | ||
connectionPool proxy.ServerConnectionPool | ||
|
||
v1connect.UnimplementedIDEClientServiceHandler | ||
} | ||
|
||
func (this *IDEClientService) SendHeartbeat(ctx context.Context, req *connect.Request[v1.SendHeartbeatRequest]) (*connect.Response[v1.SendHeartbeatResponse], error) { | ||
logger := ctxlogrus.Extract(ctx) | ||
|
||
conn, err := getConnection(ctx, this.connectionPool) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
workspace, err := conn.GetWorkspace(ctx, req.Msg.GetWorkspaceId()) | ||
if err != nil { | ||
logger.WithError(err).Error("Failed to get workspace.") | ||
return nil, proxy.ConvertError(err) | ||
} | ||
|
||
if workspace.LatestInstance == nil { | ||
logger.WithError(err).Error("Failed to get latest instance.") | ||
return nil, connect.NewError(connect.CodeFailedPrecondition, fmt.Errorf("instance not found")) | ||
} | ||
|
||
err = conn.SendHeartBeat(ctx, &protocol.SendHeartBeatOptions{ | ||
InstanceID: workspace.LatestInstance.ID, | ||
WasClosed: false, | ||
}) | ||
if err != nil { | ||
return nil, proxy.ConvertError(err) | ||
} | ||
|
||
return connect.NewResponse(&v1.SendHeartbeatResponse{}), nil | ||
} | ||
|
||
func (this *IDEClientService) SendDidClose(ctx context.Context, req *connect.Request[v1.SendDidCloseRequest]) (*connect.Response[v1.SendDidCloseResponse], error) { | ||
logger := ctxlogrus.Extract(ctx) | ||
|
||
conn, err := getConnection(ctx, this.connectionPool) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
workspace, err := conn.GetWorkspace(ctx, req.Msg.GetWorkspaceId()) | ||
if err != nil { | ||
logger.WithError(err).Error("Failed to get workspace.") | ||
return nil, proxy.ConvertError(err) | ||
} | ||
|
||
if workspace.LatestInstance == nil { | ||
logger.WithError(err).Error("Failed to get latest instance.") | ||
return nil, connect.NewError(connect.CodeFailedPrecondition, fmt.Errorf("instance not found")) | ||
} | ||
|
||
err = conn.SendHeartBeat(ctx, &protocol.SendHeartBeatOptions{ | ||
InstanceID: workspace.LatestInstance.ID, | ||
WasClosed: true, | ||
}) | ||
if err != nil { | ||
return nil, proxy.ConvertError(err) | ||
} | ||
|
||
return connect.NewResponse(&v1.SendDidCloseResponse{}), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
components/public-api/gitpod/experimental/v1/ide_client.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
syntax = "proto3"; | ||
|
||
package gitpod.experimental.v1; | ||
|
||
option go_package = "github.com/gitpod-io/gitpod/components/public-api/go/experimental/v1"; | ||
|
||
service IDEClientService { | ||
// SendHeartbeat sends a clientheartbeat signal for a running workspace. | ||
rpc SendHeartbeat(SendHeartbeatRequest) returns (SendHeartbeatResponse) {} | ||
|
||
// SendDidClose sends a client close signal for a running workspace. | ||
rpc SendDidClose(SendDidCloseRequest) returns (SendDidCloseResponse) {} | ||
} | ||
|
||
message SendHeartbeatRequest { | ||
string workspace_id = 1; | ||
} | ||
message SendHeartbeatResponse {} | ||
|
||
message SendDidCloseRequest { | ||
string workspace_id = 1; | ||
} | ||
message SendDidCloseResponse {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.