Package com.simplicite.util.tools
Class SystemTool
- java.lang.Object
-
- com.simplicite.util.tools.SystemTool
-
public class SystemTool extends java.lang.Object
System toolbox
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
SystemTool.ClassCount
static class
SystemTool.ExecResult
System execution resultclass
SystemTool.SystemInfo
Simple structure to store the platform informationsclass
SystemTool.ThreadInfos
class
SystemTool.ThreadTimes
-
Field Summary
Fields Modifier and Type Field Description static SystemTool
INSTANCE
static long
KB
static long
MB
static java.lang.String
PARAM_LOG_MEMORY
static java.lang.String
PARAM_LOG_UI
-
Constructor Summary
Constructors Constructor Description SystemTool()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static java.lang.String
applyPatch(java.lang.String url, java.lang.String login, java.lang.String pwd, java.lang.String patch, boolean log)
Apply a path thru IO servicestatic SystemTool.SystemInfo
cacheInfo()
static SystemTool.SystemInfo
cacheInfo(SystemTool.SystemInfo info)
static void
cleanDeadSessions()
Close dead sessions in m_session (i.e.static java.lang.String
cleanSrcAndBinDirs()
Purge sources and binaries directoriesstatic void
clearCacheToURL(java.lang.String url, java.lang.String user, boolean invalidate, boolean notify, java.lang.String login, java.lang.String pwd)
Clear cache thru IO servicestatic void
clearCacheToURL(java.lang.String url, java.lang.String login, java.lang.String pwd)
Clear cache and invalidate sessions thru IO servicestatic java.lang.String
clearExportDir()
Purge export directorystatic java.lang.String
clearRecycleBin()
Purge all deleted files in DBDocstatic java.lang.String
clearTempDir()
Purge temporary directorystatic void
compileResources()
Rebuild JS+CSS resources (less and minification)static void
compileThemes()
Rebuild themes with less sourcesstatic int
countSessionsToURL(java.lang.String url, java.lang.String user, boolean unique, java.lang.String login, java.lang.String pwd)
Count authenticated users thru IO servicestatic void
cronMonitoring(java.lang.String column, java.lang.String value)
Change cron of monitoringstatic java.lang.String
deleteModuleToURL(java.lang.String url, java.lang.String login, java.lang.String pwd, java.lang.String module)
Delete a module definition thru IO servicestatic SystemTool.SystemInfo
diskInfo()
static SystemTool.SystemInfo
diskInfo(SystemTool.SystemInfo info)
static SystemTool.SystemInfo
docInfo()
static SystemTool.SystemInfo
docInfo(SystemTool.SystemInfo info)
static java.lang.String
dumpHeap()
Dump the Java heapstatic java.lang.String
eraseDeadDoc()
Deprecated.Use synchronizeDocuments insteadstatic SystemTool.ExecResult
exec(java.lang.String cmd, java.util.List<java.lang.String> args, java.lang.String dir)
Exec a system commandstatic SystemTool.ExecResult
execScript(byte[] script, java.lang.String interpreter, java.util.List<java.lang.String> args, boolean keepDir)
Exec a system script using specified script interpreter (e.g.static SystemTool.ExecResult
execScript(java.lang.String script, java.lang.String interpreter, java.util.List<java.lang.String> args, boolean keepDir)
Exec a system script using specified script interpreter (e.g.static void
forceGC()
Full Garbage collection of unused JVM objectsstatic java.lang.Thread[]
getAllThreads()
Get all JVM threadsstatic SystemTool.ClassCount
getClassCount()
Get classes countstatic java.lang.String
getCronExpr(int sec)
Get cron expression with a simple interval (seconds, minutes or hours)static int
getCronInterval(java.lang.String name, int def)
Get a cron simple interval: detects seconds, minutes or hours frequency in the Cron expressionstatic java.lang.String
getDockerOSName()
Get Docker OS name if applicable.static SystemTool.SystemInfo
getInfo()
Dump some system informations: JVM, Cache, DBDoc, Diskstatic SystemTool.SystemInfo
getInfo(boolean jvm, boolean cache, boolean doc, boolean disk)
Dump some system informations: JVM, Cache, DBDoc, Diskstatic byte[]
getModuleFromURL(java.lang.String url, java.lang.String login, java.lang.String pwd, java.lang.String module)
Get a module definition thru IO service or simple HTTP callstatic java.lang.String
getPID()
Get the JVM process idstatic double
getSystemLoadAverage()
CPU usagestatic java.lang.Thread
getThread(long id, java.lang.String name)
Look for a threadstatic SystemTool.ThreadTimes
getThreadTimes()
Get threads CPU timesstatic void
initMavenRepository()
Initialize Maven repositorystatic java.lang.String
installModuleToURL(java.lang.String url, java.lang.String login, java.lang.String pwd, java.lang.String module, java.lang.String xml, boolean log)
Set a module definition thru IO servicestatic boolean
isCronStarted()
Check cron status using admin rightsstatic boolean
isDocker()
Is running inside a Docker image?static boolean
isLinux()
Is the OS Linux?static boolean
isMac()
Is the OS MacOS?static boolean
isUnix()
Is the OS UNIX?static boolean
isWindows()
Is the OS Windows?static SystemTool.SystemInfo
jvmMemory()
static SystemTool.SystemInfo
jvmMemory(SystemTool.SystemInfo info)
static java.util.Map<java.lang.String,java.lang.management.MemoryUsage>
memoryUsage(boolean peak)
Get all memories metrics using MemoryPoolMXBeanstatic java.lang.management.MemoryUsage
memoryUsage(java.lang.String name, boolean peak)
Get memory metrics using MemoryPoolMXBeanstatic java.lang.String
monitoring(boolean start)
Stop/Start monitoringstatic int
objectGC(boolean full)
Internal garbage collection of unused Simplicite objects (Object, Grant and Processes)static java.lang.String
rebuildIndex()
Rebuild document indexesstatic java.lang.String
rebuildObjectIndex()
Rebuild object indexesstatic boolean
resetCache(boolean memory, boolean core, boolean invalidateSessions, boolean notify, int preCompile)
Clears the system cache and update the LAST_CLEAR_CACHE to notify other serversstatic boolean
resetCache(java.lang.String login, boolean invalidateSessions, boolean notify)
Clears the cache for one user and update the usr_logout to notify other serversstatic boolean
resetCache(java.lang.String object, java.lang.String instance)
Deprecated.use resetCacheObjectstatic void
resetCacheAction(Grant g, java.lang.String action)
Clears specified action cachestatic void
resetCacheConstraints(java.lang.String obj)
Clears specified constraints cachestatic boolean
resetCacheDisp(Grant g, java.lang.String disp)
Clears specified disposition cachestatic void
resetCacheDomain(Grant g, java.lang.String domain)
Clears specified domain cachestatic void
resetCacheField(java.lang.String field)
Clears specified field cachestatic void
resetCacheFieldArea(java.lang.String area)
Clears specified field area cachestatic void
resetCacheFieldType(java.lang.String type)
Clears specified field type cachestatic void
resetCacheFunction(java.lang.String obj, java.lang.String action, java.lang.String view, Grant g)
static void
resetCacheGroups(Grant g)
static boolean
resetCacheList(java.lang.String lovName)
Clears specified List of values and all related objectsstatic boolean
resetCacheObject(java.lang.String object, java.lang.String instance)
Clears specified business object from all user's cachestatic void
resetCacheProcess(Grant g, java.lang.String pcs)
Clears specified process cachestatic void
resetCacheResource(Grant g, java.lang.String object, java.lang.String rowId)
Clears specified resource cachestatic void
resetCacheSysParam(java.lang.String code, java.lang.String value, Grant g)
Clears system parameter cachestatic void
resetCacheTemplate(Grant g, java.lang.String name)
static void
resetCacheText()
Clears TEXT List of valuesstatic void
resetCacheTheme(Grant g, java.lang.String theme)
Clears specified themestatic void
resetCacheView(Grant g, java.lang.String view)
Clears specified view cachestatic boolean
restartCron(boolean lock, boolean notify)
Stop and restart the cron manager using admin rights (notify other servers)static void
restartCronToURL(java.lang.String url, boolean notify, java.lang.String login, java.lang.String pwd)
Restart cron thru IO servicestatic boolean
startCron(boolean lock)
Start the cron table using admin rightsstatic boolean
stopCron(boolean unlock)
Stop the cron manager using admin rightsstatic java.lang.String
synchronizeDocs()
Purge all unsynchronized DBDocstatic SystemTool.ThreadInfos
threadDump(long id, int maxDepth)
Get thread dumpstatic java.util.List<SystemTool.ThreadInfos>
threadInfos(int maxDepth, boolean sort, boolean filter)
Get threads infostatic boolean
useClientMonitoring(Grant g)
Use client monitoring ?static boolean
useServerMonitoring()
Use server monitoring ?
-
-
-
Field Detail
-
KB
public static final long KB
- See Also:
- Constant Field Values
-
MB
public static final long MB
- See Also:
- Constant Field Values
-
INSTANCE
public static final SystemTool INSTANCE
-
PARAM_LOG_MEMORY
public static final java.lang.String PARAM_LOG_MEMORY
- See Also:
- Constant Field Values
-
PARAM_LOG_UI
public static final java.lang.String PARAM_LOG_UI
- See Also:
- Constant Field Values
-
-
Method Detail
-
forceGC
public static void forceGC()
Full Garbage collection of unused JVM objects
-
objectGC
public static int objectGC(boolean full)
Internal garbage collection of unused Simplicite objects (Object, Grant and Processes)- Parameters:
full
- true to remove object from cache, false to remove only the dynamic data (keep objects definitions)- Returns:
- Number of cleared objects
-
clearRecycleBin
public static java.lang.String clearRecycleBin()
Purge all deleted files in DBDoc
-
clearExportDir
public static java.lang.String clearExportDir()
Purge export directory
-
clearTempDir
public static java.lang.String clearTempDir()
Purge temporary directory
-
cleanSrcAndBinDirs
public static java.lang.String cleanSrcAndBinDirs()
Purge sources and binaries directories
-
eraseDeadDoc
@Deprecated public static java.lang.String eraseDeadDoc()
Deprecated.Use synchronizeDocuments instead
-
synchronizeDocs
public static java.lang.String synchronizeDocs()
Purge all unsynchronized DBDoc
-
rebuildIndex
public static java.lang.String rebuildIndex()
Rebuild document indexes
-
rebuildObjectIndex
public static java.lang.String rebuildObjectIndex()
Rebuild object indexes
-
resetCache
public static boolean resetCache(boolean memory, boolean core, boolean invalidateSessions, boolean notify, int preCompile)
Clears the system cache and update the LAST_CLEAR_CACHE to notify other servers- Parameters:
memory
- true to clear the cache memorycore
- true clear the core definitionsinvalidateSessions
- true to disconnect everybodynotify
- notify other servers ?preCompile
- pre-compile objects and processes ? (0=no, 1=sync, 2=async)
-
resetCache
public static boolean resetCache(java.lang.String login, boolean invalidateSessions, boolean notify)
Clears the cache for one user and update the usr_logout to notify other servers- Parameters:
login
- user logininvalidateSessions
- true to disconnect user sessionsnotify
- notify other servers ?
-
resetCache
@Deprecated public static boolean resetCache(java.lang.String object, java.lang.String instance)
Deprecated.use resetCacheObject
-
resetCacheObject
public static boolean resetCacheObject(java.lang.String object, java.lang.String instance)
Clears specified business object from all user's cache- Parameters:
object
- Object nameinstance
- Object instance (null means all instances of the object)
-
resetCacheSysParam
public static void resetCacheSysParam(java.lang.String code, java.lang.String value, Grant g)
Clears system parameter cache- Parameters:
code
- Parameter namevalue
- Parameter valueg
- Optional user rights to reload
-
resetCacheList
public static boolean resetCacheList(java.lang.String lovName)
Clears specified List of values and all related objects- Parameters:
lovName
- List name
-
resetCacheText
public static void resetCacheText()
Clears TEXT List of values
-
resetCacheDisp
public static boolean resetCacheDisp(Grant g, java.lang.String disp)
Clears specified disposition cache- Parameters:
g
- User rightsdisp
- Disposition name
-
resetCacheResource
public static void resetCacheResource(Grant g, java.lang.String object, java.lang.String rowId)
Clears specified resource cache- Parameters:
g
- User rightsobject
- Object name or DispositionrowId
- Object row ID
-
resetCacheProcess
public static void resetCacheProcess(Grant g, java.lang.String pcs)
Clears specified process cache- Parameters:
g
- User rightspcs
- Process/Workflow name
-
resetCacheView
public static void resetCacheView(Grant g, java.lang.String view)
Clears specified view cache- Parameters:
g
- User rightsview
- View name
-
resetCacheTheme
public static void resetCacheTheme(Grant g, java.lang.String theme)
Clears specified theme- Parameters:
g
- User rightstheme
- Theme name
-
compileThemes
public static void compileThemes()
Rebuild themes with less sources
-
compileResources
public static void compileResources()
Rebuild JS+CSS resources (less and minification)
-
initMavenRepository
public static void initMavenRepository()
Initialize Maven repository
-
resetCacheAction
public static void resetCacheAction(Grant g, java.lang.String action)
Clears specified action cache- Parameters:
g
- User rightsaction
- Action name
-
resetCacheDomain
public static void resetCacheDomain(Grant g, java.lang.String domain)
Clears specified domain cache- Parameters:
g
- User rightsdomain
- Domain name
-
resetCacheConstraints
public static void resetCacheConstraints(java.lang.String obj)
Clears specified constraints cache- Parameters:
obj
- Object name
-
resetCacheField
public static void resetCacheField(java.lang.String field)
Clears specified field cache- Parameters:
field
- Field name
-
resetCacheFieldType
public static void resetCacheFieldType(java.lang.String type)
Clears specified field type cache- Parameters:
type
- Field type
-
resetCacheFieldArea
public static void resetCacheFieldArea(java.lang.String area)
Clears specified field area cache- Parameters:
area
- Area name
-
resetCacheFunction
public static void resetCacheFunction(java.lang.String obj, java.lang.String action, java.lang.String view, Grant g)
-
resetCacheGroups
public static void resetCacheGroups(Grant g)
-
resetCacheTemplate
public static void resetCacheTemplate(Grant g, java.lang.String name)
-
isCronStarted
public static boolean isCronStarted()
Check cron status using admin rights- Returns:
- true if cron is started with scheduled jobs
-
startCron
public static boolean startCron(boolean lock)
Start the cron table using admin rights- Parameters:
lock
- true to unlock anyway and to lock with this platform- Returns:
- true if cron has been restarted
-
stopCron
public static boolean stopCron(boolean unlock)
Stop the cron manager using admin rights- Parameters:
unlock
- true to unlock if the cron has been launched by this platform- Returns:
- true if cron is stopped
-
restartCron
public static boolean restartCron(boolean lock, boolean notify)
Stop and restart the cron manager using admin rights (notify other servers)- Parameters:
lock
- true to unlock anyway and to lock with this platformnotify
- notify other servers ?- Returns:
- true if cron has been restarted
-
getInfo
public static SystemTool.SystemInfo getInfo(boolean jvm, boolean cache, boolean doc, boolean disk)
Dump some system informations: JVM, Cache, DBDoc, Disk- Parameters:
jvm
- Process JVM info ?cache
- Process cache info ?doc
- Process documents info ?disk
- Process disk info ?- Returns:
- Platform informations
-
getInfo
public static SystemTool.SystemInfo getInfo()
Dump some system informations: JVM, Cache, DBDoc, Disk- Returns:
- Platform informations
-
jvmMemory
public static SystemTool.SystemInfo jvmMemory()
-
jvmMemory
public static SystemTool.SystemInfo jvmMemory(SystemTool.SystemInfo info)
-
docInfo
public static SystemTool.SystemInfo docInfo()
-
docInfo
public static SystemTool.SystemInfo docInfo(SystemTool.SystemInfo info)
-
cacheInfo
public static SystemTool.SystemInfo cacheInfo()
-
cacheInfo
public static SystemTool.SystemInfo cacheInfo(SystemTool.SystemInfo info)
-
diskInfo
public static SystemTool.SystemInfo diskInfo()
-
diskInfo
public static SystemTool.SystemInfo diskInfo(SystemTool.SystemInfo info)
-
useServerMonitoring
public static boolean useServerMonitoring()
Use server monitoring ?
-
monitoring
public static java.lang.String monitoring(boolean start)
Stop/Start monitoring
-
useClientMonitoring
public static boolean useClientMonitoring(Grant g)
Use client monitoring ?- Returns:
- true when LOG_UI=yes and responsibility ADMIN or OPERATOR
-
cronMonitoring
public static void cronMonitoring(java.lang.String column, java.lang.String value)
Change cron of monitoring
-
memoryUsage
public static java.lang.management.MemoryUsage memoryUsage(java.lang.String name, boolean peak)
Get memory metrics using MemoryPoolMXBean- Parameters:
name
- Perm gen, Code Cache, Eden Space, Survivor Space, Old Genpeak
- True to get peak or current usage
-
memoryUsage
public static java.util.Map<java.lang.String,java.lang.management.MemoryUsage> memoryUsage(boolean peak)
Get all memories metrics using MemoryPoolMXBean- Parameters:
peak
- True to get peak or current usage
-
threadInfos
public static java.util.List<SystemTool.ThreadInfos> threadInfos(int maxDepth, boolean sort, boolean filter)
Get threads info- Parameters:
maxDepth
- Stack trace size (0=no stack)sort
- To sort result by times (desc)filter
- Only return thread executing Simplicite- Returns:
- Array if JMX is supported
-
getThreadTimes
public static SystemTool.ThreadTimes getThreadTimes()
Get threads CPU times
-
getAllThreads
public static java.lang.Thread[] getAllThreads()
Get all JVM threads
-
getThread
public static java.lang.Thread getThread(long id, java.lang.String name)
Look for a thread- Parameters:
id
- id in name is unknownname
- name if id is unknown- Returns:
- null if not found
-
threadDump
public static SystemTool.ThreadInfos threadDump(long id, int maxDepth)
Get thread dump- Parameters:
id
- Thread idmaxDepth
- Stack trace size- Returns:
- Thread info with Stack
-
dumpHeap
public static java.lang.String dumpHeap()
Dump the Java heap- Returns:
- path to the bin file
-
getPID
public static java.lang.String getPID()
Get the JVM process id- Returns:
- PID or null
-
getSystemLoadAverage
public static double getSystemLoadAverage()
CPU usage- Returns:
- System load average
-
getClassCount
public static SystemTool.ClassCount getClassCount()
Get classes count- Returns:
- Number of classes
-
getCronInterval
public static int getCronInterval(java.lang.String name, int def)
Get a cron simple interval: detects seconds, minutes or hours frequency in the Cron expression
Example: '0/30 * * * * ?' = 30 seconds
Example: '0 3/20 * * * ?' = 20*60 = 1200 seconds
Example: '0 15 1/2 * * ?' = 2*60*60 = 7200 seconds
- Parameters:
name
- crontab namedef
- default interval- Returns:
- Interval in seconds
-
getCronExpr
public static java.lang.String getCronExpr(int sec)
Get cron expression with a simple interval (seconds, minutes or hours)- Parameters:
sec
- polling interval in seconds
-
getModuleFromURL
public static byte[] getModuleFromURL(java.lang.String url, java.lang.String login, java.lang.String pwd, java.lang.String module) throws PlatformException
Get a module definition thru IO service or simple HTTP call- Parameters:
url
- Platform URLlogin
- Loginpwd
- Passwordmodule
- Module name- Returns:
- XML
- Throws:
PlatformException
-
installModuleToURL
public static java.lang.String installModuleToURL(java.lang.String url, java.lang.String login, java.lang.String pwd, java.lang.String module, java.lang.String xml, boolean log) throws java.lang.Exception
Set a module definition thru IO service- Parameters:
url
- Platform URLlogin
- Loginpwd
- Passwordmodule
- Module namexml
- Module XMLlog
- Full import log- Returns:
- result
- Throws:
java.lang.Exception
-
deleteModuleToURL
public static java.lang.String deleteModuleToURL(java.lang.String url, java.lang.String login, java.lang.String pwd, java.lang.String module) throws java.lang.Exception
Delete a module definition thru IO service- Parameters:
url
- Platform URLlogin
- Loginpwd
- Passwordmodule
- Module name- Returns:
- result
- Throws:
java.lang.Exception
-
applyPatch
public static java.lang.String applyPatch(java.lang.String url, java.lang.String login, java.lang.String pwd, java.lang.String patch, boolean log) throws java.lang.Exception
Apply a path thru IO service- Parameters:
url
- Platform URLlogin
- Loginpwd
- Passwordpatch
- Patch XMLlog
- Full import log- Returns:
- Import result
- Throws:
java.lang.Exception
-
clearCacheToURL
public static void clearCacheToURL(java.lang.String url, java.lang.String login, java.lang.String pwd) throws java.lang.Exception
Clear cache and invalidate sessions thru IO service- Parameters:
url
- Platform URLlogin
- Loginpwd
- Password- Throws:
java.lang.Exception
-
clearCacheToURL
public static void clearCacheToURL(java.lang.String url, java.lang.String user, boolean invalidate, boolean notify, java.lang.String login, java.lang.String pwd) throws HTTPException
Clear cache thru IO service- Parameters:
url
- Platform URLuser
- Optional user to clearinvalidate
- Invalidate sessions ?notify
- notify other servers ?login
- Loginpwd
- Password- Throws:
HTTPException
-
restartCronToURL
public static void restartCronToURL(java.lang.String url, boolean notify, java.lang.String login, java.lang.String pwd) throws HTTPException
Restart cron thru IO service- Parameters:
url
- Platform URLlogin
- Loginpwd
- Password- Throws:
HTTPException
-
countSessionsToURL
public static int countSessionsToURL(java.lang.String url, java.lang.String user, boolean unique, java.lang.String login, java.lang.String pwd) throws HTTPException
Count authenticated users thru IO service- Parameters:
url
- Platform URLuser
- specific login or all if nullunique
- distinct users or all authenticated sessionslogin
- Loginpwd
- Password- Returns:
- sessions count
- Throws:
HTTPException
-
isWindows
public static boolean isWindows()
Is the OS Windows?- Returns:
- True if OS is Windows
-
isLinux
public static boolean isLinux()
Is the OS Linux?- Returns:
- True if OS is Linux
-
isUnix
public static boolean isUnix()
Is the OS UNIX?- Returns:
- True if OS is UNIX
-
isMac
public static boolean isMac()
Is the OS MacOS?- Returns:
- True if OS is MacOS
-
isDocker
public static boolean isDocker()
Is running inside a Docker image?- Returns:
- True if running inside a Docker image (checked using the
DOCKER
environment variable)
-
getDockerOSName
public static java.lang.String getDockerOSName()
Get Docker OS name if applicable.- Returns:
- The value of the
DOCKER
environment variable if present
-
exec
public static SystemTool.ExecResult exec(java.lang.String cmd, java.util.List<java.lang.String> args, java.lang.String dir) throws java.lang.InterruptedException
Exec a system command- Parameters:
cmd
- Commandargs
- Arguments listdir
- Execution directory- Returns:
- System command output and error
- Throws:
java.lang.InterruptedException
-
execScript
public static SystemTool.ExecResult execScript(byte[] script, java.lang.String interpreter, java.util.List<java.lang.String> args, boolean keepDir) throws java.lang.InterruptedException
Exec a system script using specified script interpreter (e.g. bash, node, python, ...)- Parameters:
script
- Script as byte array (string e.g. read from a resource document, ...)interpreter
- Intepreter path (e.g. /bin/bash or /usr/local/bin/node, /usr/bin/python, ...), can be left empty for directly executable scriptsargs
- Arguments listkeepDir
- Keep execution dir after execution?- Returns:
- System script execution output and error
- Throws:
java.lang.InterruptedException
-
execScript
public static SystemTool.ExecResult execScript(java.lang.String script, java.lang.String interpreter, java.util.List<java.lang.String> args, boolean keepDir) throws java.lang.InterruptedException
Exec a system script using specified script interpreter (e.g. bash, node, python, ...)- Parameters:
script
- Script as string (string e.g. read from a field value ...)interpreter
- Intepreter path (e.g. /bin/bash or /usr/local/bin/node, /usr/bin/python, ...), can be left empty for directly executable scriptsargs
- Arguments listkeepDir
- Keep execution dir after execution?- Returns:
- System script execution output and error
- Throws:
java.lang.InterruptedException
-
cleanDeadSessions
public static void cleanDeadSessions()
Close dead sessions in m_session (i.e. after a server crash)
-
-