This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Doc Hub Proposal Signed-off-by: Kevin Su <[email protected]> * wip Signed-off-by: Kevin Su <[email protected]> * wip Signed-off-by: Kevin Su <[email protected]> * wip Signed-off-by: Kevin Su <[email protected]> * wip Signed-off-by: Kevin Su <[email protected]> * wip Signed-off-by: Kevin Su <[email protected]> * wip Signed-off-by: Kevin Su <[email protected]> * wip Signed-off-by: Kevin Su <[email protected]> * wip Signed-off-by: Kevin Su <[email protected]> * lint Signed-off-by: Kevin Su <[email protected]> * fix test error Signed-off-by: Kevin Su <[email protected]> * fix tests Signed-off-by: Kevin Su <[email protected]> * more tests Signed-off-by: Kevin Su <[email protected]> * lint Signed-off-by: Kevin Su <[email protected]> * update database schema Signed-off-by: Kevin Su <[email protected]> * update Signed-off-by: Kevin Su <[email protected]> * Fixed tests Signed-off-by: Kevin Su <[email protected]> * Fixed tests Signed-off-by: Kevin Su <[email protected]> * More tests Signed-off-by: Kevin Su <[email protected]> * update idl Signed-off-by: Kevin Su <[email protected]> * list description entity Signed-off-by: Kevin Su <[email protected]> * more tests Signed-off-by: Kevin Su <[email protected]> * register docs when creating task Signed-off-by: Kevin Su <[email protected]> * update go.sum Signed-off-by: Kevin Su <[email protected]> * update idl Signed-off-by: Kevin Su <[email protected]> * Fix tests Signed-off-by: Kevin Su <[email protected]> * Fix tests Signed-off-by: Kevin Su <[email protected]> * Fix tests Signed-off-by: Kevin Su <[email protected]> * more tests Signed-off-by: Kevin Su <[email protected]> * fix tests Signed-off-by: Kevin Su <[email protected]> * fix tests Signed-off-by: Kevin Su <[email protected]> * fix tests Signed-off-by: Kevin Su <[email protected]> * wip Signed-off-by: Kevin Su <[email protected]> * Add short description to workflow Signed-off-by: Kevin Su <[email protected]> * fix test Signed-off-by: Kevin Su <[email protected]> * fix test Signed-off-by: Kevin Su <[email protected]> * fix test Signed-off-by: Kevin Su <[email protected]> * fix test Signed-off-by: Kevin Su <[email protected]> * more test Signed-off-by: Kevin Su <[email protected]> * lint Signed-off-by: Kevin Su <[email protected]> * lint Signed-off-by: Kevin Su <[email protected]> * Lint Signed-off-by: Kevin Su <[email protected]> * update to one transation Signed-off-by: Kevin Su <[email protected]> * Fix tests Signed-off-by: Kevin Su <[email protected]> * fix tests Signed-off-by: Kevin Su <[email protected]> * fix tests Signed-off-by: Kevin Su <[email protected]> * fix tests Signed-off-by: Kevin Su <[email protected]> * fix tests Signed-off-by: Kevin Su <[email protected]> * fix tests Signed-off-by: Kevin Su <[email protected]> * update comment Signed-off-by: Kevin Su <[email protected]> * lint Signed-off-by: Kevin Su <[email protected]> * fix tests Signed-off-by: Kevin Su <[email protected]> * fix tests Signed-off-by: Kevin Su <[email protected]> * nit Signed-off-by: Kevin Su <[email protected]> * Bump idl Signed-off-by: Kevin Su <[email protected]> * update tests Signed-off-by: Kevin Su <[email protected]> * update tests Signed-off-by: Kevin Su <[email protected]> * update tests Signed-off-by: Kevin Su <[email protected]> * Add identifier Signed-off-by: Kevin Su <[email protected]> * update idl Signed-off-by: Kevin Su <[email protected]> * wip Signed-off-by: Kevin Su <[email protected]> * merged master Signed-off-by: Kevin Su <[email protected]> * Address comment Signed-off-by: Kevin Su <[email protected]> * Address comment Signed-off-by: Kevin Su <[email protected]> * update migrations.go Signed-off-by: Kevin Su <[email protected]> * nit Signed-off-by: Kevin Su <[email protected]> * fix tests Signed-off-by: Kevin Su <[email protected]> * fix tests Signed-off-by: Kevin Su <[email protected]> * lint Signed-off-by: Kevin Su <[email protected]> * Merged master Signed-off-by: Kevin Su <[email protected]> * more tests Signed-off-by: Kevin Su <[email protected]> Signed-off-by: Kevin Su <[email protected]>
- Loading branch information
Showing
43 changed files
with
1,300 additions
and
57 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,120 @@ | ||
package impl | ||
|
||
import ( | ||
"context" | ||
"strconv" | ||
|
||
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core" | ||
|
||
"github.com/flyteorg/flyteadmin/pkg/common" | ||
|
||
"github.com/flyteorg/flyteadmin/pkg/errors" | ||
"github.com/flyteorg/flyteadmin/pkg/manager/impl/util" | ||
"github.com/flyteorg/flyteadmin/pkg/manager/impl/validation" | ||
"github.com/flyteorg/flyteadmin/pkg/manager/interfaces" | ||
repoInterfaces "github.com/flyteorg/flyteadmin/pkg/repositories/interfaces" | ||
"github.com/flyteorg/flyteadmin/pkg/repositories/transformers" | ||
runtimeInterfaces "github.com/flyteorg/flyteadmin/pkg/runtime/interfaces" | ||
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin" | ||
"github.com/flyteorg/flytestdlib/contextutils" | ||
"github.com/flyteorg/flytestdlib/logger" | ||
"github.com/flyteorg/flytestdlib/promutils" | ||
"google.golang.org/grpc/codes" | ||
) | ||
|
||
type DescriptionEntityMetrics struct { | ||
Scope promutils.Scope | ||
} | ||
|
||
type DescriptionEntityManager struct { | ||
db repoInterfaces.Repository | ||
config runtimeInterfaces.Configuration | ||
metrics DescriptionEntityMetrics | ||
} | ||
|
||
func (d *DescriptionEntityManager) GetDescriptionEntity(ctx context.Context, request admin.ObjectGetRequest) ( | ||
*admin.DescriptionEntity, error) { | ||
if err := validation.ValidateDescriptionEntityGetRequest(request); err != nil { | ||
logger.Errorf(ctx, "invalid request [%+v]: %v", request, err) | ||
return nil, err | ||
} | ||
ctx = contextutils.WithProjectDomain(ctx, request.Id.Project, request.Id.Domain) | ||
return util.GetDescriptionEntity(ctx, d.db, *request.Id) | ||
} | ||
|
||
func (d *DescriptionEntityManager) ListDescriptionEntity(ctx context.Context, request admin.DescriptionEntityListRequest) (*admin.DescriptionEntityList, error) { | ||
// Check required fields | ||
if err := validation.ValidateDescriptionEntityListRequest(request); err != nil { | ||
return nil, err | ||
} | ||
ctx = contextutils.WithProjectDomain(ctx, request.Id.Project, request.Id.Domain) | ||
|
||
if request.ResourceType == core.ResourceType_WORKFLOW { | ||
ctx = contextutils.WithWorkflowID(ctx, request.Id.Name) | ||
} else { | ||
ctx = contextutils.WithTaskID(ctx, request.Id.Name) | ||
} | ||
|
||
filters, err := util.GetDbFilters(util.FilterSpec{ | ||
Project: request.Id.Project, | ||
Domain: request.Id.Domain, | ||
Name: request.Id.Name, | ||
RequestFilters: request.Filters, | ||
}, common.ResourceTypeToEntity[request.ResourceType]) | ||
if err != nil { | ||
logger.Error(ctx, "failed to get database filter") | ||
return nil, err | ||
} | ||
var sortParameter common.SortParameter | ||
if request.SortBy != nil { | ||
sortParameter, err = common.NewSortParameter(*request.SortBy) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
offset, err := validation.ValidateToken(request.Token) | ||
if err != nil { | ||
return nil, errors.NewFlyteAdminErrorf(codes.InvalidArgument, | ||
"invalid pagination token %s for ListWorkflows", request.Token) | ||
} | ||
listDescriptionEntitiesInput := repoInterfaces.ListResourceInput{ | ||
Limit: int(request.Limit), | ||
Offset: offset, | ||
InlineFilters: filters, | ||
SortParameter: sortParameter, | ||
} | ||
output, err := d.db.DescriptionEntityRepo().List(ctx, listDescriptionEntitiesInput) | ||
if err != nil { | ||
logger.Debugf(ctx, "Failed to list workflows with [%+v] with err %v", request.Id, err) | ||
return nil, err | ||
} | ||
descriptionEntityList, err := transformers.FromDescriptionEntityModels(output.Entities) | ||
if err != nil { | ||
logger.Errorf(ctx, | ||
"Failed to transform workflow models [%+v] with err: %v", output.Entities, err) | ||
return nil, err | ||
} | ||
var token string | ||
if len(output.Entities) == int(request.Limit) { | ||
token = strconv.Itoa(offset + len(output.Entities)) | ||
} | ||
return &admin.DescriptionEntityList{ | ||
DescriptionEntities: descriptionEntityList, | ||
Token: token, | ||
}, nil | ||
} | ||
|
||
func NewDescriptionEntityManager( | ||
db repoInterfaces.Repository, | ||
config runtimeInterfaces.Configuration, | ||
scope promutils.Scope) interfaces.DescriptionEntityInterface { | ||
|
||
metrics := DescriptionEntityMetrics{ | ||
Scope: scope, | ||
} | ||
return &DescriptionEntityManager{ | ||
db: db, | ||
config: config, | ||
metrics: metrics, | ||
} | ||
} |
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,146 @@ | ||
package impl | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/flyteorg/flyteadmin/pkg/manager/impl/testutils" | ||
"github.com/flyteorg/flyteadmin/pkg/repositories/interfaces" | ||
repositoryMocks "github.com/flyteorg/flyteadmin/pkg/repositories/mocks" | ||
runtimeInterfaces "github.com/flyteorg/flyteadmin/pkg/runtime/interfaces" | ||
runtimeMocks "github.com/flyteorg/flyteadmin/pkg/runtime/mocks" | ||
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin" | ||
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core" | ||
mockScope "github.com/flyteorg/flytestdlib/promutils" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var descriptionEntityIdentifier = core.Identifier{ | ||
ResourceType: core.ResourceType_WORKFLOW, | ||
Project: project, | ||
Domain: domain, | ||
Name: name, | ||
Version: version, | ||
} | ||
|
||
var badDescriptionEntityIdentifier = core.Identifier{ | ||
ResourceType: core.ResourceType_WORKFLOW, | ||
Project: project, | ||
Domain: domain, | ||
Name: "", | ||
Version: version, | ||
} | ||
|
||
func getMockRepositoryForDETest() interfaces.Repository { | ||
return repositoryMocks.NewMockRepository() | ||
} | ||
|
||
func getMockConfigForDETest() runtimeInterfaces.Configuration { | ||
mockConfig := runtimeMocks.NewMockConfigurationProvider( | ||
testutils.GetApplicationConfigWithDefaultDomains(), nil, nil, nil, nil, nil) | ||
return mockConfig | ||
} | ||
|
||
func TestDescriptionEntityManager_Get(t *testing.T) { | ||
repository := getMockRepositoryForDETest() | ||
manager := NewDescriptionEntityManager(repository, getMockConfigForDETest(), mockScope.NewTestScope()) | ||
|
||
response, err := manager.GetDescriptionEntity(context.Background(), admin.ObjectGetRequest{ | ||
Id: &descriptionEntityIdentifier, | ||
}) | ||
assert.NoError(t, err) | ||
assert.NotNil(t, response) | ||
|
||
response, err = manager.GetDescriptionEntity(context.Background(), admin.ObjectGetRequest{ | ||
Id: &badDescriptionEntityIdentifier, | ||
}) | ||
assert.Error(t, err) | ||
assert.Nil(t, response) | ||
} | ||
|
||
func TestDescriptionEntityManager_List(t *testing.T) { | ||
repository := getMockRepositoryForDETest() | ||
manager := NewDescriptionEntityManager(repository, getMockConfigForDETest(), mockScope.NewTestScope()) | ||
|
||
t.Run("failed to validate a request", func(t *testing.T) { | ||
response, err := manager.ListDescriptionEntity(context.Background(), admin.DescriptionEntityListRequest{ | ||
Id: &admin.NamedEntityIdentifier{ | ||
Name: "flyte", | ||
}, | ||
}) | ||
assert.Error(t, err) | ||
assert.Nil(t, response) | ||
}) | ||
|
||
t.Run("failed to sort description entity", func(t *testing.T) { | ||
response, err := manager.ListDescriptionEntity(context.Background(), admin.DescriptionEntityListRequest{ | ||
ResourceType: core.ResourceType_TASK, | ||
Id: &admin.NamedEntityIdentifier{ | ||
Name: "flyte", | ||
Project: "project", | ||
Domain: "domain", | ||
}, | ||
Limit: 1, | ||
SortBy: &admin.Sort{Direction: 3}, | ||
}) | ||
assert.Error(t, err) | ||
assert.Nil(t, response) | ||
}) | ||
|
||
t.Run("failed to validate token", func(t *testing.T) { | ||
response, err := manager.ListDescriptionEntity(context.Background(), admin.DescriptionEntityListRequest{ | ||
ResourceType: core.ResourceType_TASK, | ||
Id: &admin.NamedEntityIdentifier{ | ||
Name: "flyte", | ||
Project: "project", | ||
Domain: "domain", | ||
}, | ||
Limit: 1, | ||
Token: "hello", | ||
}) | ||
assert.Error(t, err) | ||
assert.Nil(t, response) | ||
}) | ||
|
||
t.Run("list description entities in the task", func(t *testing.T) { | ||
response, err := manager.ListDescriptionEntity(context.Background(), admin.DescriptionEntityListRequest{ | ||
ResourceType: core.ResourceType_TASK, | ||
Id: &admin.NamedEntityIdentifier{ | ||
Name: "flyte", | ||
Project: "project", | ||
Domain: "domain", | ||
}, | ||
Limit: 1, | ||
}) | ||
assert.NoError(t, err) | ||
assert.NotNil(t, response) | ||
}) | ||
|
||
t.Run("list description entities in the workflow", func(t *testing.T) { | ||
response, err := manager.ListDescriptionEntity(context.Background(), admin.DescriptionEntityListRequest{ | ||
ResourceType: core.ResourceType_WORKFLOW, | ||
Id: &admin.NamedEntityIdentifier{ | ||
Name: "flyte", | ||
Project: "project", | ||
Domain: "domain", | ||
}, | ||
Limit: 1, | ||
}) | ||
assert.NoError(t, err) | ||
assert.NotNil(t, response) | ||
}) | ||
|
||
t.Run("failed to get filter", func(t *testing.T) { | ||
response, err := manager.ListDescriptionEntity(context.Background(), admin.DescriptionEntityListRequest{ | ||
ResourceType: core.ResourceType_WORKFLOW, | ||
Id: &admin.NamedEntityIdentifier{ | ||
Name: "flyte", | ||
Project: "project", | ||
Domain: "domain", | ||
}, | ||
Filters: "wrong", | ||
}) | ||
assert.Error(t, err) | ||
assert.Nil(t, response) | ||
}) | ||
} |
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
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
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.