-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added list and describe operation * added list, describe operation and operate component commands * added list, describe operation and operate component commands * linting fixes * blocked service redploy * removed redeploy block from cli --------- Co-authored-by: rahulrayal <[email protected]>
- Loading branch information
1 parent
6ca98fd
commit 5407de7
Showing
12 changed files
with
354 additions
and
70 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 |
---|---|---|
@@ -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"` | ||
} |
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,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"` | ||
} |
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,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"` | ||
} |
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
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) | ||
} |
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
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 | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package commands | ||
|
||
import ( | ||
"encoding/json" | ||
"flag" | ||
"fmt" | ||
|
||
"github.com/dream11/odin/api/component" | ||
"github.com/dream11/odin/internal/backend" | ||
"github.com/dream11/odin/pkg/utils" | ||
) | ||
|
||
var componentClient backend.Component | ||
|
||
type Component command | ||
|
||
func (c *Component) Run(args []string) int { | ||
// Define flag set | ||
flagSet := flag.NewFlagSet("flagSet", flag.ContinueOnError) | ||
name := flagSet.String("name", "", "name of the component") | ||
serviceName := flagSet.String("service", "", "name of the service in which the component is deployed") | ||
envName := flagSet.String("env", "", "name of the environment in which the service is deployed") | ||
operation := flagSet.String("operation", "", "name of the operation to performed on the component") | ||
options := flagSet.String("options", "", "options of the operation in JSON format") | ||
|
||
err := flagSet.Parse(args) | ||
if err != nil { | ||
c.Logger.Error("Unable to parse flags! " + err.Error()) | ||
return 1 | ||
} | ||
|
||
if c.Operate { | ||
if *envName == "" { | ||
*envName = utils.FetchKey(ENV_NAME_KEY) | ||
} | ||
emptyParameters := emptyParameters(map[string]string{"--name": *name, "--service": *serviceName, "--env": *envName, "--operation": *operation, "--options": *options}) | ||
if len(emptyParameters) == 0 { | ||
var optionsJson interface{} | ||
err = json.Unmarshal([]byte(*options), &optionsJson) | ||
if err != nil { | ||
c.Logger.Error("Unable to parse options JSON " + err.Error()) | ||
return 1 | ||
} | ||
|
||
data := component.OperateComponentRequest{ | ||
Data: component.Data{ | ||
EnvName: *envName, | ||
ServiceName: *serviceName, | ||
Operations: []component.Operation{ | ||
{ | ||
Name: *operation, | ||
Values: optionsJson, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
componentClient.OperateComponent(*name, data) | ||
return 0 | ||
} | ||
|
||
c.Logger.Error(fmt.Sprintf("%s cannot be blank", emptyParameters)) | ||
return 1 | ||
} | ||
|
||
c.Logger.Error("Not a valid command") | ||
return 127 | ||
} | ||
|
||
// Help : returns an explanatory string | ||
func (c *Component) Help() string { | ||
if c.Operate { | ||
return commandHelper("operate", "component", "", []Options{ | ||
{Flag: "--name", Description: "name of the component"}, | ||
{Flag: "--service", Description: "name of the service in which the component is deployed"}, | ||
{Flag: "--env", Description: "name of the environment in which the service is deployed"}, | ||
{Flag: "--operation", Description: "name of the operation to performed on the component"}, | ||
{Flag: "--options", Description: "options of the operation in JSON format"}, | ||
}) | ||
} | ||
return defaultHelper() | ||
} | ||
|
||
// Synopsis : returns a brief helper text for the command's verbs | ||
func (c *Component) Synopsis() string { | ||
if c.Operate { | ||
return "Operate on a component" | ||
} | ||
return defaultHelper() | ||
} |
Oops, something went wrong.