Skip to content

Commit

Permalink
Sync up the generated code from openapi generator with what we have c…
Browse files Browse the repository at this point in the history
…urrently
  • Loading branch information
openwithcode committed Feb 15, 2023
1 parent cb5398e commit c2dc2ff
Show file tree
Hide file tree
Showing 50 changed files with 1,930 additions and 1,286 deletions.
12 changes: 7 additions & 5 deletions api/design_api.partials.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@
schema:
type: string
style: simple
- in: header
name: X-API-KEY
schema:
type: string
style: simple
explode: false
required: true
responses:
'200':
description: Deleted
Expand Down Expand Up @@ -390,11 +397,6 @@
style: simple
explode: false
required: true
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/DesignSchema'
responses:
"200":
description: Null response
Expand Down
98 changes: 84 additions & 14 deletions cmd/controller/app/database/db_interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,62 +35,132 @@ type DBService interface {

// DatasetService is an interface that defines a collection of APIs related to dataset
type DatasetService interface {
CreateDataset(string, openapi.DatasetInfo) (string, error)
GetDatasets(string, int32) ([]openapi.DatasetInfo, error)
// CreateDataset creates a new dataset in the db
CreateDataset(userId string, info openapi.DatasetInfo) (string, error)

// GetDatasets returns a list of datasets associated with a user
GetDatasets(userId string, limit int32) ([]openapi.DatasetInfo, error)

// GetDatasetById returns the details of a particular dataset
GetDatasetById(string) (openapi.DatasetInfo, error)
}

// DesignService is an interface that defines a collection of APIs related to design
type DesignService interface {
// CreateDesign adds a design to the db
CreateDesign(userId string, info openapi.Design) error

// GetDesign returns a design associated with the given user and design ids
GetDesign(userId string, designId string) (openapi.Design, error)

// DeleteDesign deletes the design from the db
DeleteDesign(userId string, designId string) error

// GetDesigns returns a list of designs associated with a user
GetDesigns(userId string, limit int32) ([]openapi.DesignInfo, error)

// CreateDesignSchema adds a schema for a design to the db
CreateDesignSchema(userId string, designId string, info openapi.DesignSchema) error

// GetDesignSchema returns the schema of a design from the db
GetDesignSchema(userId string, designId string, version string) (openapi.DesignSchema, error)

// GetDesignSchemas returns all the schemas associated with the given designId
GetDesignSchemas(userId string, designId string) ([]openapi.DesignSchema, error)

// UpdateDesignSchema updates a schema for a design in the db
UpdateDesignSchema(userId string, designId string, version string, info openapi.DesignSchema) error

// DeleteDesignSchema deletes the schema of a design from the db
DeleteDesignSchema(userId string, designId string, version string) error

// CreateDesignCode adds the code of a design to the db
CreateDesignCode(userId string, designId string, fileName string, fileVer string, fileData *os.File) error

// GetDesignCode retrieves the code of a design from the db
GetDesignCode(userId string, designId string, version string) ([]byte, error)

// DeleteDesignCode deletes the code of a design from the db
DeleteDesignCode(userId string, designId string, version string) error
}

// JobService is an interface that defines a collection of APIs related to job
type JobService interface {
CreateJob(string, openapi.JobSpec) (openapi.JobStatus, error)
DeleteJob(string, string) error
GetJob(string, string) (openapi.JobSpec, error)
GetJobById(string) (openapi.JobSpec, error)
GetJobStatus(string, string) (openapi.JobStatus, error)
GetJobs(string, int32) ([]openapi.JobStatus, error)
UpdateJob(string, string, openapi.JobSpec) error
UpdateJobStatus(string, string, openapi.JobStatus) error
// CreateJob creates a new job
CreateJob(userId string, spec openapi.JobSpec) (openapi.JobStatus, error)

// DeleteJob deletes a given job
DeleteJob(userId string, jobId string) error

// GetJob gets the job associated with the provided jobId
GetJob(userId string, jobId string) (openapi.JobSpec, error)

// GetJobById gets the job associated with the provided jobId
GetJobById(jobId string) (openapi.JobSpec, error)

// GetJobStatus get the status of a job
GetJobStatus(userId string, jobId string) (openapi.JobStatus, error)

// GetJobs returns the list of jobs associated with a user
GetJobs(userId string, limit int32) ([]openapi.JobStatus, error)

// UpdateJob updates the job with the given jobId
UpdateJob(userId string, jobId string, spec openapi.JobSpec) error

// UpdateJobStatus updates the status of a job given the user Id, job Id and the openapi.JobStatus
UpdateJobStatus(userId string, jobId string, status openapi.JobStatus) error

// GetTaskInfo gets the information of a task given the user Id, job Id and task Id
GetTaskInfo(string, string, string) (openapi.TaskInfo, error)

// GetTasksInfo gets the information of tasks given the user Id, job Id and a limit
GetTasksInfo(string, string, int32, bool) ([]openapi.TaskInfo, error)

// GetTasksInfoGeneric gets the information of tasks given the user Id, job Id, limit and an option to include completed tasks
GetTasksInfoGeneric(string, string, int32, bool, bool) ([]openapi.TaskInfo, error)
}

// TaskService is an interface that defines a collection of APIs related to task
type TaskService interface {
// CreateTasks creates tasks given a set of objects.Task and a flag
CreateTasks([]objects.Task, bool) error

// DeleteTasks deletes tasks given the job Id and a flag
DeleteTasks(string, bool) error

// GetTask gets the task given the user Id, job Id and task Id
GetTask(string, string, string) (map[string][]byte, error)

// IsOneTaskInState evaluates if one of the task is in a certain state given the job Id
IsOneTaskInState(string, openapi.JobState) bool

// IsOneTaskInStateWithRole evaluates if one of the tasks is in a certain state and with a specific role given the job Id
IsOneTaskInStateWithRole(string, openapi.JobState, string) bool

// MonitorTasks monitors the tasks and returns a TaskInfo channel
MonitorTasks(string) (chan openapi.TaskInfo, chan error, context.CancelFunc, error)
SetTaskDirtyFlag(string, bool) error
UpdateTaskStateByFilter(string, openapi.JobState, map[string]interface{}) error
UpdateTaskStatus(string, string, openapi.TaskStatus) error

// SetTaskDirtyFlag sets the dirty flag for tasks given the job Id and a flag
SetTaskDirtyFlag(jobId string, dirty bool) error

// UpdateTaskStateByFilter updates the state of the task using a filter
UpdateTaskStateByFilter(jobId string, newState openapi.JobState, userFilter map[string]interface{}) error

// UpdateTaskStatus updates the status of a task given the user Id, job Id, and openapi.TaskStatus
UpdateTaskStatus(jobId string, taskId string, taskStatus openapi.TaskStatus) error
}

// ComputeService is an interface that defines a collection of APIs related to computes
type ComputeService interface {
// RegisterCompute registers a compute given a openapi.ComputeSpec
RegisterCompute(openapi.ComputeSpec) (openapi.ComputeStatus, error)

// GetComputeIdsByRegion gets all the compute Ids associated with a region
GetComputeIdsByRegion(string) ([]string, error)

// GetComputeById gets the compute info given the compute Id
GetComputeById(string) (openapi.ComputeSpec, error)
// UpdateDeploymentStatus call replaces existing agent statuses with received statuses in collection.

// UpdateDeploymentStatus updates the deployment status given the compute Id, job Id and agentStatuses map
UpdateDeploymentStatus(computeId string, jobId string, agentStatuses map[string]openapi.AgentState) error
}
15 changes: 8 additions & 7 deletions cmd/deployer/app/resource_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (

"github.com/cisco-open/flame/cmd/deployer/app/deployer"
"github.com/cisco-open/flame/pkg/openapi"
"github.com/cisco-open/flame/pkg/openapi/constants"
pbNotify "github.com/cisco-open/flame/pkg/proto/notification"
"github.com/cisco-open/flame/pkg/restapi"
"github.com/cisco-open/flame/pkg/util"
Expand Down Expand Up @@ -271,8 +272,8 @@ func (r *resourceHandler) postDeploymentStatus(jobId string, taskStatuses map[st
taskStatuses, r.spec.ComputeId, jobId)
// construct url
uriMap := map[string]string{
"computeId": r.spec.ComputeId,
"jobId": jobId,
constants.ParamComputeID: r.spec.ComputeId,
constants.ParamJobID: jobId,
}
url := restapi.CreateURL(r.apiserverEp, restapi.PutDeploymentStatusEndpoint, uriMap)

Expand All @@ -288,8 +289,8 @@ func (r *resourceHandler) getDeploymentConfig(jobId string) (openapi.DeploymentC
zap.S().Infof("Sending request to apiserver / controller to get deployment config")
// construct url
uriMap := map[string]string{
"computeId": r.spec.ComputeId,
"jobId": jobId,
constants.ParamComputeID: r.spec.ComputeId,
constants.ParamJobID: jobId,
}
url := restapi.CreateURL(r.apiserverEp, restapi.GetDeploymentConfigEndpoint, uriMap)
code, respBody, err := restapi.HTTPGet(url)
Expand Down Expand Up @@ -346,9 +347,9 @@ func (r *resourceHandler) deployResources(deploymentConfig openapi.DeploymentCon
taskKey := deploymentConfig.AgentKVs[taskId]

ctx := map[string]string{
"imageLoc": deploymentConfig.ImageLoc,
"taskId": taskId,
"taskKey": taskKey,
"imageLoc": deploymentConfig.ImageLoc,
constants.ParamTaskID: taskId,
"taskKey": taskKey,
}
rendered, renderErr := mustache.RenderFile(jobTemplatePath, &ctx)
if renderErr != nil {
Expand Down
5 changes: 3 additions & 2 deletions cmd/flamectl/cmd/get_design.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/spf13/cobra"

"github.com/cisco-open/flame/cmd/flamectl/resources/design"
"github.com/cisco-open/flame/pkg/openapi/constants"
)

var getDesignCmd = &cobra.Command{
Expand Down Expand Up @@ -51,7 +52,7 @@ var getDesignsCmd = &cobra.Command{

flags := cmd.Flags()

limit, err := flags.GetString("limit")
limit, err := flags.GetString(constants.ParamLimit)
if err != nil {
return err
}
Expand All @@ -66,7 +67,7 @@ var getDesignsCmd = &cobra.Command{
}

func init() {
getDesignsCmd.Flags().StringP("limit", "l", "100", "List of all the designs by this user")
getDesignsCmd.Flags().StringP(constants.ParamLimit, "l", "100", "List of all the designs by this user")

getCmd.AddCommand(getDesignCmd, getDesignsCmd)
}
17 changes: 9 additions & 8 deletions cmd/flamectl/resources/code/code.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"strings"

"github.com/cisco-open/flame/cmd/flamectl/resources"
"github.com/cisco-open/flame/pkg/openapi/constants"
"github.com/cisco-open/flame/pkg/restapi"
"github.com/cisco-open/flame/pkg/util"
)
Expand All @@ -42,8 +43,8 @@ type Params struct {
func Create(params Params) error {
// construct URL
uriMap := map[string]string{
"user": params.User,
"designId": params.DesignId,
constants.ParamUser: params.User,
constants.ParamDesignID: params.DesignId,
}
url := restapi.CreateURL(params.Endpoint, restapi.CreateDesignCodeEndPoint, uriMap)

Expand Down Expand Up @@ -87,9 +88,9 @@ func Create(params Params) error {
func Get(params Params) error {
// construct URL
uriMap := map[string]string{
"user": params.User,
"designId": params.DesignId,
"version": params.CodeVer,
constants.ParamUser: params.User,
constants.ParamDesignID: params.DesignId,
constants.ParamVersion: params.CodeVer,
}
url := restapi.CreateURL(params.Endpoint, restapi.GetDesignCodeEndPoint, uriMap)

Expand Down Expand Up @@ -125,9 +126,9 @@ func mustOpen(f string) *os.File {
func Remove(params Params) error {
// construct URL
uriMap := map[string]string{
"user": params.User,
"designId": params.DesignId,
"version": params.CodeVer,
constants.ParamUser: params.User,
constants.ParamDesignID: params.DesignId,
constants.ParamVersion: params.CodeVer,
}
url := restapi.CreateURL(params.Endpoint, restapi.DeleteDesignCodeEndPoint, uriMap)

Expand Down
7 changes: 4 additions & 3 deletions cmd/flamectl/resources/dataset/dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/cisco-open/flame/cmd/flamectl/resources"
"github.com/cisco-open/flame/pkg/openapi"
"github.com/cisco-open/flame/pkg/openapi/constants"
"github.com/cisco-open/flame/pkg/restapi"
"github.com/olekukonko/tablewriter"
)
Expand Down Expand Up @@ -53,7 +54,7 @@ func Create(params Params) error {

// construct URL
uriMap := map[string]string{
"user": params.User,
constants.ParamUser: params.User,
}
url := restapi.CreateURL(params.Endpoint, restapi.CreateDatasetEndPoint, uriMap)

Expand Down Expand Up @@ -87,8 +88,8 @@ func Get(params Params) error {
func GetMany(params Params, flagAll bool) error {
// construct URL
uriMap := map[string]string{
"user": params.User,
"limit": params.Limit,
constants.ParamUser: params.User,
constants.ParamLimit: params.Limit,
}

endpoint := restapi.GetDatasetsEndPoint
Expand Down
15 changes: 8 additions & 7 deletions cmd/flamectl/resources/design/design.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

"github.com/cisco-open/flame/cmd/flamectl/resources"
"github.com/cisco-open/flame/pkg/openapi"
"github.com/cisco-open/flame/pkg/openapi/constants"
"github.com/cisco-open/flame/pkg/restapi"
"github.com/cisco-open/flame/pkg/util"
)
Expand All @@ -40,7 +41,7 @@ type Params struct {
func Create(params Params) error {
// construct URL
uriMap := map[string]string{
"user": params.User,
constants.ParamUser: params.User,
}
url := restapi.CreateURL(params.Endpoint, restapi.CreateDesignEndPoint, uriMap)

Expand All @@ -66,8 +67,8 @@ func Create(params Params) error {
func Remove(params Params) error {
// construct URL
uriMap := map[string]string{
"user": params.User,
"designId": params.DesignId,
constants.ParamUser: params.User,
constants.ParamDesignID: params.DesignId,
}
url := restapi.CreateURL(params.Endpoint, restapi.DeleteDesignEndPoint, uriMap)

Expand Down Expand Up @@ -98,8 +99,8 @@ func Remove(params Params) error {
func Get(params Params) error {
// construct URL
uriMap := map[string]string{
"user": params.User,
"designId": params.DesignId,
constants.ParamUser: params.User,
constants.ParamDesignID: params.DesignId,
}
url := restapi.CreateURL(params.Endpoint, restapi.GetDesignEndPoint, uriMap)

Expand Down Expand Up @@ -129,8 +130,8 @@ func Get(params Params) error {
func GetMany(params Params) error {
// construct URL
uriMap := map[string]string{
"user": params.User,
"limit": params.Limit,
constants.ParamUser: params.User,
constants.ParamLimit: params.Limit,
}
url := restapi.CreateURL(params.Endpoint, restapi.GetDesignsEndPoint, uriMap)

Expand Down
Loading

0 comments on commit c2dc2ff

Please sign in to comment.