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 13, 2023
1 parent cb5398e commit cde8d0b
Show file tree
Hide file tree
Showing 37 changed files with 1,820 additions and 1,076 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
101 changes: 87 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,135 @@ 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

// DeleteCompute deletes a compute given the user Id and compute Id
DeleteCompute(userId string, computeId string) error
}
18 changes: 18 additions & 0 deletions cmd/controller/app/database/mongodb/compute.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,21 @@ func (db *MongoService) UpdateDeploymentStatus(computeId string, jobId string, a
zap.S().Debugf("New deployment status for jobid: %s inserted", jobId)
return nil
}

func (db *MongoService) DeleteCompute(userId string, computeId string) error {
zap.S().Debugf("Delete compute : %v, %v", userId, computeId)

updateRes, err := db.deploymentCollection.DeleteOne(context.TODO(),
bson.M{util.DBFieldUserId: userId, util.DBFieldComputeId: computeId})
if err != nil {
return fmt.Errorf("failed to delete compute error: %v", err)
}

if updateRes.DeletedCount == 0 {
return fmt.Errorf("compute id %s not found", computeId)
}

zap.S().Debugf("Successfully deleted compute: %v", updateRes)

return nil
}
1,861 changes: 996 additions & 865 deletions docs/index.html

Large diffs are not rendered by default.

16 changes: 9 additions & 7 deletions pkg/openapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ type DesignCodesApiRouter interface {
// pass the data to a DesignSchemasApiServicer to perform the required actions, then write the service results to the http response.
type DesignSchemasApiRouter interface {
CreateDesignSchema(http.ResponseWriter, *http.Request)
DeleteDesignSchema(http.ResponseWriter, *http.Request)
GetDesignSchema(http.ResponseWriter, *http.Request)
GetDesignSchemas(http.ResponseWriter, *http.Request)
UpdateDesignSchema(http.ResponseWriter, *http.Request)
Expand Down Expand Up @@ -106,10 +107,11 @@ type JobsApiRouter interface {

// ComputesApiServicer defines the api actions for the ComputesApi service
// This interface intended to stay up to date with the openapi yaml used to generate it,
// while the service implementation can ignored with the .openapi-generator-ignore file
// while the service implementation can be ignored with the .openapi-generator-ignore file
// and updated with the logic required for the API.

type ComputesApiServicer interface {
DeleteCompute(context.Context, string, string) (ImplResponse, error)
DeleteCompute(ctx context.Context, computeID string, xAPIKEYParam string) (ImplResponse, error)
GetComputeConfig(context.Context, string, string) (ImplResponse, error)
GetComputeStatus(context.Context, string, string) (ImplResponse, error)
GetDeploymentConfig(context.Context, string, string, string) (ImplResponse, error)
Expand All @@ -122,7 +124,7 @@ type ComputesApiServicer interface {

// DatasetsApiServicer defines the api actions for the DatasetsApi service
// This interface intended to stay up to date with the openapi yaml used to generate it,
// while the service implementation can ignored with the .openapi-generator-ignore file
// while the service implementation can be ignored with the .openapi-generator-ignore file
// and updated with the logic required for the API.
type DatasetsApiServicer interface {
CreateDataset(context.Context, string, DatasetInfo) (ImplResponse, error)
Expand All @@ -134,7 +136,7 @@ type DatasetsApiServicer interface {

// DesignCodesApiServicer defines the api actions for the DesignCodesApi service
// This interface intended to stay up to date with the openapi yaml used to generate it,
// while the service implementation can ignored with the .openapi-generator-ignore file
// while the service implementation can be ignored with the .openapi-generator-ignore file
// and updated with the logic required for the API.
type DesignCodesApiServicer interface {
CreateDesignCode(context.Context, string, string, string, string, *os.File) (ImplResponse, error)
Expand All @@ -145,7 +147,7 @@ type DesignCodesApiServicer interface {

// DesignSchemasApiServicer defines the api actions for the DesignSchemasApi service
// This interface intended to stay up to date with the openapi yaml used to generate it,
// while the service implementation can ignored with the .openapi-generator-ignore file
// while the service implementation can be ignored with the .openapi-generator-ignore file
// and updated with the logic required for the API.
type DesignSchemasApiServicer interface {
CreateDesignSchema(context.Context, string, string, DesignSchema) (ImplResponse, error)
Expand All @@ -157,7 +159,7 @@ type DesignSchemasApiServicer interface {

// DesignsApiServicer defines the api actions for the DesignsApi service
// This interface intended to stay up to date with the openapi yaml used to generate it,
// while the service implementation can ignored with the .openapi-generator-ignore file
// while the service implementation can be ignored with the .openapi-generator-ignore file
// and updated with the logic required for the API.
type DesignsApiServicer interface {
CreateDesign(context.Context, string, DesignInfo) (ImplResponse, error)
Expand All @@ -168,7 +170,7 @@ type DesignsApiServicer interface {

// JobsApiServicer defines the api actions for the JobsApi service
// This interface intended to stay up to date with the openapi yaml used to generate it,
// while the service implementation can ignored with the .openapi-generator-ignore file
// while the service implementation can be ignored with the .openapi-generator-ignore file
// and updated with the logic required for the API.
type JobsApiServicer interface {
CreateJob(context.Context, string, JobSpec) (ImplResponse, error)
Expand Down
11 changes: 10 additions & 1 deletion pkg/openapi/api_computes.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func NewComputesApiController(s ComputesApiServicer, opts ...ComputesApiOption)
return controller
}

// Routes returns all of the api route for the ComputesApiController
// Routes returns all the api routes for the ComputesApiController
func (c *ComputesApiController) Routes() Routes {
return Routes{
{
Expand Down Expand Up @@ -137,6 +137,7 @@ func (c *ComputesApiController) DeleteCompute(w http.ResponseWriter, r *http.Req
}
// If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, w)

}

// GetComputeConfig - Get configuration for a compute cluster
Expand All @@ -153,6 +154,7 @@ func (c *ComputesApiController) GetComputeConfig(w http.ResponseWriter, r *http.
}
// If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, w)

}

// GetComputeStatus - Get status of a given compute cluster
Expand All @@ -169,6 +171,7 @@ func (c *ComputesApiController) GetComputeStatus(w http.ResponseWriter, r *http.
}
// If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, w)

}

// GetDeploymentConfig - Get the deployment config for a job for a compute cluster
Expand All @@ -187,6 +190,7 @@ func (c *ComputesApiController) GetDeploymentConfig(w http.ResponseWriter, r *ht
}
// If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, w)

}

// GetDeploymentStatus - Get the deployment status for a job on a compute cluster
Expand All @@ -205,6 +209,7 @@ func (c *ComputesApiController) GetDeploymentStatus(w http.ResponseWriter, r *ht
}
// If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, w)

}

// GetDeployments - Get all deployments within a compute cluster
Expand All @@ -221,6 +226,7 @@ func (c *ComputesApiController) GetDeployments(w http.ResponseWriter, r *http.Re
}
// If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, w)

}

// PutDeploymentStatus - Add or update the deployment status for a job on a compute cluster
Expand All @@ -246,6 +252,7 @@ func (c *ComputesApiController) PutDeploymentStatus(w http.ResponseWriter, r *ht
}
// If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, w)

}

// RegisterCompute - Register a new compute cluster
Expand All @@ -269,6 +276,7 @@ func (c *ComputesApiController) RegisterCompute(w http.ResponseWriter, r *http.R
}
// If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, w)

}

// UpdateCompute - Update a compute cluster's specification
Expand Down Expand Up @@ -296,4 +304,5 @@ func (c *ComputesApiController) UpdateCompute(w http.ResponseWriter, r *http.Req
}
// If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, w)

}
Loading

0 comments on commit cde8d0b

Please sign in to comment.