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

[DO NOT REVIEW] Simplify API Registration - Applications.Datastores #6414

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 2 additions & 0 deletions cmd/applications-rp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import (
"github.com/radius-project/radius/pkg/ucp/ucplog"

corerp_setup "github.com/radius-project/radius/pkg/corerp/setup"
dsrp_setup "github.com/radius-project/radius/pkg/datastoresrp/setup"
)

const serviceName = "radius"
Expand Down Expand Up @@ -187,6 +188,7 @@ func builders(options hostoptions.HostOptions) ([]builder.Builder, error) {

return []builder.Builder{
corerp_setup.SetupNamespace(config).GenerateBuilder(),
dsrp_setup.SetupNamespace(config).GenerateBuilder(),
// Add resource provider builders...
}, nil
}
2 changes: 1 addition & 1 deletion cmd/ucpd/ucp-self-hosted-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ planes:
Applications.Core: "http://localhost:8080"
Applications.Messaging: "http://localhost:8081"
Applications.Dapr: "http://localhost:8081"
Applications.Datastores: "http://localhost:8081"
Applications.Datastores: "http://localhost:8080"
Microsoft.Resources: "http://localhost:5017"
kind: "UCPNative"

Expand Down
2 changes: 1 addition & 1 deletion deploy/Chart/templates/ucp/configmaps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ data:
resourceProviders:
Applications.Core: "http://applications-rp.radius-system:5443"
Applications.Dapr: "http://applications-rp.radius-system:5444"
Applications.Datastores: "http://applications-rp.radius-system:5444"
Applications.Datastores: "http://applications-rp.radius-system:5443"
Applications.Messaging: "http://applications-rp.radius-system:5444"
Microsoft.Resources: "http://bicep-de.radius-system:6443"
kind: "UCPNative"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ planes:
resourceProviders:
Applications.Core: "http://applications-rp.radius-system:5443"
Applications.Dapr: "http://applications-rp.radius-system:5444"
Applications.Datastores: "http://applications-rp.radius-system:5444"
Applications.Datastores: "http://applications-rp.radius-system:5443"
Applications.Messaging: "http://applications-rp.radius-system:5444"
Microsoft.Resources: "http://bicep-de.radius-system:6443"
kind: "UCPNative"
Expand Down
172 changes: 172 additions & 0 deletions pkg/datastoresrp/setup/operations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
/*
Copyright 2023 The Radius Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package setup

import v1 "github.com/radius-project/radius/pkg/armrpc/api/v1"

var operationList = []v1.Operation{
{
Name: "Applications.Datastores/operations/read",
Display: &v1.OperationDisplayProperties{
Provider: "Applications.Datastores",
Resource: "operations",
Operation: "Get operations",
Description: "Get the list of operations",
},
IsDataAction: false,
},
{
Name: "Applications.Datastores/redisCaches/read",
Display: &v1.OperationDisplayProperties{
Provider: "Applications.Datastores",
Resource: "redisCaches",
Operation: "List redisCaches",
Description: "List Redis cache resource(s).",
},
IsDataAction: false,
},
{
Name: "Applications.Datastores/redisCaches/write",
Display: &v1.OperationDisplayProperties{
Provider: "Applications.Datastores",
Resource: "redisCaches",
Operation: "Create/Update redisCaches",
Description: "Create or update an Redis cache resource.",
},
IsDataAction: false,
},
{
Name: "Applications.Datastores/redisCaches/delete",
Display: &v1.OperationDisplayProperties{
Provider: "Applications.Datastores",
Resource: "redisCaches",
Operation: "Delete redisCache",
Description: "Delete a Redis cache resource.",
},
IsDataAction: false,
},
{
Name: "Applications.Datastores/redisCaches/getmetadata/action",
Display: &v1.OperationDisplayProperties{
Provider: "Applications.Datastores",
Resource: "redisCaches",
Operation: "Get recipe metadata",
Description: "Get recipe metadata.",
},
IsDataAction: false,
},
{
Name: "Applications.Datastores/redisCaches/listsecrets/action",
Display: &v1.OperationDisplayProperties{
Provider: "Applications.Datastores",
Resource: "redisCaches",
Operation: "List secrets",
Description: "Lists Redis cache secrets.",
},
IsDataAction: false,
},
{
Name: "Applications.Datastores/register/action",
Display: &v1.OperationDisplayProperties{
Provider: "Applications.Datastores",
Resource: "Applications.Datastores",
Operation: "Register Applications.Datastores",
Description: "Register the subscription for Applications.Datastores.",
},
IsDataAction: false,
},
{
Name: "Applications.Datastores/unregister/action",
Display: &v1.OperationDisplayProperties{
Provider: "Applications.Datastores",
Resource: "Applications.Datastores",
Operation: "Unregister Applications.Datastores",
Description: "Unregister the subscription for Applications.Datastores.",
},
IsDataAction: false,
},
{
Name: "Applications.Datastores/mongoDatabases/read",
Display: &v1.OperationDisplayProperties{
Provider: "Applications.Datastores",
Resource: "mongoDatabases",
Operation: "List mongoDatabases",
Description: "List Mongo database resource(s).",
},
IsDataAction: false,
},
{
Name: "Applications.Datastores/mongoDatabases/write",
Display: &v1.OperationDisplayProperties{
Provider: "Applications.Datastores",
Resource: "mongoDatabases",
Operation: "Create/Update mongoDatabases",
Description: "Create or update a Mongo database resource.",
},
IsDataAction: false,
},
{
Name: "Applications.Datastores/mongoDatabases/delete",
Display: &v1.OperationDisplayProperties{
Provider: "Applications.Datastores",
Resource: "mongoDatabases",
Operation: "Delete mongoDatabases",
Description: "Delete a Mongo databases resource.",
},
IsDataAction: false,
},
{
Name: "Applications.Datastores/mongoDatabases/listsecrets/action",
Display: &v1.OperationDisplayProperties{
Provider: "Applications.Datastore",
Resource: "mongoDatabases",
Operation: "List secrets",
Description: "List secret(s) of Mongo database resource.",
},
IsDataAction: false,
},
{
Name: "Applications.Datastores/sqlDatabases/read",
Display: &v1.OperationDisplayProperties{
Provider: "Applications.Datastores",
Resource: "sqlDatabases",
Operation: "List sqlDatabases",
Description: "List SQL database resource(s).",
},
IsDataAction: false,
},
{
Name: "Applications.Datastores/sqlDatabases/write",
Display: &v1.OperationDisplayProperties{
Provider: "Applications.Datastores",
Resource: "sqlDatabases",
Operation: "Create/Update sqlDatabases",
Description: "Create or update a SQL database resource.",
},
IsDataAction: false,
},
{
Name: "Applications.Datastores/sqlDatabases/delete",
Display: &v1.OperationDisplayProperties{
Provider: "Applications.Datastores",
Resource: "sqlDatabases",
Operation: "Delete sqlDatabases",
Description: "Delete a SQL database resource.",
},
IsDataAction: false,
},
}
167 changes: 167 additions & 0 deletions pkg/datastoresrp/setup/setup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
/*
Copyright 2023 The Radius Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package setup

import (
"time"

asyncctrl "github.com/radius-project/radius/pkg/armrpc/asyncoperation/controller"
"github.com/radius-project/radius/pkg/armrpc/builder"
apictrl "github.com/radius-project/radius/pkg/armrpc/frontend/controller"
"github.com/radius-project/radius/pkg/datastoresrp/datamodel"
"github.com/radius-project/radius/pkg/datastoresrp/datamodel/converter"
"github.com/radius-project/radius/pkg/recipes/controllerconfig"

ds_ctrl "github.com/radius-project/radius/pkg/datastoresrp/frontend/controller"
mongo_ctrl "github.com/radius-project/radius/pkg/datastoresrp/frontend/controller/mongodatabases"
rds_ctrl "github.com/radius-project/radius/pkg/datastoresrp/frontend/controller/rediscaches"
sql_ctrl "github.com/radius-project/radius/pkg/datastoresrp/frontend/controller/sqldatabases"
mongo_proc "github.com/radius-project/radius/pkg/datastoresrp/processors/mongodatabases"
rds_proc "github.com/radius-project/radius/pkg/datastoresrp/processors/rediscaches"
sql_proc "github.com/radius-project/radius/pkg/datastoresrp/processors/sqldatabases"
pr_ctrl "github.com/radius-project/radius/pkg/portableresources/backend/controller"
rp_frontend "github.com/radius-project/radius/pkg/rp/frontend"
)

const (
// AsyncOperationRetryAfter is polling interval for async create/update or delete resource operations.
AsyncOperationRetryAfter = time.Duration(5) * time.Second
)

// SetupNamespace builds the namespace for core resource provider.
func SetupNamespace(recipeControllerConfig *controllerconfig.RecipeControllerConfig) *builder.Namespace {
ns := builder.NewNamespace("Applications.Datastores")

_ = ns.AddResource("redisCaches", &builder.ResourceOption[*datamodel.RedisCache, datamodel.RedisCache]{
RequestConverter: converter.RedisCacheDataModelFromVersioned,
ResponseConverter: converter.RedisCacheDataModelToVersioned,

Put: builder.Operation[datamodel.RedisCache]{
UpdateFilters: []apictrl.UpdateFilter[datamodel.RedisCache]{
rp_frontend.PrepareRadiusResource[*datamodel.RedisCache],
},
AsyncJobController: func(options asyncctrl.Options) (asyncctrl.Controller, error) {
return pr_ctrl.NewCreateOrUpdateResource[*datamodel.RedisCache, datamodel.RedisCache](options, &rds_proc.Processor{}, recipeControllerConfig.Engine, recipeControllerConfig.ResourceClient, recipeControllerConfig.ConfigLoader)
},
AsyncOperationTimeout: ds_ctrl.AsyncCreateOrUpdateRedisCacheTimeout,
AsyncOperationRetryAfter: AsyncOperationRetryAfter,
},
Patch: builder.Operation[datamodel.RedisCache]{
UpdateFilters: []apictrl.UpdateFilter[datamodel.RedisCache]{
rp_frontend.PrepareRadiusResource[*datamodel.RedisCache],
},
AsyncJobController: func(options asyncctrl.Options) (asyncctrl.Controller, error) {
return pr_ctrl.NewCreateOrUpdateResource[*datamodel.RedisCache, datamodel.RedisCache](options, &rds_proc.Processor{}, recipeControllerConfig.Engine, recipeControllerConfig.ResourceClient, recipeControllerConfig.ConfigLoader)
},
AsyncOperationTimeout: ds_ctrl.AsyncCreateOrUpdateRedisCacheTimeout,
AsyncOperationRetryAfter: AsyncOperationRetryAfter,
},
Delete: builder.Operation[datamodel.RedisCache]{
AsyncJobController: func(options asyncctrl.Options) (asyncctrl.Controller, error) {
return pr_ctrl.NewDeleteResource[*datamodel.RedisCache, datamodel.RedisCache](options, &rds_proc.Processor{}, recipeControllerConfig.Engine, recipeControllerConfig.ConfigLoader)
},
AsyncOperationTimeout: ds_ctrl.AsyncCreateOrUpdateRedisCacheTimeout,
AsyncOperationRetryAfter: AsyncOperationRetryAfter,
},
Custom: map[string]builder.Operation[datamodel.RedisCache]{
"listsecrets": {
APIController: rds_ctrl.NewListSecretsRedisCache,
},
},
})

_ = ns.AddResource("mongoDatabases", &builder.ResourceOption[*datamodel.MongoDatabase, datamodel.MongoDatabase]{
RequestConverter: converter.MongoDatabaseDataModelFromVersioned,
ResponseConverter: converter.MongoDatabaseDataModelToVersioned,

Put: builder.Operation[datamodel.MongoDatabase]{
UpdateFilters: []apictrl.UpdateFilter[datamodel.MongoDatabase]{
rp_frontend.PrepareRadiusResource[*datamodel.MongoDatabase],
},
AsyncJobController: func(options asyncctrl.Options) (asyncctrl.Controller, error) {
return pr_ctrl.NewCreateOrUpdateResource[*datamodel.MongoDatabase, datamodel.MongoDatabase](options, &mongo_proc.Processor{}, recipeControllerConfig.Engine, recipeControllerConfig.ResourceClient, recipeControllerConfig.ConfigLoader)
},
AsyncOperationTimeout: ds_ctrl.AsyncCreateOrUpdateMongoDatabaseTimeout,
AsyncOperationRetryAfter: AsyncOperationRetryAfter,
},
Patch: builder.Operation[datamodel.MongoDatabase]{
UpdateFilters: []apictrl.UpdateFilter[datamodel.MongoDatabase]{
rp_frontend.PrepareRadiusResource[*datamodel.MongoDatabase],
},
AsyncJobController: func(options asyncctrl.Options) (asyncctrl.Controller, error) {
return pr_ctrl.NewCreateOrUpdateResource[*datamodel.MongoDatabase, datamodel.MongoDatabase](options, &mongo_proc.Processor{}, recipeControllerConfig.Engine, recipeControllerConfig.ResourceClient, recipeControllerConfig.ConfigLoader)
},
AsyncOperationTimeout: ds_ctrl.AsyncCreateOrUpdateMongoDatabaseTimeout,
AsyncOperationRetryAfter: AsyncOperationRetryAfter,
},
Delete: builder.Operation[datamodel.MongoDatabase]{
AsyncJobController: func(options asyncctrl.Options) (asyncctrl.Controller, error) {
return pr_ctrl.NewDeleteResource[*datamodel.MongoDatabase, datamodel.MongoDatabase](options, &mongo_proc.Processor{}, recipeControllerConfig.Engine, recipeControllerConfig.ConfigLoader)
},
AsyncOperationTimeout: ds_ctrl.AsyncCreateOrUpdateRedisCacheTimeout,
AsyncOperationRetryAfter: AsyncOperationRetryAfter,
},
Custom: map[string]builder.Operation[datamodel.MongoDatabase]{
"listsecrets": {
APIController: mongo_ctrl.NewListSecretsMongoDatabase,
},
},
})

_ = ns.AddResource("sqldatabases", &builder.ResourceOption[*datamodel.SqlDatabase, datamodel.SqlDatabase]{
RequestConverter: converter.SqlDatabaseDataModelFromVersioned,
ResponseConverter: converter.SqlDatabaseDataModelToVersioned,

Put: builder.Operation[datamodel.SqlDatabase]{
UpdateFilters: []apictrl.UpdateFilter[datamodel.SqlDatabase]{
rp_frontend.PrepareRadiusResource[*datamodel.SqlDatabase],
},
AsyncJobController: func(options asyncctrl.Options) (asyncctrl.Controller, error) {
return pr_ctrl.NewCreateOrUpdateResource[*datamodel.SqlDatabase, datamodel.SqlDatabase](options, &sql_proc.Processor{}, recipeControllerConfig.Engine, recipeControllerConfig.ResourceClient, recipeControllerConfig.ConfigLoader)
},
AsyncOperationTimeout: ds_ctrl.AsyncCreateOrUpdateMongoDatabaseTimeout,
AsyncOperationRetryAfter: AsyncOperationRetryAfter,
},
Patch: builder.Operation[datamodel.SqlDatabase]{
UpdateFilters: []apictrl.UpdateFilter[datamodel.SqlDatabase]{
rp_frontend.PrepareRadiusResource[*datamodel.SqlDatabase],
},
AsyncJobController: func(options asyncctrl.Options) (asyncctrl.Controller, error) {
return pr_ctrl.NewCreateOrUpdateResource[*datamodel.SqlDatabase, datamodel.SqlDatabase](options, &sql_proc.Processor{}, recipeControllerConfig.Engine, recipeControllerConfig.ResourceClient, recipeControllerConfig.ConfigLoader)
},
AsyncOperationTimeout: ds_ctrl.AsyncCreateOrUpdateMongoDatabaseTimeout,
AsyncOperationRetryAfter: AsyncOperationRetryAfter,
},
Delete: builder.Operation[datamodel.SqlDatabase]{
AsyncJobController: func(options asyncctrl.Options) (asyncctrl.Controller, error) {
return pr_ctrl.NewDeleteResource[*datamodel.SqlDatabase, datamodel.SqlDatabase](options, &sql_proc.Processor{}, recipeControllerConfig.Engine, recipeControllerConfig.ConfigLoader)
},
AsyncOperationTimeout: ds_ctrl.AsyncCreateOrUpdateRedisCacheTimeout,
AsyncOperationRetryAfter: AsyncOperationRetryAfter,
},
Custom: map[string]builder.Operation[datamodel.SqlDatabase]{
"listsecrets": {
APIController: sql_ctrl.NewListSecretsSqlDatabase,
},
},
})

// Optional
ns.SetAvailableOperations(operationList)

return ns
}
Loading