Documentation
¶
Index ¶
- Constants
- Variables
- func CleanOutput(raw string) string
- func CmdMatcher(cmd string) gomock.Matcher
- func Contains[T ~string](slices []T, find T) bool
- func GetCentOsName() string
- func GetCentOsVersion() string
- func GetConfigFromProperties(key, content string) (string, bool)
- func GetConfigFromYaml[T any](key, content string) (T, bool)
- func GetDefaultMaxHeap(javaCmd string) string
- func GetEnvCmd(pid int) string
- func GetJdkVersionCmd(javaCmd string) string
- func GetLocateJarCmd(pid int, filename string) string
- func GetOsName() string
- func GetOsVersion() string
- func GetPortsCmd(pid int) string
- func GetProcessScanCmd() string
- func GetSha256Cmd(filename string) string
- func GetTotalMemoryCmd() string
- func GreatThan(versionA, versionB string) bool
- func IsConnectionError(err error) bool
- func IsCredentialError(err error) bool
- func IsJoinErrors(err error) bool
- func IsPermissionDenied(err error) bool
- func IsSshError(err error) bool
- func IsValidJdkVersion(version string) bool
- func Join(errs ...error) error
- func LessThan(versionA, versionB string) bool
- func MatchVersion(expected string) types.GomegaMatcher
- func New[T any]() T
- func ParseProperties(content string) map[string]string
- func ParseYaml(content string) (map[string]interface{}, error)
- func SanitizeVersion(version string) string
- func ToSlice[T any](s Stream) ([]T, error)
- type AppType
- type AppTypes
- type Artifact
- type AuthType
- type Combinator
- type Comparator
- type Connect
- type ConnectionError
- type ConnectionTimeoutError
- type ConsoleOutput
- type Credential
- type CredentialError
- type CredentialProvider
- type CustomLogger
- func (c *CustomLogger) Debug(msg string, keysAndValues ...interface{})
- func (c *CustomLogger) Error(err error, msg string, keysAndValues ...interface{})
- func (c *CustomLogger) Info(msg string, keysAndValues ...interface{})
- func (c *CustomLogger) IntoContext(ctx context.Context) context.Context
- func (c *CustomLogger) Warning(err error, msg string, keysAndValues ...interface{})
- type DiscoveryExecutor
- type Env
- type JarFile
- type JarFileWalker
- type JavaProcess
- type JoinErrors
- type Logging
- type Monad
- type MonadConstraints
- type Monadic
- type Pattern
- type PermissionDenied
- type Predicate
- type RetryPolicy
- type Runtime
- type Server
- type ServerConnectionInfo
- type ServerConnector
- type ServerConnectorFactory
- type ServerDiscovery
- type SpringBootApp
- type SshError
- type SshOption
- type Static
- type StepFunc
- type Stream
- type YamlConfig
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 SpringBootAppTypes = AppTypes{ SpringBootFatJar, SpringBootThinJar, SpringBootExploded, }
View Source
var YamlCfg = NewYamlConfigOrDie(defaultConfigYaml)
Functions ¶
func CleanOutput ¶
func CmdMatcher ¶
func GetCentOsName ¶
func GetCentOsName() string
func GetCentOsVersion ¶
func GetCentOsVersion() string
func GetConfigFromProperties ¶
func GetConfigFromYaml ¶
func GetDefaultMaxHeap ¶
func GetJdkVersionCmd ¶
func GetLocateJarCmd ¶
func GetOsVersion ¶
func GetOsVersion() string
func GetPortsCmd ¶
func GetProcessScanCmd ¶
func GetProcessScanCmd() string
func GetSha256Cmd ¶
func GetTotalMemoryCmd ¶
func GetTotalMemoryCmd() string
func IsConnectionError ¶
func IsCredentialError ¶
func IsJoinErrors ¶
func IsPermissionDenied ¶
func IsSshError ¶
func IsValidJdkVersion ¶
func MatchVersion ¶
func MatchVersion(expected string) types.GomegaMatcher
func ParseProperties ¶
func SanitizeVersion ¶
Types ¶
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 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 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 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 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 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]
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 RetryPolicy ¶
type RetryPolicy struct {
// contains filtered or unexported fields
}
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 ServerConnectionInfo ¶
type ServerConnector ¶
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 SshOption ¶
type SshOption func(s *linuxServer)
func WithClient ¶
func WithConnectionTimeout ¶
func WithHostKeyCallback ¶
func WithHostKeyCallback(callback ssh.HostKeyCallback) SshOption
func WithKeyAlgorithms ¶
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
}
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
Click to show internal directories.
Click to hide internal directories.