Skip to content

Commit

Permalink
Merge pull request #41 from openinfradev/improve_status
Browse files Browse the repository at this point in the history
add parameters(workflowId, workflowDesc) to updateClusterStatus,updateAppGroupStatus for tks-batch
  • Loading branch information
ktkfree authored Apr 8, 2022
2 parents 414fe5a + d82b21d commit f51519d
Show file tree
Hide file tree
Showing 17 changed files with 51 additions and 25 deletions.
1 change: 1 addition & 0 deletions .github/workflows/deploy-image-with-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
pull_request:
branches:
- main
- 'release**'
jobs:
build-and-pPush-image:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
push:
branches:
- main

- 'release**'
jobs:
build-and-push-image:
runs-on: ubuntu-latest
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
- v*
branches:
- main
- 'release**'
pull_request:
jobs:
golangci:
Expand All @@ -18,7 +19,7 @@ jobs:
uses: golangci/golangci-lint-action@v2
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.29
version: latest

# Optional: working directory, useful for monorepos
# working-directory: somedir
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ on:
push:
branches:
- main
- 'release**'
pull_request:
branches:
- main
- 'release**'


jobs:
Expand Down
2 changes: 1 addition & 1 deletion cmd/server/application_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (*AppInfoServer) UpdateAppGroupStatus(ctx context.Context, in *pb.UpdateApp
}, err
}
log.Info("UpdateAppGroupStatus request for app group ID: ", appGroupID)
if err = acc.UpdateAppGroupStatus(appGroupID, in.GetStatus()); err != nil {
if err = acc.UpdateAppGroupStatus(appGroupID, in.GetStatus(), in.GetStatusDesc(), in.GetWorkflowId()); err != nil {
return &pb.SimpleResponse{
Code: pb.Code_INTERNAL,
Error: &pb.Error{
Expand Down
2 changes: 1 addition & 1 deletion cmd/server/cluster_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func (s *ClusterInfoServer) UpdateClusterStatus(ctx context.Context, in *pb.Upda
return &res, err
}

err = clusterAccessor.UpdateStatus(clusterId, in.GetStatus())
err = clusterAccessor.UpdateStatus(clusterId, in.GetStatus(), in.GetStatusDesc(), in.GetWorkflowId())
if err != nil {
return &pb.SimpleResponse{
Code: pb.Code_INTERNAL,
Expand Down
8 changes: 4 additions & 4 deletions cmd/server/cluster_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ func TestGetClusters(t *testing.T) {
}, nil)
},
checkResponse: func(req *pb.GetClustersRequest, res *pb.GetClustersResponse, err error) {
require.Error(t, err)
require.Equal(t, res.Code, pb.Code_NOT_FOUND)
require.NoError(t, err)
require.Equal(t, res.Code, pb.Code_OK_UNSPECIFIED)
},
},
{
Expand Down Expand Up @@ -272,8 +272,8 @@ func TestGetClusters(t *testing.T) {
},
buildStubs: func(mockContractClient *mocktks.MockContractServiceClient) {},
checkResponse: func(req *pb.GetClustersRequest, res *pb.GetClustersResponse, err error) {
require.Error(t, err)
require.Equal(t, res.Code, pb.Code_NOT_FOUND)
require.NoError(t, err)
require.Equal(t, res.Code, pb.Code_OK_UNSPECIFIED)
},
},
{
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ require (
github.com/google/uuid v1.3.0
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/jackc/pgx/v4 v4.15.0 // indirect
github.com/openinfradev/tks-common v0.0.0-20220321044608-105302d33457
github.com/openinfradev/tks-proto v0.0.6-0.20220324075944-e471af2c8c49
github.com/openinfradev/tks-common v0.0.0-20220406045249-8ce7aeb0cb72
github.com/openinfradev/tks-proto v0.0.6-0.20220406043255-9fffe49c4625
github.com/stretchr/testify v1.7.0
golang.org/x/crypto v0.0.0-20220210151621-f4118a5b28e2 // indirect
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -827,9 +827,11 @@ github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417/go.m
github.com/opencontainers/selinux v1.10.0/go.mod h1:2i0OySw99QjzBBQByd1Gr9gSjvuho1lHsJxIJ3gGbJI=
github.com/openinfradev/tks-common v0.0.0-20220321044608-105302d33457 h1:yKhmkHl2qi2/pyNBST8zI8fpcjjcpTFzACBwtk2fjik=
github.com/openinfradev/tks-common v0.0.0-20220321044608-105302d33457/go.mod h1:3d+gW0PPeBzEUtVRoupTTXAFlfdJLyHy2Lzlw4rcnOk=
github.com/openinfradev/tks-common v0.0.0-20220406045249-8ce7aeb0cb72 h1:DzL7q4G4UA/z+oxPnsCuHFTcnJIdLP6LIkzUn4bZvJc=
github.com/openinfradev/tks-common v0.0.0-20220406045249-8ce7aeb0cb72/go.mod h1:3Mb3KGoozH5vT7zdIQb3CXYjqpIhUbgK/qhVJu3VMRY=
github.com/openinfradev/tks-proto v0.0.6-0.20211015003551-ed8f9541f40d/go.mod h1:ul6kvgOXhNQvXEUmb92Wh5BmsuzknnTCb3wqmVNd/iI=
github.com/openinfradev/tks-proto v0.0.6-0.20220324075944-e471af2c8c49 h1:XYNl9fXGUH02/Laqht+ba2FmgOXrl7sUDHcAZHsSaUE=
github.com/openinfradev/tks-proto v0.0.6-0.20220324075944-e471af2c8c49/go.mod h1:3DrATRNCUJMW0oMLHT6D1teN4hX0vMGH4qOGnadakmo=
github.com/openinfradev/tks-proto v0.0.6-0.20220406043255-9fffe49c4625 h1:kvcIa/cU+sjsK4VhQHjtquS3mGC3UAmbNHL9Qe03vYA=
github.com/openinfradev/tks-proto v0.0.6-0.20220406043255-9fffe49c4625/go.mod h1:3DrATRNCUJMW0oMLHT6D1teN4hX0vMGH4qOGnadakmo=
github.com/opentracing-contrib/go-observer v0.0.0-20170622124052-a52f23424492/go.mod h1:Ngi6UdF0k5OKD5t5wlmGhe/EDKPoUM3BXZSSfIuJbis=
github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74=
github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
Expand Down
6 changes: 4 additions & 2 deletions pkg/application/accessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ func (x *Accessor) GetAppGroup(appGroupID uuid.UUID) (*pb.AppGroup, error) {
}

// UpdateAppGroupStatus updates status of application group.
func (x *Accessor) UpdateAppGroupStatus(appGroupID uuid.UUID, status pb.AppGroupStatus) error {
func (x *Accessor) UpdateAppGroupStatus(appGroupID uuid.UUID, status pb.AppGroupStatus, statusDesc string, workflowId string) error {
res := x.db.Model(&model.ApplicationGroup{}).
Where("id = ?", appGroupID).
Update("status", status)
Updates(map[string]interface{}{"Status": status, "StatusDesc": statusDesc, "WorkflowId": workflowId})

if res.Error != nil {
return res.Error
Expand Down Expand Up @@ -193,7 +193,9 @@ func reflectToPbAppGroup(model model.ApplicationGroup) *pb.AppGroup {
AppGroupId: model.ID.String(),
AppGroupName: model.Name,
Type: model.Type,
WorkflowId: model.WorkflowId,
Status: model.Status,
StatusDesc: model.StatusDesc,
ClusterId: model.ClusterId.String(),
ExternalLabel: model.ExternalLabel,
CreatedAt: timestamppb.New(model.CreatedAt),
Expand Down
2 changes: 1 addition & 1 deletion pkg/application/accessor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func TestGetAppGroup(t *testing.T) {
t.Logf("matching app group name: %s", appGroup.AppGroupName)
}
func TestUpdateAppGroupStatus(t *testing.T) {
if err := accessor.UpdateAppGroupStatus(appGroupID, pb.AppGroupStatus_APP_GROUP_RUNNING); err != nil {
if err := accessor.UpdateAppGroupStatus(appGroupID, pb.AppGroupStatus_APP_GROUP_RUNNING, "", ""); err != nil {
t.Errorf("an error was unexpected while update application group: %s", err)
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/application/model/application_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ type ApplicationGroup struct {
ID uuid.UUID `gorm:"primarykey;type:uuid;default:uuid_generate_v4()"`
Name string
Type pb.AppGroupType
WorkflowId string
Status pb.AppGroupStatus
StatusDesc string
ClusterId uuid.UUID `gorm:"type:uuid;"`
ExternalLabel string
UpdatedAt time.Time
Expand Down
24 changes: 17 additions & 7 deletions pkg/cluster/accessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package cluster

import (
"fmt"
_ "time"

uuid "github.com/google/uuid"
"google.golang.org/protobuf/types/known/timestamppb"
"gorm.io/gorm"
_ "time"

_ "github.com/openinfradev/tks-common/pkg/log"
model "github.com/openinfradev/tks-info/pkg/cluster/model"
Expand Down Expand Up @@ -42,15 +43,20 @@ func (x *ClusterAccessor) GetClustersByContractID(contractId uuid.UUID) ([]*pb.C

res := x.db.Find(&clusters, "contract_id = ?", contractId)

if res.RowsAffected == 0 || res.Error != nil {
return nil, fmt.Errorf("Could not find clusters with contractID: %s", contractId)
if res.Error != nil {
return nil, fmt.Errorf("Error while finding clusters with contractID: %s", contractId)
}

pbClusters := []*pb.Cluster{}

// If no record is found, just return empty array.
if res.RowsAffected == 0 {
return pbClusters, nil
}

for _, cluster := range clusters {
pbClusters = append(pbClusters, ConvertToPbCluster(cluster))
}

return pbClusters, nil
}

Expand Down Expand Up @@ -78,7 +84,9 @@ func (x *ClusterAccessor) CreateClusterInfo(contractId uuid.UUID, cspId uuid.UUI
ContractID: contractId,
CspID: cspId,
Name: name,
WorkflowId: "",
Status: pb.ClusterStatus_UNSPECIFIED,
StatusDesc: "",
SshKeyName: conf.SshKeyName,
Region: conf.Region,
NumOfAz: conf.NumOfAz,
Expand All @@ -97,10 +105,10 @@ func (x *ClusterAccessor) CreateClusterInfo(contractId uuid.UUID, cspId uuid.UUI
}

// UpdateStatus updates an status of cluster for Cluster.
func (x *ClusterAccessor) UpdateStatus(id uuid.UUID, status pb.ClusterStatus) error {
func (x *ClusterAccessor) UpdateStatus(id uuid.UUID, status pb.ClusterStatus, statusDesc string, workflowId string) error {
res := x.db.Model(&model.Cluster{}).
Where("ID = ?", id).
Update("Status", status)
Updates(map[string]interface{}{"Status": status, "StatusDesc": statusDesc, "WorkflowId": workflowId})

if res.Error != nil || res.RowsAffected == 0 {
return fmt.Errorf("nothing updated in cluster with id %s", id.String())
Expand All @@ -123,8 +131,10 @@ func ConvertToPbCluster(cluster model.Cluster) *pb.Cluster {
Id: cluster.ID.String(),
Name: cluster.Name,
CreatedAt: timestamppb.New(cluster.CreatedAt),
UpdatedAt: timestamppb.New(cluster.CreatedAt),
UpdatedAt: timestamppb.New(cluster.UpdatedAt),
WorkflowId: cluster.WorkflowId,
Status: cluster.Status,
StatusDesc: cluster.StatusDesc,
ContractId: cluster.ContractID.String(),
CspId: cluster.CspID.String(),
Kubeconfig: cluster.Kubeconfig,
Expand Down
2 changes: 1 addition & 1 deletion pkg/cluster/accessor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func TestGetClustersByCspID(t *testing.T) {
}

func TestUpdateStatus(t *testing.T) {
err := clusterAccessor.UpdateStatus(clusterId, pb.ClusterStatus_INSTALLING)
err := clusterAccessor.UpdateStatus(clusterId, pb.ClusterStatus_INSTALLING, "", "")
if err != nil {
t.Errorf("An error occurred while updating cluster status. Err: %s", err)
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/cluster/model/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ type Cluster struct {
Name string
ContractID uuid.UUID
CspID uuid.UUID
WorkflowId string
Status pb.ClusterStatus
StatusDesc string
SshKeyName string
Region string
NumOfAz int32
Expand Down
4 changes: 3 additions & 1 deletion scripts/application_db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ CREATE TABLE application_groups
name character varying(50) COLLATE pg_catalog."default",
id uuid primary key,
type bigint,
status bigint,
workflow_id character varying(100) COLLATE pg_catalog."default",
status integer,
status_desc character varying(10000) COLLATE pg_catalog."default",
cluster_id uuid,
external_label character varying(50) COLLATE pg_catalog."default",
updated_at timestamp with time zone,
Expand Down
4 changes: 3 additions & 1 deletion scripts/cluster_db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ CREATE TABLE clusters
id uuid primary key,
contract_id uuid,
csp_id uuid,
status integer,
workflow_id character varying(100) COLLATE pg_catalog."default",
status bigint,
status_desc character varying(10000) COLLATE pg_catalog."default",
ssh_key_name character varying(50) COLLATE pg_catalog."default",
region character varying(50) COLLATE pg_catalog."default",
num_of_az integer,
Expand Down

0 comments on commit f51519d

Please sign in to comment.