springboot

package module
v0.0.0-...-44f4162 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2023 License: MIT Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AppNameField                = "Implementation-Title"
	VersionField                = "Implementation-Version"
	MainClassField              = "Main-Class"
	JdkVersionField             = "Build-Jdk-Spec"
	JdkVersionFieldFor1x        = "Build-Jdk"
	SpringBootVersionField      = "Spring-Boot-Version"
	JarLauncherClassName        = "org.springframework.boot.loader.JarLauncher"
	PropertiesLauncherClassName = "org.springframework.boot.loader.PropertiesLauncher"

	PomFileName                 = "pom.xml"
	SpringBootStarterGroupId    = "org.springframework.boot"
	SpringBootStarterArtifactId = "spring-boot-starter-parent"
	SpringBootJarFilePrefix     = "spring-boot"
	JavaVersionPropertyName     = "java.version"
	CompilerTargetPropertyName  = "maven.compiler.target"
	CompilerReleasePropertyName = "maven.compiler.target"
	DefaultClasspath            = "BOOT-INF/classes/"
	DefaultLibPath              = "BOOT-INF/lib/"
	DefaultMvnPath              = "META-INF/maven/"
	ApplicationNameKey          = "spring.application.name"
	ApplicationPortKey          = "server.port"
)
View Source
const (
	LinuxProcessScanCmd       = "ps axo pid,uid,cmd | grep [j]ava | grep '\\-jar' | grep -v grep"
	LinuxLocateJarCmd         = "ls -l /proc/%d/fd | grep %s | head -1 | awk '{print $11}'"
	LinuxSha256Cmd            = "sha256sum %s | awk '{print $1}'"
	LinuxGetEnvCmd            = "cat /proc/%d/environ"
	LinuxGetJdkVersionCmd     = "%s -version 2>&1 | head -n 1 | awk -F '\"' '{print $2}'"
	LinuxGetTotalMemoryCmd    = "cat /proc/meminfo | grep MemTotal | awk '{print $2}'"
	LinuxGetDefaultMaxHeapCmd = "%s -XX:+PrintFlagsFinal 2>1 | grep ' MaxHeapSize ' | awk '{print $4}'"
	LinuxGetPortsCmd          = `` /* 239-byte string literal not displayed */
	LinuxGetOsName            = "grep '^ID=' /etc/os-release | awk -F= '{print $2}'"
	LinuxGetOsVersion         = "grep '^VERSION_ID=' /etc/os-release | awk -F= '{print $2}'"
	CentOsGetName             = "cat /etc/centos-release | awk '{print $1}'"
	CentOsGetVersion          = "cat /etc/centos-release | awk '{print $3}'"
)
View Source
const (
	JavaCmd                   = "java"
	JarOption                 = "-jar"
	JvmOptionXmx              = "-Xmx"
	JvmOptionMaxRamPercentage = "-XX:MaxRAMPercentage"
	KiB                       = 1024
	MiB                       = KiB * 1024
)
View Source
const (
	ManifestFile = "MANIFEST.MF"
	JarFileExt   = ".jar"
)

Variables

View Source
var (
	ExecutableProcess   = fmt.Sprintf(" %d 1000 java -javaagent:/path/to/applicationinsights.jar -XX:InitialRAMPercentage=60.0 -XX:MaxRAMPercentage=60.0 -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.password=testpassword1234 -Dcom.sun.management.jmxremote.local.only=true -Dmanagement.endpoints.jmx.exposure.include=health,metrics -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -DtestOption=abc=def -Dspring.jmx.enabled=true -Dserver.tomcat.mbeanregistry.enabled=true -Dfile.encoding=UTF8 -Dspring.config.import=optional:configserver:/ -Dcom.sun.management.jmxremote.password=testpassword1234 -jar %s", ExecutableProcessId, ExecutableJarFile)
	SpringBoot2xProcess = fmt.Sprintf("%d     0 /usr/bin/qemu-x86_64 /usr/bin/java -javaagent:/path/to/applicationinsights.jar -Xmx128m -Xms128m -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.local.only=true -Dmanagement.endpoints.jmx.exposure.include=healthmetrics -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -DtestOption=abc=def -Dspring.jmx.enabled=true -Dserver.tomcat.mbeanregistry.enabled=true -Dfile.encoding=UTF8 -Dspring.config.import=optional:configserver:/ -Dcom.sun.management.jmxremote.password=testpassword1234 -jar %s", SpringBoot2xProcessId, SpringBoot2xJarFileLocation)
	SpringBoot1xProcess = fmt.Sprintf("%d     0 /usr/bin/qemu-x86_64 /usr/bin/java -javaagent:/path/to/applicationinsights.jar -Xmx128m -Xms128m -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.local.only=true -Dmanagement.endpoints.jmx.exposure.include=healthmetrics -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -DtestOption=abc=def -Dspring.jmx.enabled=true -Dserver.tomcat.mbeanregistry.enabled=true -Dfile.encoding=UTF8 -Dspring.config.import=optional:configserver:/ -Dcom.sun.management.jmxremote.password=testpassword1234 -jar %s", SpringBoot1xProcessId, SpringBoot1xJarFileLocation)
	ErrorProcess        = fmt.Sprintf("%d     0 /usr/bin/qemu-x86_64 /usr/bin/java -javaagent:/path/to/applicationinsights.jar -Xmx128m -Xms128m -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.local.only=true -Dmanagement.endpoints.jmx.exposure.include=healthmetrics -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -DtestOption=abc=def -Dspring.jmx.enabled=true -Dserver.tomcat.mbeanregistry.enabled=true -Dfile.encoding=UTF8 -Dspring.config.import=optional:configserver:/ -Dcom.sun.management.jmxremote.password=testpassword1234 -jar %s", ErrorProcessId, SpringBoot1xJarFileLocation)

	Manifest = `` /* 461-byte string literal not displayed */

	TestEnv = "" /* 2056-byte string literal not displayed */

	TestJvmOptions = []string{
		"-XX:InitialRAMPercentage=60.0",
		"-XX:MaxRAMPercentage=60.0",
		"-Dcom.sun.management.jmxremote",
		"-Dcom.sun.management.jmxremote.password=testpassword1234",
		"-Dcom.sun.management.jmxremote.port=1099",
		"-Dcom.sun.management.jmxremote.local.only=true",
		"-Dmanagement.endpoints.jmx.exposure.include=health,metrics",
		"-Dcom.sun.management.jmxremote.authenticate=false",
		"-Dcom.sun.management.jmxremote.ssl=false",
		"-DtestOption=abc=def",
		"-Dspring.jmx.enabled=true",
		"-Dserver.tomcat.mbeanregistry.enabled=true",
		"-Dfile.encoding=UTF8",
		"-Dspring.application.name=hellospring2x",
		"-Dspring.config.import=optional:configserver:/",
		"-jar",
	}

	TotalMemory = "  987654321\n"

	DefaultMaxHeapSize = "  987654321\n"

	Checksum = "  987654321\n"

	RuntimeJdkVersion = " 11.0.16_232\n"

	SpringBoot1xAppName = "hellospring1x"
	SpringBoot2xAppName = "hellospring2x"
	ExecutableAppName   = "executable"
	SpringBoot1xCrName  = "hellospring1x-hellospring"
	SpringBoot2xCrName  = "hellospring2x-hellospring"
	ExecutableCrName    = "executable-executable"
	SpringBoot1xJarFile = "hellospring1x-0.0.1-SNAPSHOT.jar"
	SpringBoot2xJarFile = "hellospring2x-0.0.1-SNAPSHOT.jar"
	ExecutableJarFile   = "executable-0.0.1-SNAPSHOT.jar"
	SpringBoot1xVersion = "1.5.14.RELEASE"
	SpringBoot2xVersion = "2.4.13"
	Jdk7Version         = "1.7"
	Jdk8Version         = "8"

	SpringBoot1xProcessId = 1024
	SpringBoot2xProcessId = 1
	ExecutableProcessId   = 5647
	ErrorProcessId        = 999

	SpringBoot2xJarFileLocation = fmt.Sprintf("/home/azure/%s", SpringBoot2xJarFile)
	SpringBoot1xJarFileLocation = fmt.Sprintf("/home/azure/%s", SpringBoot1xJarFile)
	ExecutableJarFileLocation   = fmt.Sprintf("/home/azure/%s", ExecutableJarFile)

	Ports = "  22\n 8080\n38193\n44981"

	Host = "centos-8-openjdk11"

	Pom = `` /* 2635-byte string literal not displayed */

	ApplicationYaml = `` /* 415-byte string literal not displayed */

	ApplicationProperties = `` /* 291-byte string literal not displayed */

)
View Source
var ConfigPathEnvKey = "CONFIG_PATH"
View Source
var DefaultJarFileWalkers = []JarFileWalker{
	appConfigWalker,
	loggingConfigWalker,
	manifestWalker,
	certWalker,
	dependencyWalker,
	staticContentWalker,
	pomFileWalker,
}
View Source
var Patterns = newPatterns()
View Source
var YamlCfg = NewYamlConfigOrDie(defaultConfigYaml)

Functions

func CleanOutput

func CleanOutput(raw string) string

func CmdMatcher

func CmdMatcher(cmd string) gomock.Matcher

func Contains

func Contains[T ~string](slices []T, find T) bool

func GetCentOsName

func GetCentOsName() string

func GetCentOsVersion

func GetCentOsVersion() string

func GetConfigFromProperties

func GetConfigFromProperties(key, content string) (string, bool)

func GetConfigFromYaml

func GetConfigFromYaml[T any](key, content string) (T, bool)

func GetDefaultMaxHeap

func GetDefaultMaxHeap(javaCmd string) string

func GetEnvCmd

func GetEnvCmd(pid int) string

func GetJdkVersionCmd

func GetJdkVersionCmd(javaCmd string) string

func GetLocateJarCmd

func GetLocateJarCmd(pid int, filename string) string

func GetOsName

func GetOsName() string

func GetOsVersion

func GetOsVersion() string

func GetPortsCmd

func GetPortsCmd(pid int) string

func GetProcessScanCmd

func GetProcessScanCmd() string

func GetSha256Cmd

func GetSha256Cmd(filename string) string

func GetTotalMemoryCmd

func GetTotalMemoryCmd() string

func GreatThan

func GreatThan(versionA, versionB string) bool

func IsConnectionError

func IsConnectionError(err error) bool

func IsCredentialError

func IsCredentialError(err error) bool

func IsJoinErrors

func IsJoinErrors(err error) bool

func IsPermissionDenied

func IsPermissionDenied(err error) bool

func IsSshError

func IsSshError(err error) bool

func IsValidJdkVersion

func IsValidJdkVersion(version string) bool

func Join

func Join(errs ...error) error

func LessThan

func LessThan(versionA, versionB string) bool

func MatchVersion

func MatchVersion(expected string) types.GomegaMatcher

func New

func New[T any]() T

func ParseProperties

func ParseProperties(content string) map[string]string

func ParseYaml

func ParseYaml(content string) (map[string]interface{}, error)

func SanitizeVersion

func SanitizeVersion(version string) string

func ToSlice

func ToSlice[T any](s Stream) ([]T, error)

Types

type AppType

type AppType string
const (
	SpringBootFatJar   AppType = "SpringBootFatJar"
	SpringBootThinJar  AppType = "SpringBootThinJar"
	SpringBootExploded AppType = "SpringBootExploded"
	ExecutableJar      AppType = "ExecutableJar"
	Unknown            AppType = "Unknown"
)

type AppTypes

type AppTypes []AppType

func (AppTypes) Contains

func (types AppTypes) Contains(appType AppType) bool

type Artifact

type Artifact struct {
	Group   string `json:"group"`
	Name    string `json:"name"`
	Version string `json:"version"`
}

type AuthType

type AuthType int32

type Combinator

type Combinator[T any] func(a, b T) T

func IntSum

func IntSum() Combinator[any]

func StringJoiner

func StringJoiner(sep string) Combinator[any]

type Comparator

type Comparator[T comparable] func(a, b T) int

func IntComparator

func IntComparator() Comparator[int]

func StringComparator

func StringComparator() Comparator[string]

type Connect

type Connect struct {
	Parallel    bool `yaml:"parallel"`
	Parallelism int  `yaml:"parallelism"`
}

Connect

type ConnectionError

type ConnectionError struct {
	// contains filtered or unexported fields
}

func (ConnectionError) Error

func (ce ConnectionError) Error() string

func (ConnectionError) Unwrap

func (ce ConnectionError) Unwrap() error

type ConnectionTimeoutError

type ConnectionTimeoutError struct {
	// contains filtered or unexported fields
}

func (ConnectionTimeoutError) Error

func (ce ConnectionTimeoutError) Error() string

type ConsoleOutput

type ConsoleOutput struct {
	Patterns []string `yaml:"patterns"`
	Yamlpath []string `yaml:"yamlpath"`
}

ConsoleOutput

type Credential

type Credential struct {
	Id             string `json:"Id,omitempty"`
	FriendlyName   string `json:"FriendlyName,omitempty"`
	Username       string `json:"UserName,omitempty"`
	Password       string `json:"Password,omitempty"`
	CredentialType string `json:"CredentialType,omitempty"`
}

type CredentialError

type CredentialError struct {
	// contains filtered or unexported fields
}

func (CredentialError) Error

func (ce CredentialError) Error() string

func (CredentialError) Unwrap

func (ce CredentialError) Unwrap() error

type CredentialProvider

type CredentialProvider interface {
	GetCredentials() ([]*Credential, error)
}

type CustomLogger

type CustomLogger struct {
	// contains filtered or unexported fields
}

func GetAzureLogger

func GetAzureLogger(ctx context.Context, annotationsMaps ...map[string]string) *CustomLogger

func (*CustomLogger) Debug

func (c *CustomLogger) Debug(msg string, keysAndValues ...interface{})

func (*CustomLogger) Error

func (c *CustomLogger) Error(err error, msg string, keysAndValues ...interface{})

func (*CustomLogger) Info

func (c *CustomLogger) Info(msg string, keysAndValues ...interface{})

func (*CustomLogger) IntoContext

func (c *CustomLogger) IntoContext(ctx context.Context) context.Context

func (*CustomLogger) Warning

func (c *CustomLogger) Warning(err error, msg string, keysAndValues ...interface{})

type DiscoveryExecutor

type DiscoveryExecutor interface {
	Discover(ctx context.Context, server ServerConnectionInfo, alternativeConnectionInfos ...ServerConnectionInfo) ([]*SpringBootApp, error)
}

func NewSpringBootDiscoveryExecutor

func NewSpringBootDiscoveryExecutor(
	credentialProvider CredentialProvider,
	serverConnectorFactory ServerConnectorFactory,
	cfg YamlConfig,
) DiscoveryExecutor

type Env

type Env struct {
	Denylist []string `yaml:"denylist"`
}

Env

type JarFile

type JarFile interface {
	GetLocation() string
	GetAppType() AppType
	GetArtifactGroup() (string, error)
	GetArtifactName() (string, error)
	GetArtifactVersion() (string, error)
	GetAppName(process JavaProcess) (string, error)
	GetAppPort(process JavaProcess) (int, error)
	GetChecksum() (string, error)
	GetBuildJdkVersion() (string, error)
	GetSpringBootVersion() (string, error)
	GetDependencies() ([]string, error)
	GetApplicationConfigurations() (map[string]string, error)
	GetLoggingFiles() (map[string]string, error)
	GetCertificates() ([]string, error)
	GetStaticFiles() ([]string, error)
	GetLastModifiedTime() (time.Time, error)
	GetSize() (int64, error)
	GetManifests() map[string]string
	GetMavenProject() *mvnparser.MavenProject
}

type JarFileWalker

type JarFileWalker func(name string, f *zip.File, j *jarFile) error

type JavaProcess

type JavaProcess interface {
	GetProcessId() int
	GetUid() int
	GetRuntimeJdkVersion() (string, error)
	LocateJarFile() (string, error)
	GetJavaCmd() (string, error)
	GetJvmOptions() ([]string, error)
	GetEnvironments() ([]string, error)
	GetJvmMemory() (int64, error)
	GetPorts() ([]int, error)
	Executor() ServerDiscovery
}

type JoinErrors

type JoinErrors struct {
	// contains filtered or unexported fields
}

func (JoinErrors) Error

func (je JoinErrors) Error() string

func (JoinErrors) Unwrap

func (je JoinErrors) Unwrap() []error

type Logging

type Logging struct {
	ConsoleOutput ConsoleOutput `yaml:"console_output"`
	FilePatterns  []string      `yaml:"file_patterns"`
}

Logging

type Monad

type Monad struct {
	// contains filtered or unexported fields
}

func Of

func Of[T any](actual T, extras ...any) *Monad

func (*Monad) Field

func (m *Monad) Field(field string) *Monad

func (*Monad) Map

func (m *Monad) Map(mapFunc func(val any) any) *Monad

type MonadConstraints

type MonadConstraints interface {
	*SpringBootApp | *Runtime | *Artifact
}

type Monadic

type Monadic[T MonadConstraints] struct {
	// contains filtered or unexported fields
}

func NewMonadic

func NewMonadic[T MonadConstraints](process JavaProcess, jarFile JarFile) *Monadic[T]

func (*Monadic[T]) Apply

func (m *Monadic[T]) Apply(f StepFunc) *Monadic[T]

func (*Monadic[T]) Final

func (m *Monadic[T]) Final(monad *Monad) error

func (*Monadic[T]) Get

func (m *Monadic[T]) Get() (T, error)

type Pattern

type Pattern struct {
	Logging Logging  `yaml:"logging"`
	Cert    []string `yaml:"cert"`
	Static  Static   `yaml:"static"`
	App     []string `yaml:"app"`
}

Pattern

type PermissionDenied

type PermissionDenied struct {
	// contains filtered or unexported fields
}

func (PermissionDenied) Error

func (pe PermissionDenied) Error() string

func (PermissionDenied) Unwrap

func (pe PermissionDenied) Unwrap() error

type Predicate

type Predicate func(t any) bool

type RetryPolicy

type RetryPolicy struct {
	// contains filtered or unexported fields
}

func PolicyOf

func PolicyOf(max int, interval time.Duration) RetryPolicy

type Runtime

type Runtime struct {
	Server            string   `json:"server"`
	Uid               int      `json:"uid"`
	Pid               int      `json:"pid"`
	RuntimeJdkVersion string   `json:"runtimeJdkVersion"`
	AppPort           int      `json:"appPort"`
	JavaCmd           string   `json:"javaCmd"`
	Environments      []string `json:"environments"`
	JvmOptions        []string `json:"jvmOptions"`
	JvmMemory         int64    `json:"jvmMemory"`
	OsName            string   `json:"osName"`
	OsVersion         string   `json:"osVersion"`
	BindingPorts      []int    `json:"bindingPorts"`
}

type Server

type Server struct {
	Connect Connect `yaml:"connect"`
}

Server

type ServerConnectionInfo

type ServerConnectionInfo struct {
	Server string
	Port   int
}

type ServerConnector

type ServerConnector interface {
	FQDN() string
	Connect(username, password string) error
	Close() error
	Read(remoteLocation string) (io.ReaderAt, os.FileInfo, error)
	RunCmd(cmd string) (string, error)
	Username() string
}

type ServerConnectorFactory

type ServerConnectorFactory interface {
	Create(ctx context.Context, host string, port int) ServerConnector
}

func DefaultServerConnectorFactory

func DefaultServerConnectorFactory(opts ...SshOption) ServerConnectorFactory

type ServerDiscovery

type ServerDiscovery interface {
	Prepare() (*Credential, error)
	Server() ServerConnector
	ProcessScan() ([]JavaProcess, error)
	GetTotalMemory() (int64, error)
	GetOsName() (string, error)
	GetOsVersion() (string, error)
	ReadJarFile(location string, walkers ...JarFileWalker) (JarFile, error)
	Finish() error
}

func NewLinuxServerDiscovery

func NewLinuxServerDiscovery(
	ctx context.Context,
	serverConnector ServerConnector,
	credentialProvider CredentialProvider,
	cfg YamlConfig) ServerDiscovery

type SpringBootApp

type SpringBootApp struct {
	AppName                   string            `json:"appName"`
	AppType                   AppType           `json:"appType"`
	ApplicationConfigurations map[string]string `json:"applicationConfigurations"`
	Artifact                  *Artifact         `json:"artifact"`
	BuildJdkVersion           string            `json:"buildJdkVersion"`
	Checksum                  string            `json:"checksum"`
	Certificates              []string          `json:"certificates"`
	Dependencies              []string          `json:"dependencies"`
	JarFileLocation           string            `json:"jarFileLocation"`
	JarSize                   int64             `json:"jarSize"`
	LoggingConfigurations     map[string]string `json:"loggingConfigurations"`
	LastModifiedTime          time.Time         `json:"lastModifiedTime"`
	LastUpdatedTime           time.Time         `json:"lastUpdatedTime"`
	Runtime                   *Runtime          `json:"runtime"`
	SpringBootVersion         string            `json:"springBootVersion"`
	StaticContentLocations    []string          `json:"staticContentLocations"`
}

type SshError

type SshError struct {
	// contains filtered or unexported fields
}

func (SshError) Error

func (se SshError) Error() string

func (SshError) Unwrap

func (se SshError) Unwrap() error

type SshOption

type SshOption func(s *linuxServer)

func WithClient

func WithClient(client *ssh.Client) SshOption

func WithConnectionTimeout

func WithConnectionTimeout(timeout time.Duration) SshOption

func WithHostKeyCallback

func WithHostKeyCallback(callback ssh.HostKeyCallback) SshOption

func WithKeyAlgorithms

func WithKeyAlgorithms(algos []string) SshOption

type Static

type Static struct {
	Folder    []string `yaml:"folder"`
	Extension []string `yaml:"extension"`
}

Static

type StepFunc

type StepFunc func(process JavaProcess, jarFile JarFile) *Monad

type Stream

type Stream interface {
	ForEach(f interface{}) error
	Peek(f interface{}) Stream
	Map(f interface{}) Stream
	FlatMap(f interface{}) Stream
	Distinct() Stream
	Filter(f Predicate) Stream
	Join(sep string) (string, error)
	Retry(policy RetryPolicy) Stream
	Take(n int) Stream
	First() (any, error)
	Sorted(less interface{}) Stream
	Reduce(seed any, c Combinator[any]) (any, error)
	Parallel(parallelism int) Stream
	GroupBy(keyFunc func(t any) string, combinator Combinator[any]) (map[string]any, error)
	// contains filtered or unexported methods
}

func FromSlice

func FromSlice[T any](ctx context.Context, slice []T) Stream

type YamlConfig

type YamlConfig struct {
	Pattern Pattern `yaml:"pattern"`
	Env     Env     `yaml:"env"`
	Server  Server  `yaml:"server"`
}

YamlConfig

func NewYamlConfigOrDie

func NewYamlConfigOrDie(defaultConfigYaml string) YamlConfig

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL