import java.awt.Color import java.util.concurrent.Callable import java.util.concurrent.Executors import java.util.concurrent.atomic.AtomicBoolean import static Services.* import static ServiceControl.* import java.awt.AWTException import java.awt.Font import java.awt.Image import java.awt.Menu import java.awt.MenuItem import java.awt.PopupMenu import java.awt.SystemTray import java.awt.TrayIcon import java.awt.event.ActionEvent import java.awt.event.ActionListener import javax.swing.JOptionPane import javax.imageio.ImageIO group 'com.att.ecomp' version '1.01-SNAPSHOT' apply plugin: 'groovy' apply plugin: 'java' apply plugin: "org.hidetake.ssh" apply plugin: 'java-gradle-plugin' apply plugin: 'idea' sourceCompatibility = 1.8 buildscript { repositories { jcenter() mavenCentral() } dependencies { classpath 'org.codehaus.groovy:groovy-all:2.4.12' classpath "org.hidetake:gradle-ssh-plugin:2.9.0" } } enum Services { BACKEND , //be FRONTEND , //fe DB , //cassandra CACHING , //elawsrticsearch SECURITY , //webseal ALL //all services } enum ServiceControl { HEALTH , START , RESTART , STOP , KILL } //env variables //fill YOUR_WINDOWS_USER_HOME project.ext.set("NEW_VAG",Boolean.FALSE) //flags to use new vagrant configuration project.ext.set("IS_HOTSWAP",Boolean.FALSE) //flags to use new vagrant configuration project.ext.set("PROJECT_PATH", System.getenv("SDC")) //ex. 'C:\\GIT_WORK\\asdc\\sdc') project.ext.set("VAGRANT_HOME", NEW_VAG ? System.getenv("NEW_VAG") : System.getenv("VAG")) //ex. 'C:\\GIT_WORK\\vagrant-asdc-all-in-one') project.ext.set("USER_HOME", "${System.getenv("USERPROFILE")}\\.ssh") project.ext.set("BE_REMOTE", NEW_VAG ? '/opt/app/jetty/base/be' : '/home/vagrant/catalog-be' ) project.ext.set("FE_REMOTE", NEW_VAG ? '/opt/app/jetty/base/fe' : '/home/vagrant/catalog-fe' ) project.ext.set("VAGRANT_USER", NEW_VAG ? 'm11981' : 'vagrant' ) project.ext.set("RSA_PRIVATE_KEY_PATH", NEW_VAG ? "$VAGRANT_HOME/id_rsa" : '' ) project.ext.set("VAGRANT_PASSWORD", NEW_VAG ? 'Aa123456' : 'vagrant' ) project.ext.set("X_FOLDER",'/xFolder' ) project.ext.set("BE_DEPENDENCIES", 'common-be,common-app-api,catalog-dao,catalog-model,security-utils' ) project.ext.set("command", [ (ALL) : [ (HEALTH) : { NEW_VAG ? 'sudo curl -i http://localhost:8181/sdc1/rest/healthCheck' : 'curl -i localhost:8080/sdc2/rest/healthCheck' } , (KILL) : { NEW_VAG ? 'sudo pkill java' : 'pkill java'} ] , // TODO: refine kill only for services (BACKEND) : [ (START) : { NEW_VAG ? 'sudo service jettyBE start' : 'service catalog-be start'} , (STOP) : { NEW_VAG ? 'sudo service jettyBE stop' : 'service catalog-be stop'} , (RESTART) : { NEW_VAG ? 'sudo service jettyBE restart' : 'service catalog-be restart'}] , (DB) : [ (START) : { NEW_VAG ? 'sudo service cassandra start' : 'start-asdc-storage.sh' } , (STOP) : { NEW_VAG ? 'sudo service cassandra stop' : 'service cassandra stop'} , (RESTART) : { NEW_VAG ? 'sudo service cassandra restart' : 'service cassandra restart'} ] , (FRONTEND): [ (START) : { NEW_VAG ? 'sudo service jettyFE start' : 'service catalog-fe start' } , (STOP) : { NEW_VAG ? 'sudo service jettyFE stop' : 'service catalog-fe stop'} , (RESTART) : { NEW_VAG ? 'sudo service jettyFE restart' : 'service catalog-fe restart' } ] , (CACHING): [ (START) : { NEW_VAG ? 'sudo service elasticsearch start' : 'echo "starting es is not yet supported"' } ], (SECURITY): [ (START) : { NEW_VAG ? 'sudo docker start sdc-WebSeal-Simulator' : 'service webseal-simulator start' } , (STOP) : { NEW_VAG ? 'sudo docker stop sdc-WebSeal-Simulator' : 'service webseal-simulator stop'} , (RESTART) : { NEW_VAG ? 'sudo docker restart sdc-WebSeal-Simulator' : 'service webseal-simulator restart'}] ] ) //abstraction level to shell scripts , support old and new vagrant bash commands //icons project.ext.set("warnImg",'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAAADvSURBVDhPY2RgYPgPxGQDiAGLXkB4UMD56DuD9YFUhj179oD5Li4uDEcdZjN8l+ME8+EgTgLTAJDm7zWKYPb/enUwzdh4E0xzttxHNQRoABOUCQYYmj+9QrCBACQHUoMM4AYga74ZDiRAmvnEwHwQGywGBOiGgA1A16wmJYjQDAJANkgMmyEosYBVMzIAuuTWs/cM6iuhfCCAGwDWrAHxKyFw68ZNuCE40wGygcga0AEkEEHRiIxxASzqUKKRHIAwAJgo4BgXwKIGxQUgf8MwOsAlh+EFUMDBMAxgE0MGoLwAignSMFQPzmgkDjAwAACSmn13nChk1QAAAABJRU5ErkJggg==') project.ext.set("okImg1",'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAAAD4SURBVDhPY2RgYPgPxGQDiAGLXkB4UMD56DuD9YFUhj179oD5Li4uDEcdZjN8l+ME8+EgTgLTAJDm7zWKYLbSRh8wfc9/C5jmbLmPagjQACYoEwwwNLMxgzHMIJAcSA0ygBuArFm81gyi+ddfCAaywWJAgG4I2AB0zdxWkhCNMABkg8SwGYISC1g1IwOgS74ee87wsvkUVADJAJjpyIDbRAxMfz3zCkwjA5ghONMB2DVIBiDbigwggQiKRmSMC2BRhxKN5ACEAcBEAce4ABY1LFAaDLAFJAwgyyGHB4YXQAEHwzCATQwZgPICKCZIw1A9OKOROMDAAAA4gXvZorg7ZgAAAABJRU5ErkJggg==') project.ext.set("okImg2" , 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAAADjSURBVDhPY2RgYPgPxGQDiAGLXkB4UMD56DuD9YFUhj179oD5Li4uDEcdZjN8l+ME8+EgTgLTAJDm7zWKYPbWZ7Jg2lvqMZjmbLmPagjQACYoEwywaQYBGBskB1KDDOAGIGuetFsUTCMDmBi6IWAD0DUra3OA2cgAJIbNEJRYwKUZGdy9+oMhz/U1lIdkADZnwwwDaUIHMENwpgNk16DbigwggQiKRmSMC2BRhxKN5ACEAcBEAce4ABY1LFAaDLAFJAwgyyGHB4YXQAEHwzCATQwZgPICKCZIw1A9OKOROMDAAAAZD3X55epfOAAAAABJRU5ErkJggg==') project.ext.set("errorImg" , 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAAADlSURBVDhPY2RgYPgPxGQDiAGLXkB4UMD56DuD9YFUhj179oD5Li4uDEcdZjN8l+ME8+EgTgLTAJDm7zWKYPZbGRUwLfzkDpjmbLmPagjQACYoEwywaQYBGBskB1KDDOAGIGtexisCppEBTAzdELAB6Jrd+QXAbGQAEsNmCEos4NKMDHZ+/MAQ9fkNlIdkADZnwwwDaUIHyIaADM
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<parent>
		<groupId>org.onap.so</groupId>
		<artifactId>bpmn</artifactId>
		<version>1.2.0-SNAPSHOT</version>
	</parent>

	<modelVersion>4.0.0</modelVersion>
	<artifactId>MSOCockpit</artifactId>
	<packaging>pom</packaging>
	<name>MSOCockpit</name>
	<description>Builds the Camunda cockpit webapp for MSO</description>

	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-assembly-plugin</artifactId>
				<executions>
					<execution>
						<configuration>
							<descriptors>
								<descriptor>src/main/assembly/cockpit-build.xml</descriptor>
							</descriptors>
							<appendAssemblyId>false</appendAssemblyId>
						</configuration>
						<id>cockpit-build</id>
						<phase>package</phase>
						<goals>
							<goal>single</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
	
	<dependencies>
		
		<dependency>
			<groupId>org.camunda.bpm.webapp</groupId>
			<artifactId>${camunda.bpm.webapp.artifact}</artifactId>
			<version>${camunda.version}</version>
			<type>war</type>
		</dependency>
		
		<dependency>
			<groupId>org.onap.so</groupId>
			<artifactId>common</artifactId>
			<version>${project.version}</version>
		</dependency>
		<!--<dependency>
			<groupId>org.onap.so</groupId>
			<artifactId>cockpit-urnmap-plugin</artifactId>
			<version>${project.version}</version>
		</dependency> -->
		<dependency>
			<groupId>org.onap.so</groupId>
			<artifactId>MSOCoreBPMN</artifactId>
			<version>${project.version}</version>
		</dependency>
	</dependencies>
	
</project>
L ? 'install' : 'compile' exec{ println "--> compiling project at -> ${PROJECT_PATH}\\catalog-be" workingDir "${PROJECT_PATH}" //vagrant path commandLine 'cmd','/c',"mvn -T 1 $cmd war:war -pl catalog-be -Pcatalog -Dmaven.test.skip" //commandLine 'cmd', '/c','mvn -T 1C package -pl catalog-model,catalog-dao,catalog-be -P catalog -Dmaven.test.skip' } } task compileWar(){ doLast{ compileWar() } } //deprecated - use deployBE() task be() { doLast{ def started = System.currentTimeMillis(); exec{ println "[MasterD]--> copying be... [from $VAGRANT_HOME]" workingDir VAGRANT_HOME //vagrant path commandLine 'cmd','/c', 'copy_war_be.bat','localhost' , "$PROJECT_PATH\\catalog-be\\target\\catalog-be*.war" , "$BE_REMOTE/webapps" //args = [ ] } println """ **** copying finished in -> ${System.currentTimeMillis() - started}ms **** """ } } task beConfig( ) { doLast{ exec{ workingDir "${System.env.VAG}" //vagrant path commandLine 'cmd','/c','copy_war_be_with_configuration','localhost' , "$PROJECT_PATH\\catalog-be\\target\\catalog-be*.war" , "$BE_REMOTE/webapps" //args = [ ] } } } task feConfig( ) { doLast{ exec{ workingDir "${System.env.VAG}" //vagrant path commandLine 'cmd','/c','copy_war_fe_with_configuration','localhost' , "$PROJECT_PATH\\catalog-fe\\target\\catalog-fe*.war" , "$FE_REMOTE/webapps" //args = [ ] } } } task fe() { doLast{ exec { workingDir "${System.env.VAG}" //vagrant path commandLine 'cmd','/c', 'copy_war_fe.bat', 'localhost', "$PROJECT_PATH\\catalog-fe\\target\\catalog-fe*.war", "$FE_REMOTE/webapps" //args = [ ] } } } def installAllProject(){ exec{ println "[MasterD]--> Compiling&Installing project at -> ${PROJECT_PATH}" workingDir "${PROJECT_PATH}" //vagrant path commandLine 'cmd','/c','mvn -T 2 clean install -U -Pcatalog -Dmaven.test.skip' } } task installAllProject { doLast { installAllProject() } } task installAll { doLast{ println '[MasterD]--> Finished!!' } } installAll.dependsOn { tasks.findAll { task -> task.name.startsWith('install_') } } def install_BE(){ exec { println '[MasterD][Install]--> Installing BE!!' workingDir "${PROJECT_PATH}" commandLine 'cmd','/c', 'mvn clean install -pl catalog-be -am -Pcatalog -Dmaven.test.skip' //args = [ ] } } task install_BE() { doLast{ install_BE() } } def install_FE() { exec { workingDir "${PROJECT_PATH}" commandLine 'cmd','/c', 'mvn clean install -pl catalog-ui,catalog-fe -am -Pcatalog -Dmaven.test.skip' } } task install_FE() { doLast { install_FE() } } def updaterBERapid(){ /* if ( ticket() > PREVIOUS_BUILD_VAR ){ PREVIOUS_BUILD_VAR = ticket()*/ def started = System.currentTimeMillis(); println "[MasterD][Rapid]--> compiling changes using maven" compileWar() println "[MasterD][Rapid]--> copying war" copyBE() //use this if you want to deploy entire war //hotswap.execute() restartBackend() println msg(" redeploy finished in -> ${System.currentTimeMillis() - started}ms ") } task updaterBERapid(){ doLast { updaterBERapid() } } def updaterBE(){ def started = System.currentTimeMillis(); IS_MVN_INSTALL = pomChanges() ? true : false println "[MasterD]--> compiling changes using maven" compileDependencies() compileWar() println "[MasterD]--> copying war" IS_HOTSWAP ? copyExplodedBE() : copyBE() //execute() //use this if you want to deploy entire war //hotswap.execute() restartBackend() println msg("redeploy finished in -> ${System.currentTimeMillis() - started}ms ") } task updaterBE(){ doLast { updaterBE() } } def copyBEConfiguration(){ /* execSafe { ssh.settings { knownHosts = allowAnyHosts } ssh.run { session(remotes.vagrant) { println msg("Stopping BackEnd Server") execute command[BACKEND][STOP]() } } }*/ } def updaterBEFull(){ def started = System.currentTimeMillis(); compile() println "[MasterD]--> copying war" copyBE() //use this if you want to deploy entire war //hotswap.execute() copyBEConfiguration() println msg("redeploy finished in -> ${System.currentTimeMillis() - started}ms ") } task updaterBEFull(){ doLast { updaterBEFull() } } def copyFEConfiguration(){ //todo- implement } def updaterFE(){ def started = System.currentTimeMillis(); println "[MasterD]--> compiling changes using maven" compileFE() println "[MasterD]--> copying war" copyFE() //.execute() //use this if you want to deploy entire war //hotswap.execute() copyFEConfiguration() println msg("redeploy finished in -> ${System.currentTimeMillis() - started}ms ") } task updaterFE(){ doLast { updaterFE() } } def stopBackend(){ execSafe { ssh.settings { knownHosts = allowAnyHosts } ssh.run { session(remotes.vagrant) { println msg("Stopping BackEnd Server") execute command[BACKEND][STOP]() } } } } task stopBackend(){ doLast { stopBackend() } } def startBackend(){ execSafe { ssh.settings { knownHosts = allowAnyHosts } ssh.run { session(remotes.vagrant) { println msg("[MasterD] starting backend sever") execute command[BACKEND][START]() } } } println """[MasterD]-> finished !! """ } task startBackend(){ doLast{ startBackend() } } def restartBackend(){ execSafe { ssh.settings { knownHosts = allowAnyHosts } ssh.run { session(remotes.vagrant) { println msg("[MasterD] restarting backend sever") execute command[BACKEND][RESTART]() } } } println """[MasterD]-> finished !! """ } //todo- remove this if you want to auto-deploy on every file save /* compileJava.doFirst{ updater?.execute() }*/ enum STATUS { UP, DOWN , UNKNOWN , UNAVAILABLE } task health(){ doLast { prepareTray() } } def execSafe( closure){ if (!lockObj) { [0..4].forEach( {println "Critical ERROR : lock object is not initialized\n\nCritical ERROR : cannot run tasks\n"}() ) return; } synchronized (lockObj){ boolean prev = isHaltHealth.get() try { isHaltHealth.set(true) closure() } catch (Exception e) { println e } finally { isHaltHealth.set(prev) } } } def fetchFiles( remote, local ){ ssh.run { session(remotes.vagrant) { //execute "cd /home/vagrant/catalog-be/tmp ; ls -lt | grep catalog-be" //todo- use my dates to filter def f = get from: remote , into: local println f?.name //return f } //println "fetched files in ${System.currentTimeMillis() - started} ms" } //return null } def killJava(){ execSafe { def res ssh.run { session( remotes.vagrant ) { println """ *-*-****************************-*-* killing all java proccesses *-*-****************************-*-* """ res = execute command[ALL][KILL]() } } println res?.toString() } } def importNormative(){ execSafe { ssh.run { session(remotes.vagrant) { println """ *-*-************************************-*-* importNormative *-*-************************************-*-* """ execute "python -v $BE_REMOTE/scripts/import/tosca/importNormativeAll.py" } } } } def startAll(){ def startCassandra = """ #!/bin/bash cassandra& elasticsearch -d #Wait until ES is up until curl localhost:9200/_cluster/health; do printf "." sleep 3 done # Create Elastic Mapping if not exist in ES createESMapping.sh """ execSafe { ssh.run { session(remotes.vagrant) { println """ *-*-************************************-*-* starting all SDC services(DB,BE,FE,Webseal) *-*-************************************-*-* """ if ( NEW_VAG ){ execute command[DB][START]() Thread.sleep(5000) execute command[CACHING][START]() } else execute startCassandra //[0..4]?.forEach( Thread?.sleep(2000) ) Thread?.sleep(10000) Thread?.sleep(10000) execute command[BACKEND][START]() execute command[FRONTEND][START]() execute command[SECURITY][START]() } } } } /*def clearLog(type: Delete){ delete{ delete 'C:/ProgramData/all.log' followSymlinks = true } }*/ task clearLog(type: Delete){ doLast{ delete 'C:/ProgramData/all.log' followSymlinks = true } } def logBE(){ try{ println "\n*** logging BE all.log ***\n" ssh.run { session( remotes.vagrant ) { //String now = execute 'echo \"\$(date +\'%Y_%m_%d\')\"' //println "\n\n*******************************************************\n\n"+now?.toString() clearLog?.execute() //todo- remove this .execute() fetchFiles( '/home/vagrant/catalog-be/logs/SDC/SDC-BE/all.log' , 'C:/ProgramData') //"%USERPROFILE%\AppData\Local\") //project.ext.set( "logFile" , 'C:/ProgramData/all.log' ) // -f /home/vagrant/catalog-fe/logs/*$now.stderrout.log -f /home/vagrant/catalog-be/logs/*$now.stderrout.log -f /home/vagrant/catalog-be/logs/ASDC/ASDC-BE/debug.log*' } } parallel { exec { //if ( logFile ){ String notepad = 'C:\\Program Files (x86)\\Notepad++\\notepad++.exe' println "logging $logFile to notepad++ [$notepad]" commandLine 'cmd','/c' , notepad ,logFile } } }catch(Exception e){ println "cannot open logs!!!" e.printStackTrace() } } task logBE(){ doLast{ logBE() } } def toggleHealthPolling(){ isHaltHealth.set(!isHaltHealth.get()) } //converts predefined icon to Image def Image convert( imageName ){ String encodedimage = project.ext.get(imageName); byte[] byteImage = encodedimage?.split(',')[1]?.decodeBase64() Image image = ImageIO.read(new ByteArrayInputStream(byteImage)); } def refreshMenu(String imageName){ switch( imageName ) { case 'unavailableImg' : toggleHealthString = "Resume Health"; break; default : toggleHealthString = "Halt Health"; } if (((MenuItem)toggleHealthItemView).getLabel() != toggleHealthString) ((MenuItem)toggleHealthItemView).setLabel(toggleHealthString); } def startDB(){ println "[MasterD] Starting database.." execSafe { ssh.settings { knownHosts = allowAnyHosts } ssh.run { session(remotes.vagrant) { execute command[DB][START]() } } } } task startDB(){ doLast { startDB() } } def stopDB(){ execSafe { ssh.settings { knownHosts = allowAnyHosts } ssh.run { session(remotes.vagrant) { execute command[DB][STOP]() } } } } task stopDB(){ doLast { stopDB() } } def startFE(){ execSafe { ssh.settings { knownHosts = allowAnyHosts } ssh.run { session(remotes.vagrant) { execute command[FRONTEND][START]() } } } } task startFE(){ doLast { startFE() } } def stopFE(){ execSafe { ssh.settings { knownHosts = allowAnyHosts } ssh.run { session(remotes.vagrant) { execute command[FRONTEND][STOP]() } } } } task stopFE(){ doLast { stopFE() } } def ActionListener newListener( closure ){ ActionListener listener = new ActionListener() { public void actionPerformed(ActionEvent e) { try { closure() } catch (AWTException e1) { System.err.println(e1); } } } listener } ext.updateTray = { STATUS status -> lastStatus = status if (SystemTray.isSupported()) { // get the SystemTray instance SystemTray tray = SystemTray.getSystemTray(); // load an image String imageName = status==STATUS.UP ? (Math.random()>0.5 ?'okImg1':'okImg2') : status==STATUS.UNAVAILABLE ? 'unavailableImg' : status==STATUS.DOWN ? 'errorImg' : 'warnImg' Image image = convert imageName if (trayIcon != null) { trayIcon.setImage(image) refreshMenu(imageName); return ; } //region -> Menu UI // create a popup menu PopupMenu popup = new PopupMenu(); // create menu item for the default action MenuItem hotswapItem = new MenuItem("===> WAR <==="); hotswapItem.setFont(new Font("MONOSPACED" , Font.BOLD ,15f )) //region Multilevel Menus Menu deployMasterMenu = new Menu("DeployMaster"); Menu backendMenu = new Menu("Backend"); Menu frontendMenu = new Menu("Frontend"); Menu dbMenu = new Menu("Database"); try{ deployMasterMenu.setFont(new Font("Cooper Black" ,Font.BOLD ,14f )) backendMenu.setFont(new Font("Cooper Black" ,Font.PLAIN ,13f )) frontendMenu.setFont(new Font("Cooper Black" ,Font.PLAIN ,13f )) dbMenu.setFont(new Font("Cooper Black" ,Font.PLAIN ,13f )) }catch(Exception e){ println e } //DeployMaster Menu MenuItem updaterBeWithDependenciesItem = new MenuItem("[BE] Quick Compile -> Deploy"); MenuItem updaterFullBeItem = new MenuItem("[BE] Full Install -> Deploy"); MenuItem updaterFeItem = new MenuItem("[FE] Quick Compile -> Deploy"); MenuItem updaterFullFeItem = new MenuItem("[FE] Full Install -> Deploy"); //Menu UI build deployMasterMenu.add(updaterFullBeItem); deployMasterMenu.add(updaterBeWithDependenciesItem); deployMasterMenu.addSeparator(); deployMasterMenu.add(updaterFullFeItem); deployMasterMenu.add(updaterFeItem); //BE menu MenuItem startItem = new MenuItem("[BE] Start"); MenuItem stopItem = new MenuItem("[BE] Stop BackEnd"); MenuItem copyBeWarItem = new MenuItem("[BE] Copy War"); backendMenu.add(startItem); backendMenu.add(stopItem); backendMenu.add(copyBeWarItem); //FE menu MenuItem startFEItem = new MenuItem("[FE] Start"); MenuItem stopFEItem = new MenuItem("[FE] Stop"); MenuItem copyFeWarItem = new MenuItem("[FE] Copy War"); frontendMenu.add(startFEItem); frontendMenu.add(stopFEItem); frontendMenu.add(copyFeWarItem); //DB menu MenuItem startDBItem = new MenuItem("[DB] Start"); MenuItem stopDBItem = new MenuItem("[DB] Stop"); MenuItem backupDBItem = new MenuItem("[DB] Backup"); MenuItem restoreDBItem = new MenuItem("[DB] Restore"); dbMenu.add(startDBItem); dbMenu.add(stopDBItem); dbMenu.add(backupDBItem); dbMenu.add(restoreDBItem); //endregion MenuItem killItem = new MenuItem("Kill All"); MenuItem startAllItem = new MenuItem("Start All"); MenuItem importItem = new MenuItem("Import Normative"); MenuItem healthInfoItem = new MenuItem("[Info] Health"); MenuItem toggleHealthItem = new MenuItem(toggleHealthString); MenuItem logsItem = new MenuItem("Logs [Beta]"); MenuItem exitItem = new MenuItem("Exit"); toggleHealthItemView = toggleHealthItem; popup.add(hotswapItem); popup?.addSeparator(); popup.add(deployMasterMenu); popup?.addSeparator(); popup.add(backendMenu) popup.add(frontendMenu) popup.add(dbMenu) popup?.addSeparator(); popup.add(startAllItem); popup.add(killItem); popup?.addSeparator(); popup.add(toggleHealthItem); popup.add(healthInfoItem); popup?.addSeparator(); popup.add(importItem); popup.add(logsItem); popup?.addSeparator(); popup.add(exitItem); //endregion UI // construct a TrayIcon trayIcon = new TrayIcon(image, "HealthTray", popup); //region -> Button actions def listenerHotswap = newListener { project.ext.set("IS_HOTSWAP", !IS_HOTSWAP); hotswapItem?.setLabel( IS_HOTSWAP ? "==> HotSwap <==" : "===> WAR <===") } // create a action listener to listen for default action executed on the tray icon def listenerFullBE = newListener { parallel { install_BE(); IS_HOTSWAP ? copyExplodedBE() : copyBE(); restartBackend() } } def listenerFullFE = newListener { parallel { install_FE(); copyFE() } } ActionListener listenerFE = newListener { parallel { updaterFE() } } ActionListener listenerBE = newListener { parallel { updaterBE() } } ActionListener exitListener = newListener { executor?.isShutdown() ?: executor?.shutdown() tray.remove(trayIcon); project.ext.set("isStopHealthCheck", true) println "Shutting down.. bye bye.." } ActionListener stopBackendListener = newListener { stopBackend() } ActionListener startBEListener = newListener { parallel { startBackend() } } ActionListener killJavaListener = newListener { killJava() } ActionListener startAllListener = newListener { parallel { startAll() } } ActionListener listener5 = new ActionListener() { public void actionPerformed(ActionEvent e) { try { parallel { importNormative() } } catch (AWTException e1) { System.err.println(e1); } } }; ActionListener listener6 = new ActionListener() { public void actionPerformed(ActionEvent e) { try { parallel { healthPopup() } } catch (AWTException e1) { System.err.println(e1); } } }; ActionListener listener7 = new ActionListener() { public void actionPerformed(ActionEvent e) { try { logBE()//tasks.logger.execute() } catch (AWTException e1) { System.err.println(e1); } } }; ActionListener listener8 = new ActionListener() { public void actionPerformed(ActionEvent e) { try { toggleHealthPolling()//tasks.logger.execute() } catch (AWTException e1) { System.err.println(e1); } } }; ActionListener copyBeWarListener = new ActionListener() { public void actionPerformed(ActionEvent e) { try { parallel { copyBE() }//.execute()//tasks.logger.execute() } catch (AWTException e1) { System.err.println(e1); } } }; ActionListener startDBListener = new ActionListener() { public void actionPerformed(ActionEvent e) { try { parallel { startDB() }//tasks.logger.execute() } catch (AWTException e1) { System.err.println(e1); } } } ActionListener stopDBListener = new ActionListener() { public void actionPerformed(ActionEvent e) { try { stopDB()//tasks.logger.execute() } catch (AWTException e1) { System.err.println(e1); } } } ActionListener dbBackupListener = new ActionListener() { public void actionPerformed(ActionEvent e) { try { parallel { backupDB()//tasks.logger.execute() } } catch (AWTException e1) { System.err.println(e1); } } } ActionListener feStartListener = new ActionListener() { public void actionPerformed(ActionEvent e) { try { parallel { startFE() }//tasks.logger.execute() } catch (AWTException e1) { System.err.println(e1); } } } ActionListener feStopListener = new ActionListener() { public void actionPerformed(ActionEvent e) { try { stopFE()//tasks.logger.execute() } catch (AWTException e1) { System.err.println(e1); } } } ActionListener feCopyListener = new ActionListener() { public void actionPerformed(ActionEvent e) { try { parallel { copyFE() //.execute()//tasks.logger.execute() } } catch (AWTException e1) { System.err.println(e1); } } } //def listenerFullModules = newListener { parallel { installAllProject() } } //region -> Button<=Listener hotswapItem.addActionListener(listenerHotswap) updaterFeItem.addActionListener(listenerFE) updaterFullBeItem.addActionListener( listenerFullBE ) updaterBeWithDependenciesItem.addActionListener( listenerBE ) updaterFullFeItem.addActionListener( listenerFullFE ) stopItem.addActionListener(stopBackendListener) startItem.addActionListener(startBEListener) copyBeWarItem.addActionListener(copyBeWarListener); killItem.addActionListener(killJavaListener) startAllItem.addActionListener(startAllListener) importItem.addActionListener(listener5) healthInfoItem.addActionListener(listener6) toggleHealthItem.addActionListener(listener8) logsItem.addActionListener(listener7) exitItem.addActionListener(exitListener) startDBItem.addActionListener( startDBListener ) stopDBItem.addActionListener( stopDBListener ) backupDBItem.addActionListener( dbBackupListener ) copyFeWarItem.addActionListener( feCopyListener ) startFEItem.addActionListener( feStartListener ) stopFEItem.addActionListener( feStopListener ) //endregion //endregion // set the TrayIcon properties // ... // add the tray image try { tray.add(trayIcon); } catch (AWTException e) { System.err.println(e); } // ... } else { println "Java TrayIcon Option is not supported in your System, try enabling it. Bye Bye" } } def prepareTray(){ long UPDATE_THRESHOLD = 3500 float SCALAR = 1 ssh.settings { knownHosts = allowAnyHosts } while(!isStopHealthCheck) { if (!isHaltHealth.get()) { //if await or await is more then 60 second return health check ssh.run { session(remotes.vagrant) { try { def healthOutput = execute command[ALL][HEALTH]() if (healthOutput?.contains("Failed command .* with status 7") || healthOutput?.contains("Problem accessing /sdc2/rest/healthCheck")) updateTray(STATUS.DOWN) def statusCollecion = healthOutput?.findAll "\"healthCheckStatus\": \".*\"" def upCount = statusCollecion?.count { it?.contains("UP") } def downCount = statusCollecion?.count { it?.contains("DOWN") } def uknownCount = (statusCollecion?.size() - upCount) - downCount println " UP -> $upCount | downCount=$downCount | uknownCount=$uknownCount " (uknownCount > 0 || (downCount > 0 && upCount > 0)) ? updateTray(STATUS.UNKNOWN) : ((upCount > 0) ? updateTray(STATUS.UP) : updateTray(STATUS.DOWN)) SCALAR = 1 } catch (Exception e) { updateTray(STATUS.DOWN) println e SCALAR = Math.min(SCALAR * 1.1, 5) //slow down on errors } //green color effects if (lastStatus && lastStatus == STATUS.UP) { trayIcon.setImage(convert(Math.random() > 0.5 ? 'okImg1' : 'okImg2')) //randomly green change color } Thread.yield() Thread?.sleep((long) (UPDATE_THRESHOLD * SCALAR)) } } }else{ updateTray(STATUS.UNAVAILABLE) Thread.yield() } } } def healthPopup(){ ssh.run { session(remotes.vagrant) { def healthOutput = execute command[ALL][HEALTH]() JOptionPane.showMessageDialog(null, healthOutput, "HEALTH", JOptionPane.INFORMATION_MESSAGE); } } } project.ext.set("msg", { content -> """ ************************************************************************************************ ************************************************************************************************ ******* ********* ************** **************** $content ************************************************************************************************ ************************************************************************************************ """} )