Primary tech and list of available techs
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				continuous-integration/drone/push Build is passing
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	continuous-integration/drone/push Build is passing
				
			This is initial support limited to running apps only and only for get handler.
This commit is contained in:
		
							parent
							
								
									3fdabb2229
								
							
						
					
					
						commit
						7c46fdd886
					
				
					 5 changed files with 101 additions and 1 deletions
				
			
		
							
								
								
									
										5
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								Makefile
									
									
									
									
									
								
							| 
						 | 
				
			
			@ -19,3 +19,8 @@ minio:
 | 
			
		|||
		-e MINIO_ROOT_USER=test \
 | 
			
		||||
		-e MINIO_ROOT_PASSWORD=testtest \
 | 
			
		||||
		minio/minio server /data --console-address ":9001"
 | 
			
		||||
 | 
			
		||||
.PHONY: clean
 | 
			
		||||
clean:
 | 
			
		||||
	-podman stop rosti-snapshots
 | 
			
		||||
	-podman rm rosti-snapshots
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -84,6 +84,10 @@ type App struct {
 | 
			
		|||
	// Disk usage in inodes
 | 
			
		||||
	DiskUsageInodes int `json:"disk_usage_inodes"`
 | 
			
		||||
 | 
			
		||||
	// this is gathered in docker package and has to be assembled externally
 | 
			
		||||
	Techs       AppTechs `json:"techs,omitempty" gorm:"-"`        // list of available technologies in the image
 | 
			
		||||
	PrimaryTech AppTech  `json:"primary_tech,omitempty" gorm:"-"` // Technology that was selected as primary in the environment
 | 
			
		||||
 | 
			
		||||
	// This is not store in the database but used in create request when the app suppose to be created from an existing snapshot
 | 
			
		||||
	Snapshot string `json:"snapshot" gorm:"-"`
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -119,3 +123,12 @@ func (a *App) Validate() []string {
 | 
			
		|||
 | 
			
		||||
	return errors
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// AppTechs is list of technologies available in the app
 | 
			
		||||
type AppTechs []AppTech
 | 
			
		||||
 | 
			
		||||
// AppTech holds info about one technology in the app
 | 
			
		||||
type AppTech struct {
 | 
			
		||||
	Name    string
 | 
			
		||||
	Version string
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,6 +1,7 @@
 | 
			
		|||
package docker
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"errors"
 | 
			
		||||
	"log"
 | 
			
		||||
	"path"
 | 
			
		||||
	"strings"
 | 
			
		||||
| 
						 | 
				
			
			@ -277,3 +278,59 @@ func (c *Container) GetProcessList() (*[]Process, error) {
 | 
			
		|||
 | 
			
		||||
	return &processes, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetPrimaryTech returns primary tech configured in the container.
 | 
			
		||||
func (c *Container) GetPrimaryTech() (apps.AppTech, error) {
 | 
			
		||||
	tech := apps.AppTech{}
 | 
			
		||||
 | 
			
		||||
	driver := c.getDriver()
 | 
			
		||||
 | 
			
		||||
	stdouterr, err := driver.Exec(c.App.Name, []string{"readlink", "/srv/bin/primary_tech"}, "", []string{}, true)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return tech, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if len(string(*stdouterr)) > 0 {
 | 
			
		||||
		parts := strings.Split(string(*stdouterr), "/")
 | 
			
		||||
		if len(parts) == 5 {
 | 
			
		||||
			rawTech := parts[3]
 | 
			
		||||
			techParts := strings.Split(rawTech, "-")
 | 
			
		||||
			if len(techParts) != 2 {
 | 
			
		||||
				return tech, errors.New("wrong number of tech parts")
 | 
			
		||||
			}
 | 
			
		||||
			return apps.AppTech{
 | 
			
		||||
				Name:    techParts[0],
 | 
			
		||||
				Version: techParts[1],
 | 
			
		||||
			}, nil
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return tech, errors.New("wrong number of path parts")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetTechs returns all techs available in the container
 | 
			
		||||
func (c *Container) GetTechs() (apps.AppTechs, error) {
 | 
			
		||||
	techs := apps.AppTechs{}
 | 
			
		||||
 | 
			
		||||
	driver := c.getDriver()
 | 
			
		||||
 | 
			
		||||
	stdouterr, err := driver.Exec(c.App.Name, []string{"ls", "/opt/techs"}, "", []string{}, true)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return techs, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	techsRaw := strings.Split(string(*stdouterr), "\n")
 | 
			
		||||
	for _, techRaw := range techsRaw {
 | 
			
		||||
		techParts := strings.Split(techRaw, "-")
 | 
			
		||||
		if len(techParts) == 2 {
 | 
			
		||||
			techs = append(techs, apps.AppTech{
 | 
			
		||||
				Name:    techParts[0],
 | 
			
		||||
				Version: techParts[1],
 | 
			
		||||
			})
 | 
			
		||||
		} else {
 | 
			
		||||
			return techs, errors.New("one of the tech has wrong number of parts")
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return techs, nil
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -140,6 +140,31 @@ func getEventHandler(m *nats.Msg, message *RequestMessage) error {
 | 
			
		|||
		return errorReplyFormater(m, "backend error", err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Gather runtime info about the container
 | 
			
		||||
	container := docker.Container{
 | 
			
		||||
		App: app,
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	status, err := container.Status()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Printf("backend error: %v\n", err)
 | 
			
		||||
		return errorReplyFormater(m, "backend error", err)
 | 
			
		||||
	}
 | 
			
		||||
	if status == "running" {
 | 
			
		||||
		var err error
 | 
			
		||||
		app.Techs, err = container.GetTechs()
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			log.Printf("backend error: %v\n", err)
 | 
			
		||||
			return errorReplyFormater(m, "backend error", err)
 | 
			
		||||
		}
 | 
			
		||||
		app.PrimaryTech, err = container.GetPrimaryTech()
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			log.Printf("backend error: %v\n", err)
 | 
			
		||||
			return errorReplyFormater(m, "backend error", err)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Assembling reply message
 | 
			
		||||
	reply := ReplyMessage{
 | 
			
		||||
		AppName: app.Name,
 | 
			
		||||
		Payload: app,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										2
									
								
								stats.go
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								stats.go
									
									
									
									
									
								
							| 
						 | 
				
			
			@ -40,7 +40,7 @@ func updateUsage(name string) error {
 | 
			
		|||
	return err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Updates only container's state
 | 
			
		||||
// Updates only container's state. Check current status of the container and saves it into the database.
 | 
			
		||||
func updateState(name string) error {
 | 
			
		||||
	processor := apps.AppsProcessor{
 | 
			
		||||
		DB: common.GetDBConnection(),
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue