Skip to content

Commit

Permalink
Odin New version (#63)
Browse files Browse the repository at this point in the history
* fix: show overall service status in env service status

* fix: service list help

* fix: order of empty flags

* feat: platform parameter while deploying service

Co-authored-by: Harshit Sharma <[email protected]>
Co-authored-by: Swapnesh Kumar <[email protected]>
Co-authored-by: Shobhit <[email protected]>
Co-authored-by: Akshay Patidar <[email protected]>
Co-authored-by: Shobhit <[email protected]>
Co-authored-by: dhavalmehta07 <[email protected]>
Co-authored-by: Swapnesh Kumar <[email protected]>
Co-authored-by: Harshit Sharma <[email protected]>
Co-authored-by: Pawan Tejwani <[email protected]>
Co-authored-by: sarveshdream11 <[email protected]>
Co-authored-by: BalkishanNanavath <[email protected]>
  • Loading branch information
12 people authored Mar 17, 2022
1 parent 44b3b30 commit d846a04
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 29 deletions.
4 changes: 2 additions & 2 deletions api/component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type Component struct {
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:"deployment_platform_mapping,omitempty" json:"deployment_platform_mapping,omitempty"`
DeploymentPlatformMapping interface{} `yaml:"behaviour,omitempty" json:"behaviour,omitempty"`
}

// Type interface
Expand All @@ -25,7 +25,7 @@ type Type struct {
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:"deployment_platform_mapping,omitempty" json:"deployment_platform_mapping,omitempty"`
DeploymentPlatformMapping interface{} `yaml:"behaviour,omitempty" json:"behaviour,omitempty"`
}

// ListTypeResponse interface
Expand Down
2 changes: 2 additions & 0 deletions api/environment/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@ type EnvServiceStatus struct {
LastDeployedAt string `yaml:"lastDeployedAt,omitempty" json:"lastDeployedAt,omitempty"`
Version string `yaml:"version,omitempty" json:"version,omitempty"`
Components []Status `yaml:"components,omitempty" json:"components,omitempty"`
Status string `yaml:"status,omitempty" json:"status,omitempty"`
}

type EnvStatus struct {
ServiceStatus []EnvStatusPerService `yaml:"services,omitempty" json:"services,omitempty"`
Status string `yaml:"status,omitempty" json:"status,omitempty"`
}

type EnvStatusPerService struct {
Expand Down
7 changes: 4 additions & 3 deletions api/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
type Service struct {
Name string `yaml:"name,omitempty" json:"name,omitempty"`
Version string `yaml:"version,omitempty" json:"version,omitempty"`
Platform string `yaml:"platform,omitempty" json:"platform,omitempty"`
Team []string `yaml:"team,omitempty" json:"team,omitempty"`
Description string `yaml:"description,omitempty" json:"description,omitempty"`
Mature *bool `yaml:"isMature,omitempty" json:"isMature,omitempty"`
Expand All @@ -32,9 +33,9 @@ type DetailResponse struct {

// Status interface
type Status struct {
Name string `yaml:"name,omitempty" json:"name,omitempty"`
Ec2 string `yaml:"ec2,omitempty" json:"ec2,omitempty"`
Docker string `yaml:"docker,omitempty" json:"docker,omitempty"`
Name string `yaml:"name,omitempty" json:"name,omitempty"`
VM string `yaml:"vm,omitempty" json:"vm,omitempty"`
Container string `yaml:"container,omitempty" json:"container,omitempty"`
}

// StatusResponse 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.0.0-alpha",
Version: "1.0.1-alpha",
}
3 changes: 2 additions & 1 deletion internal/backend/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,12 @@ func (s *Service) MarkMature(service, version string) {
}

// DeployService : deploy a service
func (s *Service) DeployService(service, version, env string, force, rebuild bool) {
func (s *Service) DeployService(service, version, env, platform string, force, rebuild bool) {
client := newApiClient()
client.QueryParams["env_name"] = env
client.QueryParams["force"] = fmt.Sprintf("%v", force)
client.QueryParams["rebuild"] = fmt.Sprintf("%v", rebuild)
client.QueryParams["platform"] = platform

response := client.action(path.Join(serviceEntity, "deploy", service, "versions", version)+"/", "POST", nil)
response.Process(true)
Expand Down
2 changes: 2 additions & 0 deletions internal/command/commands/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package commands

import (
"fmt"
"sort"
"strings"

odin "github.com/dream11/odin/app"
Expand Down Expand Up @@ -56,5 +57,6 @@ func emptyParameters(params map[string]string) string {
emptyParameters = append(emptyParameters, key)
}
}
sort.Strings(emptyParameters)
return strings.Join(emptyParameters, ", ")
}
2 changes: 1 addition & 1 deletion internal/command/commands/componentType.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (c *ComponentType) Run(args []string) int {
return 1
}

c.Logger.Output(string(details))
c.Logger.Output(fmt.Sprintf("\n%s", details))

return 0
}
Expand Down
21 changes: 11 additions & 10 deletions internal/command/commands/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (e *Env) Run(args []string) int {
name := flagSet.String("name", "", "name of environment")
team := flagSet.String("team", "", "display environments created by a team")
purpose := flagSet.String("purpose", "", "reason to create environment")
env := flagSet.String("env-type", "kube", "environment to attach with environment")
env := flagSet.String("env-type", "dev", "environment to attach with environment")
service := flagSet.String("service", "", "service name to filter out describe environment")
component := flagSet.String("component", "", "component name to filter out describe environment")
providerAccount := flagSet.String("account", "", "account name to provision the environment in")
Expand Down Expand Up @@ -72,10 +72,9 @@ func (e *Env) Run(args []string) int {
if e.Status {
emptyParameters := emptyParameters(map[string]string{"--name": *name})
if len(emptyParameters) == 0 {
e.Logger.Info("Fetching status for environment: " + *name + ", service: " + *service)

if *service != "" {

e.Logger.Info(fmt.Sprintf("Fetching status for service: %s in environment: %s", *service, *name))
envServiceStatus, err := envClient.EnvServiceStatus(*name, *service)
if err != nil {
e.Logger.Error(err.Error())
Expand All @@ -84,6 +83,7 @@ func (e *Env) Run(args []string) int {

relativeDeployedSinceTime := datetime.DateTimeFromNow(envServiceStatus.LastDeployedAt)
e.Logger.Output("Service version: " + string(envServiceStatus.Version))
e.Logger.Output("Service Status: " + string(envServiceStatus.Status))
e.Logger.Output("Last deployed: " + relativeDeployedSinceTime)
e.Logger.Output("Component details: ")

Expand All @@ -105,16 +105,16 @@ func (e *Env) Run(args []string) int {
}

} else {

e.Logger.Info(fmt.Sprintf("Fetching status for environment: %s", *name))
envStatus, err := envClient.EnvStatus(*name)
if err != nil {
e.Logger.Error(err.Error())
return 1
}

e.Logger.Output(fmt.Sprintf("Environment Status: %s\n", envStatus.Status))
tableHeaders := []string{"Name", "Version", "Status", "Last deployed"}
var tableData [][]interface{}

e.Logger.Output("Services:")
for _, serviceStatus := range envStatus.ServiceStatus {
relativeDeployedSinceTime := datetime.DateTimeFromNow(serviceStatus.LastDeployedAt)
tableData = append(tableData, []interface{}{
Expand Down Expand Up @@ -193,7 +193,7 @@ func (e *Env) Run(args []string) int {
return 1
}

e.Logger.Output(string(details))
e.Logger.Output(fmt.Sprintf("\n%s", details))
if *service == "" && *component == "" {
e.Logger.Output("\nCommand to descibe env")
e.Logger.ItalicEmphasize(fmt.Sprintf("odin describe env --name %s --service <serviceName> --component <componentName>", *name))
Expand Down Expand Up @@ -245,9 +245,9 @@ func (e *Env) Run(args []string) int {
if e.Delete {
emptyParameters := emptyParameters(map[string]string{"--name": *name})
if len(emptyParameters) == 0 {
e.Logger.Warn("Deleting environment:" + *name)
e.Logger.Info("Deleting environment: " + *name)
envClient.DeleteEnv(*name)

e.Logger.Success(fmt.Sprintf("Deletion started: %s", *name))
return 0
}

Expand All @@ -265,13 +265,14 @@ func (e *Env) Run(args []string) int {
return 1
}

tableHeaders := []string{"ID", "Action", "Resource Details", "Modified by", "Last Modified"}
tableHeaders := []string{"ID", "State", "Action", "Resource Details", "Modified by", "Last Modified"}
var tableData [][]interface{}

for _, env := range envResp {
relativeCreationTimestamp := datetime.DateTimeFromNow(env.CreatedAt)
tableData = append(tableData, []interface{}{
env.ID,
env.State,
env.Action,
env.ResourceDetails,
env.CreatedBy,
Expand Down
29 changes: 18 additions & 11 deletions internal/command/commands/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func (s *Service) Run(args []string) int {
isMature := flagSet.Bool("mature", false, "mark service version as matured")
rebuild := flagSet.Bool("rebuild", false, "rebuild executor for creating images or deploying services")
component := flagSet.String("component", "", "name of service component")
platform := flagSet.String("platform", "", "platform to deploy the service in")

err := flagSet.Parse(args)
if err != nil {
Expand Down Expand Up @@ -77,11 +78,12 @@ func (s *Service) Run(args []string) int {
s.Logger.Error("Unrecognized file format")
return 1
}

serviceDataMap := parsedConfig.(map[string]interface{})
serviceClient.CreateService(parsedConfig)
s.Logger.Success(fmt.Sprintf("Service creation started for %s@%s ", serviceDataMap["name"], serviceDataMap["version"]))

s.Logger.Output("Command to check status of images")
s.Logger.ItalicEmphasize("odin status service --name <serviceName> --version <serviceVersion>")
s.Logger.ItalicEmphasize(fmt.Sprintf("odin status service --name %s --version %s", serviceDataMap["name"], serviceDataMap["version"]))
return 0
}

Expand Down Expand Up @@ -109,7 +111,7 @@ func (s *Service) Run(args []string) int {
return 1
}

s.Logger.Output(string(details))
s.Logger.Output(fmt.Sprintf("\n%s", details))
if len(*component) == 0 {
s.Logger.Output("Command to get component details")
s.Logger.ItalicEmphasize(fmt.Sprintf("odin describe service --name %s --version <serviceVersion> --component <componentName>", *serviceName))
Expand All @@ -128,8 +130,12 @@ func (s *Service) Run(args []string) int {
s.Logger.Error(err.Error())
return 1
}

tableHeaders := []string{"Name", "Version", "Description", "Team", "Mature"}
var tableHeaders []string
if len(*serviceName) == 0 {
tableHeaders = []string{"Name", "Latest Version", "Description", "Team", "Mature"}
} else {
tableHeaders = []string{"Name", "Version", "Description", "Team", "Mature"}
}
var tableData [][]interface{}

for _, service := range serviceList {
Expand Down Expand Up @@ -177,8 +183,9 @@ func (s *Service) Run(args []string) int {
emptyParameters := emptyParameters(map[string]string{"--name": *serviceName, "--version": *serviceVersion, "--env": *envName})
if len(emptyParameters) == 0 {
s.Logger.Info("Deploying service: " + *serviceName + "@" + *serviceVersion + " in " + *envName)
serviceClient.DeployService(*serviceName, *serviceVersion, *envName, *platform, *force, *rebuild)

serviceClient.DeployService(*serviceName, *serviceVersion, *envName, *force, *rebuild)
s.Logger.Success(fmt.Sprintf("Deployment of service %s@%s is started on env %s", *serviceName, *serviceVersion, *envName))

return 0
}
Expand All @@ -190,7 +197,7 @@ func (s *Service) Run(args []string) int {
if s.Undeploy {
emptyParameters := emptyParameters(map[string]string{"--name": *serviceName, "--env": *envName})
if len(emptyParameters) == 0 {
s.Logger.Info("Undeploying service: " + *serviceName + " from environment" + *envName)
s.Logger.Info("Undeploying service: " + *serviceName + " from environment " + *envName)
serviceClient.UndeployService(*serviceName, *envName)

s.Logger.Success("Job Triggered to undeploy your service " + *serviceName + " from the env " + *envName)
Expand Down Expand Up @@ -229,8 +236,8 @@ func (s *Service) Run(args []string) int {
for _, componentStatus := range serviceStatus {
tableData = append(tableData, []interface{}{
componentStatus.Name,
componentStatus.Ec2,
componentStatus.Docker,
componentStatus.VM,
componentStatus.Container,
})
}

Expand Down Expand Up @@ -270,10 +277,10 @@ func (s *Service) Help() string {

if s.List {
return commandHelper("list", "service", []string{
"--team=name of team",
"--name=name of service",
"--version=version of services to be listed",
"--team=name of team",
"--mature (mature marked service versions)",
"--detailed (get a detailed view)",
})
}

Expand Down

0 comments on commit d846a04

Please sign in to comment.