Skip to content

Commit

Permalink
Merge pull request #178 from dream11/release-20230309
Browse files Browse the repository at this point in the history
Release 20230309
  • Loading branch information
yogesh-badke authored Mar 9, 2023
2 parents 2ec5c44 + 5407de7 commit 595bebc
Show file tree
Hide file tree
Showing 17 changed files with 471 additions and 99 deletions.
60 changes: 9 additions & 51 deletions api/component/component.go
Original file line number Diff line number Diff line change
@@ -1,58 +1,16 @@
package component

// Component interface
type Component struct {
Name string `yaml:"name,omitempty" json:"name,omitempty"`
Type string `yaml:"type,omitempty" json:"type,omitempty"`
Version string `yaml:"version,omitempty" json:"version,omitempty"`
Config interface{} `yaml:"config,omitempty" json:"config,omitempty"`
Deployment interface{} `yaml:"deployment_config,omitempty" json:"deployment_config,omitempty"`
Scaling interface{} `yaml:"scaling_config,omitempty" json:"scaling_config,omitempty"`
Discovery interface{} `yaml:"discovery_config,omitempty" json:"discovery_config,omitempty"`
DeploymentPlatformMapping interface{} `yaml:"behaviour,omitempty" json:"behaviour,omitempty"`
type Operation struct {
Name string `yaml:"name,omitempty" json:"name,omitempty"`
Values interface{} `yaml:"values,omitempty" json:"values,omitempty"`
}

// Type interface
type Type struct {
Name string `yaml:"name,omitempty" json:"name,omitempty"`
Version string `yaml:"version,omitempty" json:"version,omitempty"`
TotalVersions int `yaml:"totalVersions,omitempty" json:"totalVersions,omitempty"`
DeploymentTypes []string `yaml:"deployment_types,omitempty" json:"deployment_types,omitempty"`
CreatedBy string `yaml:"createdBy,omitempty" json:"createdBy,omitempty"`
UpdatedBy string `yaml:"updatedBy,omitempty" json:"updatedBy,omitempty"`
CreatedAt string `yaml:"createdAt,omitempty" json:"createdAt,omitempty"`
UpdatedAt string `yaml:"updatedAt,omitempty" json:"updatedAt,omitempty"`
Config interface{} `yaml:"config,omitempty" json:"config,omitempty"`
Deployment interface{} `yaml:"deployment_config,omitempty" json:"deployment_config,omitempty"`
Scaling interface{} `yaml:"scaling_config,omitempty" json:"scaling_config,omitempty"`
Discovery interface{} `yaml:"discovery_config,omitempty" json:"discovery_config,omitempty"`
DeploymentPlatformMapping interface{} `yaml:"behaviour,omitempty" json:"behaviour,omitempty"`
type Data struct {
EnvName string `yaml:"env_name,omitempty" json:"env_name,omitempty"`
ServiceName string `yaml:"service_name,omitempty" json:"service_name,omitempty"`
Operations []Operation `yaml:"operations,omitempty" json:"operations,omitempty"`
}

// Exposed Config interface
type ExposedConfig struct {
Config string `yaml:"config,omitempty" json:"config,omitempty"`
Mandatory bool `yaml:"mandatory,omitempty" json:"mandatory,omitempty"`
DataType string `yaml:"data_type,omitempty" json:"data_type,omitempty"`
}

// ListTypeResponse interface
type ListTypeResponse struct {
Response []Type `yaml:"resp,omitempty" json:"resp,omitempty"`
}

// DetailComponentTypeResponse interface
type ComponentDetailsResponse struct {
Response ComponentDetails `yaml:"resp,omitempty" json:"resp,omitempty"`
}

// ComponentDetails interface
type ComponentDetails struct {
Details Type `yaml:"details,omitempty" json:"details,omitempty"`
ExposedConfigs []ExposedConfig `yaml:"exposed_config,omitempty" json:"exposed_config,omitempty"`
}

// ListTypeResponse interface
type DetailComponentResponse struct {
Response Component `yaml:"resp,omitempty" json:"resp,omitempty"`
type OperateComponentRequest struct {
Data Data `yaml:"data,omitempty" json:"data,omitempty"`
}
58 changes: 58 additions & 0 deletions api/componenttype/componenttype.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package componenttype

// Component interface
type Component struct {
Name string `yaml:"name,omitempty" json:"name,omitempty"`
Type string `yaml:"type,omitempty" json:"type,omitempty"`
Version string `yaml:"version,omitempty" json:"version,omitempty"`
Config interface{} `yaml:"config,omitempty" json:"config,omitempty"`
Deployment interface{} `yaml:"deployment_config,omitempty" json:"deployment_config,omitempty"`
Scaling interface{} `yaml:"scaling_config,omitempty" json:"scaling_config,omitempty"`
Discovery interface{} `yaml:"discovery_config,omitempty" json:"discovery_config,omitempty"`
DeploymentPlatformMapping interface{} `yaml:"behaviour,omitempty" json:"behaviour,omitempty"`
}

// Type interface
type Type struct {
Name string `yaml:"name,omitempty" json:"name,omitempty"`
Version string `yaml:"version,omitempty" json:"version,omitempty"`
TotalVersions int `yaml:"totalVersions,omitempty" json:"totalVersions,omitempty"`
DeploymentTypes []string `yaml:"deployment_types,omitempty" json:"deployment_types,omitempty"`
CreatedBy string `yaml:"createdBy,omitempty" json:"createdBy,omitempty"`
UpdatedBy string `yaml:"updatedBy,omitempty" json:"updatedBy,omitempty"`
CreatedAt string `yaml:"createdAt,omitempty" json:"createdAt,omitempty"`
UpdatedAt string `yaml:"updatedAt,omitempty" json:"updatedAt,omitempty"`
Config interface{} `yaml:"config,omitempty" json:"config,omitempty"`
Deployment interface{} `yaml:"deployment_config,omitempty" json:"deployment_config,omitempty"`
Scaling interface{} `yaml:"scaling_config,omitempty" json:"scaling_config,omitempty"`
Discovery interface{} `yaml:"discovery_config,omitempty" json:"discovery_config,omitempty"`
DeploymentPlatformMapping interface{} `yaml:"behaviour,omitempty" json:"behaviour,omitempty"`
}

// Exposed Config interface
type ExposedConfig struct {
Config string `yaml:"config,omitempty" json:"config,omitempty"`
Mandatory bool `yaml:"mandatory,omitempty" json:"mandatory,omitempty"`
DataType string `yaml:"data_type,omitempty" json:"data_type,omitempty"`
}

// ListTypeResponse interface
type ListTypeResponse struct {
Response []Type `yaml:"resp,omitempty" json:"resp,omitempty"`
}

// DetailComponentTypeResponse interface
type ComponentDetailsResponse struct {
Response ComponentDetails `yaml:"resp,omitempty" json:"resp,omitempty"`
}

// ComponentDetails interface
type ComponentDetails struct {
Details Type `yaml:"details,omitempty" json:"details,omitempty"`
ExposedConfigs []ExposedConfig `yaml:"exposed_config,omitempty" json:"exposed_config,omitempty"`
}

// ListTypeResponse interface
type DetailComponentResponse struct {
Response Component `yaml:"resp,omitempty" json:"resp,omitempty"`
}
11 changes: 11 additions & 0 deletions api/operation/operation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package operation

type Operation struct {
Name string `yaml:"name,omitempty" json:"name,omitempty"`
Description string `yaml:"description,omitempty" json:"description,omitempty"`
InputSchema interface{} `yaml:"inputSchema,omitempty" json:"inputSchema,omitempty"`
}

type ListOperation struct {
Response []Operation `yaml:"resp,omitempty" json:"resp,omitempty"`
}
26 changes: 13 additions & 13 deletions api/service/service.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
package service

import (
"github.com/dream11/odin/api/component"
"github.com/dream11/odin/api/componenttype"
"github.com/dream11/odin/api/label"
)

type Service struct {
Name string `yaml:"name,omitempty" json:"name,omitempty"`
Version string `yaml:"version,omitempty" json:"version,omitempty"`
Team string `yaml:"team,omitempty" json:"team,omitempty"`
Description string `yaml:"description,omitempty" json:"description,omitempty"`
CreatedBy string `yaml:"createdBy,omitempty" json:"createdBy,omitempty"`
UpdatedBy string `yaml:"updatedBy,omitempty" json:"updatedBy,omitempty"`
CreatedAt string `yaml:"createdAt,omitempty" json:"createdAt,omitempty"`
UpdatedAt string `yaml:"updatedAt,omitempty" json:"updatedAt,omitempty"`
Active *bool `yaml:"isActive,omitempty" json:"isActive,omitempty"`
Tags interface{} `yaml:"tags,omitempty" json:"tags,omitempty"`
Labels []label.Label `yaml:"labels,omitempty" json:"labels,omitempty"`
Components []component.Component `yaml:"components,omitempty" json:"components,omitempty"`
Name string `yaml:"name,omitempty" json:"name,omitempty"`
Version string `yaml:"version,omitempty" json:"version,omitempty"`
Team string `yaml:"team,omitempty" json:"team,omitempty"`
Description string `yaml:"description,omitempty" json:"description,omitempty"`
CreatedBy string `yaml:"createdBy,omitempty" json:"createdBy,omitempty"`
UpdatedBy string `yaml:"updatedBy,omitempty" json:"updatedBy,omitempty"`
CreatedAt string `yaml:"createdAt,omitempty" json:"createdAt,omitempty"`
UpdatedAt string `yaml:"updatedAt,omitempty" json:"updatedAt,omitempty"`
Active *bool `yaml:"isActive,omitempty" json:"isActive,omitempty"`
Tags interface{} `yaml:"tags,omitempty" json:"tags,omitempty"`
Labels []label.Label `yaml:"labels,omitempty" json:"labels,omitempty"`
Components []componenttype.Component `yaml:"components,omitempty" json:"components,omitempty"`
}

// ListResponse interface
Expand Down
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ type application struct {
// App (Application) interface
var App application = application{
Name: "odin",
Version: "1.2.3",
Version: "1.3.0-beta",
}
16 changes: 16 additions & 0 deletions internal/backend/component.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package backend

import (
"path"

"github.com/dream11/odin/api/component"
)

type Component struct{}

func (c *Component) OperateComponent(componentName string, data component.OperateComponentRequest) {
client := newStreamingApiClient()
client.Headers["Command-Verb"] = "operate"
response := client.streamWithRetry(path.Join("component", componentName, "operate"), "PUT", data)
response.Process(true)
}
10 changes: 5 additions & 5 deletions internal/backend/componentType.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,35 @@ import (
"encoding/json"
"path"

"github.com/dream11/odin/api/component"
"github.com/dream11/odin/api/componenttype"
)

// ComponentType entity
type ComponentType struct{}

// ListComponentTypes : list all available component types
func (c *ComponentType) ListComponentTypes(componentTypeName, version string) ([]component.Type, error) {
func (c *ComponentType) ListComponentTypes(componentTypeName, version string) ([]componenttype.Type, error) {
client := newApiClient()
client.QueryParams["version"] = version
client.QueryParams["name"] = componentTypeName
response := client.actionWithRetry("componenttypes", "GET", nil)

response.Process(true) // process response and exit if error

var componentTypeResponse component.ListTypeResponse
var componentTypeResponse componenttype.ListTypeResponse
err := json.Unmarshal(response.Body, &componentTypeResponse)

return componentTypeResponse.Response, err
}

// DescribeComponentTypes : describe a component type
func (c *ComponentType) DescribeComponentType(componentTypeName, version string) (component.ComponentDetails, error) {
func (c *ComponentType) DescribeComponentType(componentTypeName, version string) (componenttype.ComponentDetails, error) {
client := newApiClient()
client.QueryParams["version"] = version
response := client.actionWithRetry(path.Join("componenttypes", componentTypeName), "GET", nil)
response.Process(true) // process response and exit if error

var componentDetailsResponse component.ComponentDetailsResponse
var componentDetailsResponse componenttype.ComponentDetailsResponse
err := json.Unmarshal(response.Body, &componentDetailsResponse)

return componentDetailsResponse.Response, err
Expand Down
9 changes: 8 additions & 1 deletion internal/backend/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package backend

import (
"encoding/json"
"errors"
"path"

envResp "github.com/dream11/odin/api/environment"
Expand Down Expand Up @@ -141,11 +142,17 @@ func (e *Env) EnvServiceStatus(env, serviceName string) (envResp.EnvServiceStatu
client := newApiClient()

response := client.actionWithRetry(path.Join(envEntity, env)+"/services/"+serviceName+"/status", "GET", nil)
response.Process(true) // process response and exit if error

var envResponse envResp.EnvServiceStatusResponse
err := json.Unmarshal(response.Body, &envResponse)

if response.Error != nil {
return envResponse.ServiceResponse, response.Error
}
if response.StatusCode >= 400 {
return envResponse.ServiceResponse, errors.New(string(response.Body))
}

return envResponse.ServiceResponse, err
}

Expand Down
19 changes: 19 additions & 0 deletions internal/backend/operation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package backend

import (
"encoding/json"
"path"

operationapi "github.com/dream11/odin/api/operation"
)

type Operation struct{}

func (o *Operation) ListOperations(componentTypeName string) ([]operationapi.Operation, error) {
client := newApiClient()
response := client.actionWithRetry(path.Join("component", componentTypeName, "operate"), "GET", nil)
response.Process(true) // process response and exit if error
var listResponse operationapi.ListOperation
err := json.Unmarshal(response.Body, &listResponse)
return listResponse.Response, err
}
9 changes: 9 additions & 0 deletions internal/command/command_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ func CommandsCatalog() map[string]cli.CommandFactory {
"undeploy service-set": func() (cli.Command, error) {
return &commands.ServiceSet{Undeploy: true}, nil
},
"list operation": func() (cli.Command, error) {
return &commands.Operation{List: true}, nil
},
"describe operation": func() (cli.Command, error) {
return &commands.Operation{Describe: true}, nil
},
"operate component": func() (cli.Command, error) {
return &commands.Component{Operate: true}, nil
},

// Verb for application-template
"generate application-template": func() (cli.Command, error) {
Expand Down
1 change: 1 addition & 0 deletions internal/command/commands/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type command struct {
Release bool // Release a resource record
Set bool // Set a default env
Update bool // Update a env
Operate bool // Operate on a component

Logger ui.Logger // Use this to log messages
Input ui.Input // Use this to take inputs
Expand Down
Loading

0 comments on commit 595bebc

Please sign in to comment.