blob: b80295eff8f8722c4507c7f477daaf2ae2f57f1b [file] [log] [blame]
Michael Landoa5445102018-03-04 14:53:33 +02001import java.awt.Color
2import java.util.concurrent.Callable
3import java.util.concurrent.Executors
4import java.util.concurrent.atomic.AtomicBoolean
5
6import static Services.*
7import static ServiceControl.*
8import java.awt.AWTException
9import java.awt.Font
10import java.awt.Image
11import java.awt.Menu
12import java.awt.MenuItem
13import java.awt.PopupMenu
14import java.awt.SystemTray
15import java.awt.TrayIcon
16import java.awt.event.ActionEvent
17import java.awt.event.ActionListener
18import javax.swing.JOptionPane
19import javax.imageio.ImageIO
20
21
22group 'com.att.ecomp'
23version '1.01-SNAPSHOT'
24
25apply plugin: 'groovy'
26apply plugin: 'java'
27apply plugin: "org.hidetake.ssh"
28apply plugin: 'java-gradle-plugin'
29apply plugin: 'idea'
30
31sourceCompatibility = 1.8
32
33buildscript {
34 repositories {
35 jcenter()
36 mavenCentral()
37 }
38 dependencies {
39 classpath 'org.codehaus.groovy:groovy-all:2.4.12'
40 classpath "org.hidetake:gradle-ssh-plugin:2.9.0"
41 }
42}
43
44enum Services {
45 BACKEND , //be
46 FRONTEND , //fe
47 DB , //cassandra
48 CACHING , //elawsrticsearch
49 SECURITY , //webseal
50 ALL //all services
51}
52enum ServiceControl {
53 HEALTH ,
54 START ,
55 RESTART ,
56 STOP ,
57 KILL
58}
59//env variables
60//fill YOUR_WINDOWS_USER_HOME
61project.ext.set("NEW_VAG",Boolean.FALSE) //flags to use new vagrant configuration
62project.ext.set("IS_HOTSWAP",Boolean.FALSE) //flags to use new vagrant configuration
63project.ext.set("PROJECT_PATH", System.getenv("SDC")) //ex. 'C:\\GIT_WORK\\asdc\\sdc')
64project.ext.set("VAGRANT_HOME", NEW_VAG ? System.getenv("NEW_VAG") : System.getenv("VAG")) //ex. 'C:\\GIT_WORK\\vagrant-asdc-all-in-one')
65project.ext.set("USER_HOME", "${System.getenv("USERPROFILE")}\\.ssh")
66project.ext.set("BE_REMOTE", NEW_VAG ? '/opt/app/jetty/base/be' : '/home/vagrant/catalog-be' )
67project.ext.set("FE_REMOTE", NEW_VAG ? '/opt/app/jetty/base/fe' : '/home/vagrant/catalog-fe' )
68project.ext.set("VAGRANT_USER", NEW_VAG ? 'm11981' : 'vagrant' )
69project.ext.set("RSA_PRIVATE_KEY_PATH", NEW_VAG ? "$VAGRANT_HOME/id_rsa" : '' )
70project.ext.set("VAGRANT_PASSWORD", NEW_VAG ? 'Aa123456' : 'vagrant' )
71project.ext.set("X_FOLDER",'/xFolder' )
72project.ext.set("BE_DEPENDENCIES", 'common-be,common-app-api,catalog-dao,catalog-model,security-utils' )
73project.ext.set("command", [ (ALL) : [ (HEALTH) : { NEW_VAG ? 'sudo curl -i http://localhost:8181/sdc1/rest/healthCheck' : 'curl -i localhost:8080/sdc2/rest/healthCheck' } ,
74 (KILL) : { NEW_VAG ? 'sudo pkill java' : 'pkill java'} ] , // TODO: refine kill only for services
75 (BACKEND) : [ (START) : { NEW_VAG ? 'sudo service jettyBE start' : 'service catalog-be start'} ,
76 (STOP) : { NEW_VAG ? 'sudo service jettyBE stop' : 'service catalog-be stop'} ,
77 (RESTART) : { NEW_VAG ? 'sudo service jettyBE restart' : 'service catalog-be restart'}] ,
78 (DB) : [ (START) : { NEW_VAG ? 'sudo service cassandra start' : 'start-asdc-storage.sh' } ,
79 (STOP) : { NEW_VAG ? 'sudo service cassandra stop' : 'service cassandra stop'} ,
80 (RESTART) : { NEW_VAG ? 'sudo service cassandra restart' : 'service cassandra restart'} ] ,
81 (FRONTEND): [ (START) : { NEW_VAG ? 'sudo service jettyFE start' : 'service catalog-fe start' } ,
82 (STOP) : { NEW_VAG ? 'sudo service jettyFE stop' : 'service catalog-fe stop'} ,
83 (RESTART) : { NEW_VAG ? 'sudo service jettyFE restart' : 'service catalog-fe restart' } ] ,
84 (CACHING): [ (START) : { NEW_VAG ? 'sudo service elasticsearch start' : 'echo "starting es is not yet supported"' } ],
85 (SECURITY): [ (START) : { NEW_VAG ? 'sudo docker start sdc-WebSeal-Simulator' : 'service webseal-simulator start' } ,
86 (STOP) : { NEW_VAG ? 'sudo docker stop sdc-WebSeal-Simulator' : 'service webseal-simulator stop'} ,
87 (RESTART) : { NEW_VAG ? 'sudo docker restart sdc-WebSeal-Simulator' : 'service webseal-simulator restart'}]
88 ] ) //abstraction level to shell scripts , support old and new vagrant bash commands
89
90//icons
91project.ext.set("warnImg",'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAAADvSURBVDhPY2RgYPgPxGQDiAGLXkB4UMD56DuD9YFUhj179oD5Li4uDEcdZjN8l+ME8+EgTgLTAJDm7zWKYPb/enUwzdh4E0xzttxHNQRoABOUCQYYmj+9QrCBACQHUoMM4AYga74ZDiRAmvnEwHwQGywGBOiGgA1A16wmJYjQDAJANkgMmyEosYBVMzIAuuTWs/cM6iuhfCCAGwDWrAHxKyFw68ZNuCE40wGygcga0AEkEEHRiIxxASzqUKKRHIAwAJgo4BgXwKIGxQUgf8MwOsAlh+EFUMDBMAxgE0MGoLwAignSMFQPzmgkDjAwAACSmn13nChk1QAAAABJRU5ErkJggg==')
92project.ext.set("okImg1",'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAAAD4SURBVDhPY2RgYPgPxGQDiAGLXkB4UMD56DuD9YFUhj179oD5Li4uDEcdZjN8l+ME8+EgTgLTAJDm7zWKYLbSRh8wfc9/C5jmbLmPagjQACYoEwwwNLMxgzHMIJAcSA0ygBuArFm81gyi+ddfCAaywWJAgG4I2AB0zdxWkhCNMABkg8SwGYISC1g1IwOgS74ee87wsvkUVADJAJjpyIDbRAxMfz3zCkwjA5ghONMB2DVIBiDbigwggQiKRmSMC2BRhxKN5ACEAcBEAce4ABY1LFAaDLAFJAwgyyGHB4YXQAEHwzCATQwZgPICKCZIw1A9OKOROMDAAAA4gXvZorg7ZgAAAABJRU5ErkJggg==')
93project.ext.set("okImg2" , 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAAADjSURBVDhPY2RgYPgPxGQDiAGLXkB4UMD56DuD9YFUhj179oD5Li4uDEcdZjN8l+ME8+EgTgLTAJDm7zWKYPbWZ7Jg2lvqMZjmbLmPagjQACYoEwywaQYBGBskB1KDDOAGIGuetFsUTCMDmBi6IWAD0DUra3OA2cgAJIbNEJRYwKUZGdy9+oMhz/U1lIdkADZnwwwDaUIHMENwpgNk16DbigwggQiKRmSMC2BRhxKN5ACEAcBEAce4ABY1LFAaDLAFJAwgyyGHB4YXQAEHwzCATQwZgPICKCZIw1A9OKOROMDAAAAZD3X55epfOAAAAABJRU5ErkJggg==')
94project.ext.set("errorImg" , 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAAADlSURBVDhPY2RgYPgPxGQDiAGLXkB4UMD56DuD9YFUhj179oD5Li4uDEcdZjN8l+ME8+EgTgLTAJDm7zWKYPZbGRUwLfzkDpjmbLmPagjQACYoEwywaQYBGBskB1KDDOAGIGtexisCppEBTAzdELAB6Jrd+QXAbGQAEsNmCEos4NKMDHZ+/MAQ9fkNlIdkADZnwwwDaUIHyIaADMDAQAP/AwMPjEFsbGpAGGs6AEUPsnfgzsaiDiUayQUgF2A4jaAXoHpQXAByNgyjA1xyGF4A+RuGYQCbGDLA6gWCGKoHJSGRDhgYAL/hkunRq+joAAAAAElFTkSuQmCC')
95project.ext.set("unavailableImg" , 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAABJ0AAASdAHeZh94AAAAB3RJTUUH4QwNDgEDrNoaqgAAAOhJREFUOMulkz8OgjAUhz8MQ7mBkwnnkBAH4mbCCdxcXLwAoxdwYXHjBCRupoMheg4TJ29QNhwshMofSfpLOry2v6/vta8OUGEhF4DsbUx6L8XytkNKCUAURTxWZ9TCM93buQb8mFXiI4E43gCQ5xeQPt7x2YG4fWa0OQwDhBANRCVdyGyKOQyDJhuV+HgvZQLGzABCiEGI036FPnNbZVlSFPfvnWg1gJpea72OjPh6lUZcQ5yhPkjTkxHv94fpfcB23t81PftmWMr9e+pQZjobd6zuobX2fViXAFCRvSv9GtOH9ji23/kDswRrCVqtQOAAAAAASUVORK5CYII=')
96
97
98//health params
99project.ext.set("trayIcon", null)
100project.ext.set("lastStatus", null)
101project.ext.set("isStopHealthCheck", false)
102project.ext.set("isHaltHealth", new AtomicBoolean(false) )
103project.ext.set("startedAwait", Long.MAX_VALUE)
104project.ext.set("logFile", 'C:/ProgramData/all.log')
105project.ext.set("pomList" , ["${System?.getenv('SDC')}/catalog-fe/pom.xml" ,"${System?.getenv('SDC')}/catalog-be/pom.xml" ] ) //empty list will scan all openecomp poms
106project.ext.set("pomChangesMap" , [:] )
107project.ext.set("beConfigFilesToCopyMapping" , [ 'src/main/resources/config/*.yaml' : 'config/catalog-be/' ,
108 'src/main/resources/config/*.properties' : 'config/catalog-be/'] )
109
110//menu item strings
111project.ext.set("toggleHealthString" , "Halt Health" )
112//menu item
113project.ext.set("toggleHealthItemView" , null )
114
115//other
116project.ext.set("IS_MVN_INSTALL",false)
117project.ext.set("executor" , null )
118project.ext.set("lockObj" , new Object() )
119/*compile?.doLast {
120 println "2. hello compile2"
121}*/
122
123/*def post(String host , String serviceName,String msg){
124 // POST
125 def post = new URL("$host/$serviceName").openConnection();
126 def message = '{"message":"this is a message"}'
127 post.setRequestMethod("POST")
128 post.setDoOutput(true)
129 post.setRequestProperty("Content-Type", "application/json")
130 post.getOutputStream().write(message.getBytes("UTF-8"));
131 def postRC = post.getResponseCode();
132 println(postRC);
133 if( postRC.equals(200)) {
134 println(post.getInputStream().getText());
135 }
136}
137
138def postStat( long operationTime, String user , String meta ){
139 def host = 'http://135.76.123.70:8888'
140 def params = "user=$user&meta=$meta"
141 post host , "UserStats" , params
142}*/
143
144
145def hash( List list ){
146 def map = list?.collectEntries { File file -> [(file?.absolutePath) : file?.text?.hashCode() ]}
147
148 map
149}
150
151def pomChanges(){
152 long started = System.currentTimeMillis()
153 if ( !pomList )
154 listPom()
155 //find hash changes
156 def changes = pomList?.findAll {
157 def File file = new File(it);
158 pomChangesMap[it] != file?.text?.hashCode()
159 }
160 println "\n\n[MasterD][POM]--> detected changes for -> $changes"
161 //update changes in map
162 changes?.each { pomChangesMap[it] = new File(it)?.text?.hashCode() }
163 println "\n\n[MasterD][POM]--> pom map -> $pomChangesMap"
164
165 println """
166 ****** POM changes detection finished after -> ${System.currentTimeMillis()- started}ms ******
167 """
168
169 changes
170}
171//list pom with updated file hashes
172def listPom(){
173 long started = System.currentTimeMillis()
174 if (!pomList) {
175 def tree = fileTree( PROJECT_PATH ).include '**/pom.xml'//.filter { it.isFile() && it?.toString()?.toLowerCase()?.endsWith('pom.xml') }
176 //println "$PROJECT_PATH list is ->${ list?.collect { it?.absolutePath } }"
177 //flatten and filter openecomp poms
178 pomList = tree?.flatten()?.findAll { File file -> file?.text?.contains('org.openecomp.sdc') }?.collect {File file -> file?.absolutePath }
179 }
180 pomChangesMap = pomList.collectEntries { absolutePath ->[ ( absolutePath ) : new File(absolutePath)?.text?.hashCode() ] }
181
182 println """ [MasterD][Init] intializing POM detector
183
184 ********* POM listing finished after -> ${System.currentTimeMillis()- started}ms *********
185 """
186 return pomList
187}
188
189
190task initialization(){
191 listPom()
192 executor = Executors.newCachedThreadPool();
193}
194
195def parallel( closure ){
196 executor?.submit(new Callable<Object>(){
197 @Override
198 public Object call() {
199 closure();
200 return null;
201 }
202 })
203}
204/*class Preferences {
205 def String Username
206 def String IsNewVagrant
207 def String IsRapidMode
208}
209
210def initXFolder(){
211 def folder = new File(X_FOLDER);
212 folder?.exists() ?: folder?.mkdirs()
213
214 new File("${folder?.absolutePath}/$PREFERENCES_FILENAME")
215}*/
216
217task tester{
218 /*doLast{
219 //postStat(10000, "shay" , "report/index")
220 listPom()
221 new File('catalog-be\\pom.xml') << "#hello"
222 pomChanges()
223 }*/
224}
225
226
227def fetchFilesByExtention(remote, local , ext ){
228 ssh.run {
229 def started = System.currentTimeMillis()
230 println "folder diff"
231 session(remotes.vagrant) {
232 //execute "cd /home/vagrant/catalog-be/tmp ; ls -lt | grep catalog-be" //todo- use my dates to filter
233 get from: remote , into: local , filter: { it?.absolutePath =~ /jetty.*catalog-be.*\.dir.*\.$ext/ } // { it?.absolutePath =~ /.*catalog-be.*dir.*classes.*/ }
234 }
235 println "fetched files in ${System.currentTimeMillis() - started} ms"
236 }
237}
238
239def updateRemoteFile(String remote , String local){
240 ssh.run {
241 def to = "$BE_REMOTE${remote[remote?.indexOf("tmp\\")..remote.size()-1].replaceAll("\\\\","/")}"
242 println "copying $local \nto\n $to"
243 session(remotes.vagrant) {
244 put from: local , into: to }
245 }
246}
247
248def compareAndSwap(){
249 def final LIMIT = 10
250 def newClasses = new File("$PROJECT_PATH\\catalog-be\\target\\classes")
251 def File jettyClasses ;
252 //locate classes
253 println "traversing.."
254 new File("build/hotswap").traverse { if (it?.directory && it?.name?.equals("classes")){
255 jettyClasses = it
256 return;
257 } }
258 def jettyClassesList = []
259 jettyClasses?.traverse { jettyClassesList << it }
260
261 println "$jettyClasses"
262 //Sort compiled classes
263 def files = []
264 newClasses?.traverse { files << it }
265 def result = files.sort{ a,b -> b.lastModified() <=> a.lastModified() }
266 println "show only last $LIMIT changes"
267 result[0..LIMIT]?.each{ println it?.lastModified() +" | "+ it?.name + (it?.directory ? "[Directory]" : "") } //show only last 10 changes
268
269 //update
270 def changesMap = [ : ] //<old,new>
271 println "updating changes"
272 result[0..LIMIT]?.each { File f -> def File other = jettyClassesList.find{ File other-> other?.absolutePath?.endsWith(f?.name) };
273 if ( !(f.directory) && f?.text?.hashCode() != other?.text?.hashCode() )
274 updateRemoteFile( other?.getAbsolutePath() , f?.getAbsolutePath() )
275 } //use hashing
276}
277
278task hotswap(){
279 doLast {
280 new File("build/hotswap")?.deleteDir()
281 new File("build/hotswap")?.mkdirs()
282 ssh.settings {
283 knownHosts = allowAnyHosts
284 }
285 fetchFilesByExtention( "$BE_REMOTE/tmp/" , 'build/hotswap' , "class")
286 compareAndSwap()
287 }
288}
289
290remotes {
291 vagrant {
292 host = '127.0.0.1'
293 port = 2222
294 user = VAGRANT_USER
295 password = VAGRANT_PASSWORD
296 identity = NEW_VAG ? new File(RSA_PRIVATE_KEY_PATH) : null
297 }
298
299}
300
301def gitLatest(){
302
303}
304
305def newEcoSystem(){
306 //cleanTitan()
307 backupDB() //and clean all
308 //restoreDB() //restore latest
309 createSchema()
310 fillSchema()
311 postCreate()
312 startAll()
313 //todo- conside updating from git
314 updaterBEFull()
315 updaterFE()
316}
317def importHeatTypes(){
318 //todo- impl
319}
320def postCreate(){
321 importNormative()
322 importHeatTypes()
323}
324def fillSchema(){
325 // add conformence level
326}
327def createSchemaPreStep(){
328 //todo- DB up
329}
330def createSchemaPostStep(){
331 ////todo- impl create amdocs dox
332}
333def createSchema(){
334 createSchemaPreStep()
335 //todo- create schema
336 //todo- create titan
337 createSchemaPostStep()
338}
339
340def cleanTitan(){
341 execSafe{
342 ssh.settings {
343 knownHosts = allowAnyHosts
344 }
345 ssh.run {
346 session(remotes.vagrant) {
347 execute "cqlsh -e 'DROP KEYSPACE titan;'"
348 println "[MasterD][DB_DROP]-> Dropped 'titan' KEYSPACE."
349 }
350 }
351 }
352}
353task cleanTitan {
354 doLast{
355 cleanTitan()
356 }
357}
358
359task fetchE2EDB(){
360 doLast{
361 fetchE2EDB()
362 }
363}
364def fetchE2EDB(){
365 execSafe{
366 ssh.settings {
367 knownHosts = allowAnyHosts
368 }
369 ssh.run {
370 session(remotes.vagrant) {
371 def tmp = '$CASSANDRA_HOME/backup/e2e'
372 //execute 'mkdir $CASSANDRA_HOME/backup/e2e/'
373 //execute 'wget http://135.76.210.202:8080/ETE_backup_files/latest_ETE_backup_file.zip -P /vagrant/db'
374 println "[MasterD] download finished, unzipping.."
375 execute "unzip -u $tmp/latest_ETE_backup_file.zip" //execute 'unzip -u /vagrant/db/latest_ETE_backup_file.zip'//'
376 def folder = execute "cd $tmp; ls -d -- */"
377 println "[MasterD] unzipping finished into -> $folder , untaring.."
378 execute "tar zxf $tmp/$folder/* --strip 3 -C" +'$CASSANDRA_HOME/data | pv -l >/dev/null'
379 println "[MasterD][E2E_DB]-> Downloaded & unzipped e2e data successfully."
380 }
381 }
382 }
383}
384def copyExplodedBE() {
385 execSafe{
386 println "[MasterD][BackEnd] copying exploded war."
387 ssh.settings {
388 knownHosts = allowAnyHosts
389 }
390 long started = System.currentTimeMillis()
391 def dirPath = "${PROJECT_PATH}/catalog-be/target/catalog-be-1.1.0-SNAPSHOT"
392 def dir = new File(dirPath);
393 println "[MasterD][BackEnd] copying ${dir?.directorySize()/(1024*1024)} MB, from ${dir?.name} to $BE_REMOTE/webapps"
394 ssh.run {
395 session(remotes.vagrant) {
396 execute "rm -R $BE_REMOTE/webapps/catalog-be-1.1.0-SNAPSHOT"
397 put from: dir?.absolutePath , into: "$BE_REMOTE/webapps"
398 }
399 }
400 println "[MasterD][BackEnd] Successfully copied exploded war in ${System.currentTimeMillis()-started}ms."
401 }
402}
403task copyExplodedBE(){
404 doLast{
405 copyExplodedBE()
406 }
407}
408def backupDB() {
409 execSafe{
410 ssh.settings {
411 knownHosts = allowAnyHosts
412 }
413 ssh.run {
414 session(remotes.vagrant) {
415 execute 'mkdir -p $CASSANDRA_HOME/backup'
416 def res = execute 'mv $CASSANDRA_HOME/data $CASSANDRA_HOME/backup/data_$(date +\'%Y_%m_%d__%H:%M:%S\')'
417 println "[MasterD][DB_BACKUP]-> snapshot DB finished. $res"
418 }
419 }
420 }
421}
422task backupDB{
423 doLast{
424 backupDB()
425 }
426}
427
428def restoreDB(){
429 execSafe{
430 ssh.settings {
431 knownHosts = allowAnyHosts
432 }
433 ssh.run {
434 session(remotes.vagrant) {
435 println "[MasterD]-> restoring DB"
436 execute 'mkdir -p $CASSANDRA_HOME/data'
437 def res = execute 'mv $CASSANDRA_HOME/backup/data_*/* $CASSANDRA_HOME/data'
438 println "[MasterD]-> DB restore FINISHED!! $res"
439 }
440 }
441 }
442}
443task restoreDB() {
444 doLast {
445 restoreDB()
446 }
447}
448
449def vm( ){
450 exec{
451 if (VAGRANT_HOME){
452 workingDir VAGRANT_HOME //vagrant path
453 println "*****************\nworking dir -> $VAGRANT_HOME"
454 commandLine "cmd","/c", "vagrant up"
455 //args = [ ]
456 } else {
457 println "[MasterD]--> please define windows enviroment variable VAG pointing to vagrant project"
458 }
459 }
460}
461
462task vm{
463 doLast{
464 vm()
465 }
466}
467
468def copyFE() {
469 println "[MasterD][FrontEnd] starting war copy."
470 ssh.settings {
471 knownHosts = allowAnyHosts
472 }
473 long started = System.currentTimeMillis()
474 def target = "${PROJECT_PATH}/catalog-fe/target/"
475 def files = GFileUtils.listFiles( new File(target) , ["war"] as String[] , false);
476 files?.each{ File file ->
477 if (!file?.name?.contains('classes')){
478 println "[MasterD][FrontEnd] copying ${file.length()/(1024*1024)} MB, from ${file?.name} to $FE_REMOTE/webapps"
479 ssh.run {
480 session(remotes.vagrant) {
481 put from: file?.absolutePath , into: "$FE_REMOTE/webapps"
482 }
483 }
484 }
485
486 }
487 println "[MasterD][FrontEnd] Successfully copied war in ${System.currentTimeMillis()-started}ms."
488}
489
490task deployFE{
491 doLast {
492 copyFE()
493 }
494}
495
496
497def copyBE(){
498 println "[MasterD][BackEnd] starting war copy."
499 ssh.settings {
500 knownHosts = allowAnyHosts
501 }
502 def target = "${PROJECT_PATH}/catalog-be/target/"
503 def files = GFileUtils.listFiles( new File(target) , ["war"] as String[] , false);
504 long started = System.currentTimeMillis()
505 files?.each{ File file ->
506 if (!file?.name?.contains('classes')){
507 println "[MasterD][BackEnd] copying ${file.length()/(1024*1024)} MB, from ${file?.name} to $BE_REMOTE/webapps"
508 ssh.run {
509 session(remotes.vagrant) {
510 put from: file?.absolutePath , into: "$BE_REMOTE/webapps"
511 }
512 }
513 }
514 }
515 println "[MasterD][BackEnd] SUCCESSFULY copied be war in ${System.currentTimeMillis()-started}ms."
516}
517
518task deployBE {
519 doLast {
520 copyBE()
521 }
522}
523def compileFE(){
524 exec{
525 println "[MasterD][FE]--> compiling project at -> ${PROJECT_PATH}\\catalog-fe"
526 workingDir "${PROJECT_PATH}" //vagrant path
527 commandLine 'cmd','/c','mvn -T 2 compile -pl catalog-fe,catalog-ui -am -Pcatalog -Dmaven.test.skip'
528 }
529}
530task compileFE(){
531 doLast{
532 compileFE()
533 }
534}
535def compileBE(){
536 exec{
537 println "[MasterD][BE]--> compiling project at -> ${PROJECT_PATH}\\catalog-be"
538 workingDir "${PROJECT_PATH}" //vagrant path
539 commandLine 'cmd','/c','mvn -T 2 compile -pl catalog-be -Pcatalog -Dmaven.test.skip'
540 }
541}
542task compileBE{
543 doLast{
544 compileBE()
545 }
546}
547
548def compile(){
549 exec{
550 println "[MasterD]--> compiling project at -> ${PROJECT_PATH}"
551 workingDir "${PROJECT_PATH}" //vagrant path
552 commandLine 'cmd','/c','mvn -T 2 compile -am -Pcatalog -Dmaven.test.skip'
553 }
554}
555
556task compile{
557 doLast{
558 compile()
559 }
560}
561def compileDependencies(){
562 def cmd = IS_MVN_INSTALL ? 'install' : 'compile'
563 exec{
564 println "[MasterD]--> compiling BE dependencies -> $BE_DEPENDENCIES [ SKIPPING TESTS!! ]"
565 workingDir "${PROJECT_PATH}" //vagrant path
566 commandLine 'cmd','/c',"mvn $cmd -pl $BE_DEPENDENCIES -Pcatalog -Dmaven.test.skip" //commandLine 'cmd', '/c','mvn -T 1C package -pl catalog-model,catalog-dao,catalog-be -P catalog -Dmaven.test.skip'
567 }
568}
569task compileDependencies {
570 doLast{
571 compileDependencies()
572 }
573}
574def compileWar(){
575 def cmd = IS_MVN_INSTALL ? 'install' : 'compile'
576 exec{
577 println "--> compiling project at -> ${PROJECT_PATH}\\catalog-be"
578 workingDir "${PROJECT_PATH}" //vagrant path
579 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'
580 }
581}
582task compileWar(){
583 doLast{
584 compileWar()
585 }
586}
587
588//deprecated - use deployBE()
589task be() {
590 doLast{
591 def started = System.currentTimeMillis();
592 exec{
593 println "[MasterD]--> copying be... [from $VAGRANT_HOME]"
594 workingDir VAGRANT_HOME //vagrant path
595 commandLine 'cmd','/c', 'copy_war_be.bat','localhost' , "$PROJECT_PATH\\catalog-be\\target\\catalog-be*.war" , "$BE_REMOTE/webapps"
596 //args = [ ]
597 }
598 println """
599 **** copying finished in -> ${System.currentTimeMillis() - started}ms ****
600 """
601 }
602}
603
604task beConfig( ) {
605 doLast{
606 exec{
607 workingDir "${System.env.VAG}" //vagrant path
608 commandLine 'cmd','/c','copy_war_be_with_configuration','localhost' , "$PROJECT_PATH\\catalog-be\\target\\catalog-be*.war" , "$BE_REMOTE/webapps"
609 //args = [ ]
610 }
611 }
612
613}
614task feConfig( ) {
615 doLast{
616 exec{
617 workingDir "${System.env.VAG}" //vagrant path
618 commandLine 'cmd','/c','copy_war_fe_with_configuration','localhost' , "$PROJECT_PATH\\catalog-fe\\target\\catalog-fe*.war" , "$FE_REMOTE/webapps"
619 //args = [ ]
620 }
621 }
622
623}
624
625task fe() {
626 doLast{
627 exec {
628 workingDir "${System.env.VAG}" //vagrant path
629 commandLine 'cmd','/c', 'copy_war_fe.bat', 'localhost', "$PROJECT_PATH\\catalog-fe\\target\\catalog-fe*.war", "$FE_REMOTE/webapps"
630 //args = [ ]
631 }
632 }
633}
634
635def installAllProject(){
636 exec{
637 println "[MasterD]--> Compiling&Installing project at -> ${PROJECT_PATH}"
638 workingDir "${PROJECT_PATH}" //vagrant path
639 commandLine 'cmd','/c','mvn -T 2 clean install -U -Pcatalog -Dmaven.test.skip'
640 }
641}
642task installAllProject {
643 doLast {
644 installAllProject()
645 }
646}
647
648task installAll {
649 doLast{
650 println '[MasterD]--> Finished!!'
651 }
652}
653installAll.dependsOn { tasks.findAll { task -> task.name.startsWith('install_') } }
654
655def install_BE(){
656 exec {
657 println '[MasterD][Install]--> Installing BE!!'
658 workingDir "${PROJECT_PATH}"
659 commandLine 'cmd','/c', 'mvn clean install -pl catalog-be -am -Pcatalog -Dmaven.test.skip'
660 //args = [ ]
661 }
662}
663
664task install_BE() {
665 doLast{
666 install_BE()
667 }
668}
669
670def install_FE() {
671 exec {
672 workingDir "${PROJECT_PATH}"
673 commandLine 'cmd','/c', 'mvn clean install -pl catalog-ui,catalog-fe -am -Pcatalog -Dmaven.test.skip'
674 }
675}
676task install_FE() {
677 doLast {
678 install_FE()
679 }
680}
681
682def updaterBERapid(){
683 /* if ( ticket() > PREVIOUS_BUILD_VAR ){
684 PREVIOUS_BUILD_VAR = ticket()*/
685 def started = System.currentTimeMillis();
686 println "[MasterD][Rapid]--> compiling changes using maven"
687 compileWar()
688 println "[MasterD][Rapid]--> copying war"
689 copyBE() //use this if you want to deploy entire war //hotswap.execute()
690 restartBackend()
691 println msg(" redeploy finished in -> ${System.currentTimeMillis() - started}ms ")
692}
693task updaterBERapid(){
694 doLast {
695 updaterBERapid()
696 }
697}
698def updaterBE(){
699 def started = System.currentTimeMillis();
700 IS_MVN_INSTALL = pomChanges() ? true : false
701 println "[MasterD]--> compiling changes using maven"
702 compileDependencies()
703 compileWar()
704 println "[MasterD]--> copying war"
705 IS_HOTSWAP ? copyExplodedBE() : copyBE() //execute() //use this if you want to deploy entire war //hotswap.execute()
706 restartBackend()
707 println msg("redeploy finished in -> ${System.currentTimeMillis() - started}ms ")
708}
709task updaterBE(){
710 doLast {
711 updaterBE()
712 }
713}
714def copyBEConfiguration(){
715/* execSafe {
716 ssh.settings {
717 knownHosts = allowAnyHosts
718 }
719 ssh.run {
720 session(remotes.vagrant) {
721 println msg("Stopping BackEnd Server")
722 execute command[BACKEND][STOP]()
723 }
724 }
725 }*/
726}
727def updaterBEFull(){
728 def started = System.currentTimeMillis();
729 compile()
730 println "[MasterD]--> copying war"
731 copyBE() //use this if you want to deploy entire war //hotswap.execute()
732 copyBEConfiguration()
733 println msg("redeploy finished in -> ${System.currentTimeMillis() - started}ms ")
734}
735task updaterBEFull(){
736 doLast {
737 updaterBEFull()
738 }
739}
740def copyFEConfiguration(){
741 //todo- implement
742}
743def updaterFE(){
744 def started = System.currentTimeMillis();
745 println "[MasterD]--> compiling changes using maven"
746 compileFE()
747 println "[MasterD]--> copying war"
748 copyFE() //.execute() //use this if you want to deploy entire war //hotswap.execute()
749 copyFEConfiguration()
750 println msg("redeploy finished in -> ${System.currentTimeMillis() - started}ms ")
751}
752task updaterFE(){
753 doLast {
754 updaterFE()
755 }
756}
757def stopBackend(){
758 execSafe {
759 ssh.settings {
760 knownHosts = allowAnyHosts
761 }
762 ssh.run {
763 session(remotes.vagrant) {
764 println msg("Stopping BackEnd Server")
765 execute command[BACKEND][STOP]()
766 }
767 }
768 }
769}
770task stopBackend(){
771 doLast {
772 stopBackend()
773 }
774}
775
776def startBackend(){
777 execSafe {
778 ssh.settings {
779 knownHosts = allowAnyHosts
780 }
781 ssh.run {
782 session(remotes.vagrant) {
783 println msg("[MasterD] starting backend sever")
784
785 execute command[BACKEND][START]()
786 }
787 }
788 }
789 println """[MasterD]-> finished !!
790 """
791}
792task startBackend(){
793 doLast{
794 startBackend()
795 }
796}
797
798def restartBackend(){
799 execSafe {
800 ssh.settings {
801 knownHosts = allowAnyHosts
802 }
803 ssh.run {
804 session(remotes.vagrant) {
805 println msg("[MasterD] restarting backend sever")
806
807 execute command[BACKEND][RESTART]()
808 }
809 }
810 }
811 println """[MasterD]-> finished !!
812 """
813}
814//todo- remove this if you want to auto-deploy on every file save
815/*
816compileJava.doFirst{
817 updater?.execute()
818}*/
819
820enum STATUS { UP, DOWN , UNKNOWN , UNAVAILABLE }
821
822task health(){
823 doLast {
824 prepareTray()
825 }
826}
827
828def execSafe( closure){
829 if (!lockObj) {
830 [0..4].forEach( {println "Critical ERROR : lock object is not initialized\n\nCritical ERROR : cannot run tasks\n"}() )
831 return;
832 }
833 synchronized (lockObj){
834 boolean prev = isHaltHealth.get()
835 try {
836 isHaltHealth.set(true)
837 closure()
838 } catch (Exception e) {
839 println e
840 } finally {
841 isHaltHealth.set(prev)
842 }
843 }
844}
845
846def fetchFiles( remote, local ){
847 ssh.run {
848 session(remotes.vagrant) {
849 //execute "cd /home/vagrant/catalog-be/tmp ; ls -lt | grep catalog-be" //todo- use my dates to filter
850 def f = get from: remote , into: local
851 println f?.name
852 //return f
853 }
854 //println "fetched files in ${System.currentTimeMillis() - started} ms"
855 }
856
857 //return null
858}
859
860
861def killJava(){
862 execSafe {
863 def res
864 ssh.run {
865 session( remotes.vagrant ) {
866 println """ *-*-****************************-*-*
867 killing all java proccesses
868 *-*-****************************-*-*
869 """
870 res = execute command[ALL][KILL]()
871 }
872 }
873 println res?.toString()
874 }
875}
876
877def importNormative(){
878 execSafe {
879 ssh.run {
880 session(remotes.vagrant) {
881 println """ *-*-************************************-*-*
882 importNormative
883 *-*-************************************-*-*
884 """
885 execute "python -v $BE_REMOTE/scripts/import/tosca/importNormativeAll.py"
886 }
887 }
888 }
889}
890
891def startAll(){
892 def startCassandra = """
893 #!/bin/bash
894
895 cassandra&
896 elasticsearch -d
897
898 #Wait until ES is up
899 until curl localhost:9200/_cluster/health;
900 do
901 printf "."
902 sleep 3
903 done
904
905 # Create Elastic Mapping if not exist in ES
906 createESMapping.sh
907 """
908 execSafe {
909 ssh.run {
910 session(remotes.vagrant) {
911 println """ *-*-************************************-*-*
912 starting all SDC services(DB,BE,FE,Webseal)
913 *-*-************************************-*-*
914 """
915 if ( NEW_VAG ){
916 execute command[DB][START]()
917 Thread.sleep(5000)
918 execute command[CACHING][START]()
919 }
920 else
921 execute startCassandra
922 //[0..4]?.forEach( Thread?.sleep(2000) )
923 Thread?.sleep(10000)
924 Thread?.sleep(10000)
925 execute command[BACKEND][START]()
926 execute command[FRONTEND][START]()
927 execute command[SECURITY][START]()
928 }
929 }
930 }
931}
932
933
934/*def clearLog(type: Delete){
935 delete{
936 delete 'C:/ProgramData/all.log'
937 followSymlinks = true
938 }
939}*/
940task clearLog(type: Delete){
941 doLast{
942 delete 'C:/ProgramData/all.log'
943 followSymlinks = true
944 }
945}
946def logBE(){
947 try{
948 println "\n*** logging BE all.log ***\n"
949
950 ssh.run {
951 session( remotes.vagrant ) {
952 //String now = execute 'echo \"\$(date +\'%Y_%m_%d\')\"'
953 //println "\n\n*******************************************************\n\n"+now?.toString()
954 clearLog?.execute() //todo- remove this .execute()
955 fetchFiles( '/home/vagrant/catalog-be/logs/SDC/SDC-BE/all.log' , 'C:/ProgramData') //"%USERPROFILE%\AppData\Local\")
956 //project.ext.set( "logFile" , 'C:/ProgramData/all.log' )
957
958 // -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*'
959 }
960 }
961
962 parallel {
963 exec {
964 //if ( logFile ){
965 String notepad = 'C:\\Program Files (x86)\\Notepad++\\notepad++.exe'
966 println "logging $logFile to notepad++ [$notepad]"
967 commandLine 'cmd','/c' , notepad ,logFile
968 }
969 }
970 }catch(Exception e){
971 println "cannot open logs!!!"
972 e.printStackTrace()
973 }
974}
975task logBE(){
976 doLast{
977 logBE()
978 }
979}
980
981def toggleHealthPolling(){
982 isHaltHealth.set(!isHaltHealth.get())
983}
984//converts predefined icon to Image
985def Image convert( imageName ){
986 String encodedimage = project.ext.get(imageName);
987 byte[] byteImage = encodedimage?.split(',')[1]?.decodeBase64()
988 Image image = ImageIO.read(new ByteArrayInputStream(byteImage));
989}
990
991def refreshMenu(String imageName){
992 switch( imageName ) {
993 case 'unavailableImg' : toggleHealthString = "Resume Health"; break;
994 default : toggleHealthString = "Halt Health";
995 }
996 if (((MenuItem)toggleHealthItemView).getLabel() != toggleHealthString)
997 ((MenuItem)toggleHealthItemView).setLabel(toggleHealthString);
998}
999def startDB(){
1000 println "[MasterD] Starting database.."
1001 execSafe {
1002 ssh.settings {
1003 knownHosts = allowAnyHosts
1004 }
1005 ssh.run {
1006 session(remotes.vagrant) {
1007 execute command[DB][START]()
1008 }
1009 }
1010 }
1011}
1012task startDB(){
1013 doLast {
1014 startDB()
1015 }
1016}
1017def stopDB(){
1018 execSafe {
1019 ssh.settings {
1020 knownHosts = allowAnyHosts
1021 }
1022 ssh.run {
1023 session(remotes.vagrant) {
1024 execute command[DB][STOP]()
1025 }
1026 }
1027 }
1028}
1029task stopDB(){
1030 doLast {
1031 stopDB()
1032 }
1033}
1034def startFE(){
1035 execSafe {
1036 ssh.settings {
1037 knownHosts = allowAnyHosts
1038 }
1039 ssh.run {
1040 session(remotes.vagrant) {
1041 execute command[FRONTEND][START]()
1042 }
1043 }
1044 }
1045}
1046task startFE(){
1047 doLast {
1048 startFE()
1049 }
1050}
1051def stopFE(){
1052 execSafe {
1053 ssh.settings {
1054 knownHosts = allowAnyHosts
1055 }
1056 ssh.run {
1057 session(remotes.vagrant) {
1058 execute command[FRONTEND][STOP]()
1059 }
1060 }
1061 }
1062}
1063task stopFE(){
1064 doLast {
1065 stopFE()
1066 }
1067}
1068
1069def ActionListener newListener( closure ){
1070 ActionListener listener = new ActionListener() {
1071 public void actionPerformed(ActionEvent e) {
1072 try {
1073 closure()
1074 } catch (AWTException e1) {
1075 System.err.println(e1);
1076 }
1077 }
1078 }
1079
1080 listener
1081}
1082
1083ext.updateTray = { STATUS status ->
1084 lastStatus = status
1085 if (SystemTray.isSupported()) {
1086 // get the SystemTray instance
1087 SystemTray tray = SystemTray.getSystemTray();
1088 // load an image
1089 String imageName = status==STATUS.UP ? (Math.random()>0.5 ?'okImg1':'okImg2') : status==STATUS.UNAVAILABLE ? 'unavailableImg' : status==STATUS.DOWN ? 'errorImg' : 'warnImg'
1090 Image image = convert imageName
1091 if (trayIcon != null) {
1092 trayIcon.setImage(image)
1093 refreshMenu(imageName);
1094 return ;
1095 }
1096 //region -> Menu UI
1097 // create a popup menu
1098 PopupMenu popup = new PopupMenu();
1099 // create menu item for the default action
1100
1101 MenuItem hotswapItem = new MenuItem("===> WAR <===");
1102 hotswapItem.setFont(new Font("MONOSPACED" , Font.BOLD ,15f ))
1103
1104 //region Multilevel Menus
1105 Menu deployMasterMenu = new Menu("DeployMaster");
1106 Menu backendMenu = new Menu("Backend");
1107 Menu frontendMenu = new Menu("Frontend");
1108 Menu dbMenu = new Menu("Database");
1109 try{
1110 deployMasterMenu.setFont(new Font("Cooper Black" ,Font.BOLD ,14f ))
1111 backendMenu.setFont(new Font("Cooper Black" ,Font.PLAIN ,13f ))
1112 frontendMenu.setFont(new Font("Cooper Black" ,Font.PLAIN ,13f ))
1113 dbMenu.setFont(new Font("Cooper Black" ,Font.PLAIN ,13f ))
1114 }catch(Exception e){
1115 println e
1116 }
1117
1118 //DeployMaster Menu
1119 MenuItem updaterBeWithDependenciesItem = new MenuItem("[BE] Quick Compile -> Deploy");
1120 MenuItem updaterFullBeItem = new MenuItem("[BE] Full Install -> Deploy");
1121 MenuItem updaterFeItem = new MenuItem("[FE] Quick Compile -> Deploy");
1122 MenuItem updaterFullFeItem = new MenuItem("[FE] Full Install -> Deploy");
1123
1124 //Menu UI build
1125
1126 deployMasterMenu.add(updaterFullBeItem);
1127 deployMasterMenu.add(updaterBeWithDependenciesItem);
1128
1129 deployMasterMenu.addSeparator();
1130 deployMasterMenu.add(updaterFullFeItem);
1131 deployMasterMenu.add(updaterFeItem);
1132
1133
1134 //BE menu
1135 MenuItem startItem = new MenuItem("[BE] Start");
1136 MenuItem stopItem = new MenuItem("[BE] Stop BackEnd");
1137 MenuItem copyBeWarItem = new MenuItem("[BE] Copy War");
1138 backendMenu.add(startItem);
1139 backendMenu.add(stopItem);
1140 backendMenu.add(copyBeWarItem);
1141
1142 //FE menu
1143 MenuItem startFEItem = new MenuItem("[FE] Start");
1144 MenuItem stopFEItem = new MenuItem("[FE] Stop");
1145 MenuItem copyFeWarItem = new MenuItem("[FE] Copy War");
1146 frontendMenu.add(startFEItem);
1147 frontendMenu.add(stopFEItem);
1148 frontendMenu.add(copyFeWarItem);
1149
1150 //DB menu
1151 MenuItem startDBItem = new MenuItem("[DB] Start");
1152 MenuItem stopDBItem = new MenuItem("[DB] Stop");
1153 MenuItem backupDBItem = new MenuItem("[DB] Backup");
1154 MenuItem restoreDBItem = new MenuItem("[DB] Restore");
1155 dbMenu.add(startDBItem);
1156 dbMenu.add(stopDBItem);
1157 dbMenu.add(backupDBItem);
1158 dbMenu.add(restoreDBItem);
1159 //endregion
1160
1161
1162 MenuItem killItem = new MenuItem("Kill All");
1163 MenuItem startAllItem = new MenuItem("Start All");
1164 MenuItem importItem = new MenuItem("Import Normative");
1165 MenuItem healthInfoItem = new MenuItem("[Info] Health");
1166 MenuItem toggleHealthItem = new MenuItem(toggleHealthString);
1167 MenuItem logsItem = new MenuItem("Logs [Beta]");
1168 MenuItem exitItem = new MenuItem("Exit");
1169
1170 toggleHealthItemView = toggleHealthItem;
1171
1172 popup.add(hotswapItem);
1173 popup?.addSeparator();
1174 popup.add(deployMasterMenu);
1175 popup?.addSeparator();
1176 popup.add(backendMenu)
1177 popup.add(frontendMenu)
1178 popup.add(dbMenu)
1179 popup?.addSeparator();
1180 popup.add(startAllItem);
1181 popup.add(killItem);
1182 popup?.addSeparator();
1183 popup.add(toggleHealthItem);
1184 popup.add(healthInfoItem);
1185 popup?.addSeparator();
1186 popup.add(importItem);
1187 popup.add(logsItem);
1188 popup?.addSeparator();
1189 popup.add(exitItem);
1190 //endregion UI
1191 // construct a TrayIcon
1192 trayIcon = new TrayIcon(image, "HealthTray", popup);
1193
1194 //region -> Button actions
1195 def listenerHotswap = newListener { project.ext.set("IS_HOTSWAP", !IS_HOTSWAP); hotswapItem?.setLabel( IS_HOTSWAP ? "==> HotSwap <==" : "===> WAR <===") }
1196 // create a action listener to listen for default action executed on the tray icon
1197 def listenerFullBE = newListener { parallel { install_BE(); IS_HOTSWAP ? copyExplodedBE() : copyBE(); restartBackend() } }
1198 def listenerFullFE = newListener { parallel { install_FE(); copyFE() } }
1199 ActionListener listenerFE = newListener { parallel { updaterFE() } }
1200 ActionListener listenerBE = newListener { parallel { updaterBE() } }
1201 ActionListener exitListener = newListener {
1202 executor?.isShutdown() ?: executor?.shutdown()
1203 tray.remove(trayIcon);
1204 project.ext.set("isStopHealthCheck", true)
1205 println "Shutting down.. bye bye.."
1206 }
1207 ActionListener stopBackendListener = newListener { stopBackend() }
1208 ActionListener startBEListener = newListener { parallel { startBackend() } }
1209 ActionListener killJavaListener = newListener { killJava() }
1210
1211 ActionListener startAllListener = newListener { parallel { startAll() } }
1212
1213 ActionListener listener5 = new ActionListener() {
1214 public void actionPerformed(ActionEvent e) {
1215 try {
1216 parallel { importNormative() }
1217 } catch (AWTException e1) {
1218 System.err.println(e1);
1219 }
1220 }
1221 };
1222
1223 ActionListener listener6 = new ActionListener() {
1224 public void actionPerformed(ActionEvent e) {
1225 try {
1226 parallel { healthPopup() }
1227 } catch (AWTException e1) {
1228 System.err.println(e1);
1229 }
1230 }
1231 };
1232
1233 ActionListener listener7 = new ActionListener() {
1234 public void actionPerformed(ActionEvent e) {
1235 try {
1236 logBE()//tasks.logger.execute()
1237 } catch (AWTException e1) {
1238 System.err.println(e1);
1239 }
1240 }
1241 };
1242 ActionListener listener8 = new ActionListener() {
1243 public void actionPerformed(ActionEvent e) {
1244 try {
1245 toggleHealthPolling()//tasks.logger.execute()
1246 } catch (AWTException e1) {
1247 System.err.println(e1);
1248 }
1249 }
1250 };
1251 ActionListener copyBeWarListener = new ActionListener() {
1252 public void actionPerformed(ActionEvent e) {
1253 try {
1254 parallel { copyBE() }//.execute()//tasks.logger.execute()
1255 } catch (AWTException e1) {
1256 System.err.println(e1);
1257 }
1258 }
1259 };
1260
1261 ActionListener startDBListener = new ActionListener() {
1262 public void actionPerformed(ActionEvent e) {
1263 try {
1264 parallel {
1265 startDB()
1266 }//tasks.logger.execute()
1267 } catch (AWTException e1) {
1268 System.err.println(e1);
1269 }
1270 }
1271 }
1272
1273 ActionListener stopDBListener = new ActionListener() {
1274 public void actionPerformed(ActionEvent e) {
1275 try {
1276 stopDB()//tasks.logger.execute()
1277 } catch (AWTException e1) {
1278 System.err.println(e1);
1279 }
1280 }
1281 }
1282
1283 ActionListener dbBackupListener = new ActionListener() {
1284 public void actionPerformed(ActionEvent e) {
1285 try {
1286 parallel {
1287 backupDB()//tasks.logger.execute()
1288 }
1289 } catch (AWTException e1) {
1290 System.err.println(e1);
1291 }
1292 }
1293 }
1294
1295 ActionListener feStartListener = new ActionListener() {
1296 public void actionPerformed(ActionEvent e) {
1297 try {
1298 parallel {
1299 startFE()
1300 }//tasks.logger.execute()
1301 } catch (AWTException e1) {
1302 System.err.println(e1);
1303 }
1304 }
1305 }
1306
1307 ActionListener feStopListener = new ActionListener() {
1308 public void actionPerformed(ActionEvent e) {
1309 try {
1310 stopFE()//tasks.logger.execute()
1311 } catch (AWTException e1) {
1312 System.err.println(e1);
1313 }
1314 }
1315 }
1316
1317 ActionListener feCopyListener = new ActionListener() {
1318 public void actionPerformed(ActionEvent e) {
1319 try {
1320 parallel {
1321 copyFE() //.execute()//tasks.logger.execute()
1322 }
1323 } catch (AWTException e1) {
1324 System.err.println(e1);
1325 }
1326 }
1327 }
1328
1329
1330 //def listenerFullModules = newListener { parallel { installAllProject() } }
1331 //region -> Button<=Listener
1332 hotswapItem.addActionListener(listenerHotswap)
1333 updaterFeItem.addActionListener(listenerFE)
1334 updaterFullBeItem.addActionListener( listenerFullBE )
1335 updaterBeWithDependenciesItem.addActionListener( listenerBE )
1336 updaterFullFeItem.addActionListener( listenerFullFE )
1337 stopItem.addActionListener(stopBackendListener)
1338 startItem.addActionListener(startBEListener)
1339 copyBeWarItem.addActionListener(copyBeWarListener);
1340 killItem.addActionListener(killJavaListener)
1341 startAllItem.addActionListener(startAllListener)
1342 importItem.addActionListener(listener5)
1343 healthInfoItem.addActionListener(listener6)
1344 toggleHealthItem.addActionListener(listener8)
1345 logsItem.addActionListener(listener7)
1346 exitItem.addActionListener(exitListener)
1347
1348 startDBItem.addActionListener( startDBListener )
1349 stopDBItem.addActionListener( stopDBListener )
1350 backupDBItem.addActionListener( dbBackupListener )
1351 copyFeWarItem.addActionListener( feCopyListener )
1352 startFEItem.addActionListener( feStartListener )
1353 stopFEItem.addActionListener( feStopListener )
1354 //endregion
1355 //endregion
1356 // set the TrayIcon properties
1357
1358 // ...
1359 // add the tray image
1360 try {
1361 tray.add(trayIcon);
1362
1363 } catch (AWTException e) {
1364 System.err.println(e);
1365 }
1366 // ...
1367 } else {
1368 println "Java TrayIcon Option is not supported in your System, try enabling it. Bye Bye"
1369 }
1370
1371}
1372
1373def prepareTray(){
1374 long UPDATE_THRESHOLD = 3500
1375 float SCALAR = 1
1376 ssh.settings {
1377 knownHosts = allowAnyHosts
1378 }
1379 while(!isStopHealthCheck) {
1380 if (!isHaltHealth.get()) { //if await or await is more then 60 second return health check
1381 ssh.run {
1382 session(remotes.vagrant) {
1383 try {
1384 def healthOutput = execute command[ALL][HEALTH]()
1385 if (healthOutput?.contains("Failed command .* with status 7") || healthOutput?.contains("Problem accessing /sdc2/rest/healthCheck"))
1386 updateTray(STATUS.DOWN)
1387 def statusCollecion = healthOutput?.findAll "\"healthCheckStatus\": \".*\""
1388 def upCount = statusCollecion?.count { it?.contains("UP") }
1389 def downCount = statusCollecion?.count { it?.contains("DOWN") }
1390 def uknownCount = (statusCollecion?.size() - upCount) - downCount
1391 println " UP -> $upCount | downCount=$downCount | uknownCount=$uknownCount "
1392 (uknownCount > 0 || (downCount > 0 && upCount > 0)) ? updateTray(STATUS.UNKNOWN) : ((upCount > 0) ? updateTray(STATUS.UP) : updateTray(STATUS.DOWN))
1393 SCALAR = 1
1394 } catch (Exception e) {
1395 updateTray(STATUS.DOWN)
1396 println e
1397 SCALAR = Math.min(SCALAR * 1.1, 5) //slow down on errors
1398 }
1399 //green color effects
1400 if (lastStatus && lastStatus == STATUS.UP) {
1401 trayIcon.setImage(convert(Math.random() > 0.5 ? 'okImg1' : 'okImg2'))
1402 //randomly green change color
1403 }
1404 Thread.yield()
1405 Thread?.sleep((long) (UPDATE_THRESHOLD * SCALAR))
1406 }
1407 }
1408 }else{
1409 updateTray(STATUS.UNAVAILABLE)
1410 Thread.yield()
1411 }
1412 }
1413}
1414
1415def healthPopup(){
1416 ssh.run {
1417 session(remotes.vagrant) {
1418 def healthOutput = execute command[ALL][HEALTH]()
1419 JOptionPane.showMessageDialog(null,
1420 healthOutput,
1421 "HEALTH",
1422 JOptionPane.INFORMATION_MESSAGE);
1423 }
1424 }
1425}
1426
1427project.ext.set("msg", { content -> """
1428 ************************************************************************************************
1429 ************************************************************************************************
1430 ******* *********
1431 ************** ****************
1432 $content
1433
1434 ************************************************************************************************
1435 ************************************************************************************************
1436 """} )