1 import java.util.concurrent.Callable
2 import java.util.concurrent.Executors
3 import java.util.concurrent.atomic.AtomicBoolean
4 import java.awt.AWTException
8 import java.awt.MenuItem
9 import java.awt.PopupMenu
10 import java.awt.SystemTray
11 import java.awt.TrayIcon
12 import java.awt.event.ActionEvent
13 import java.awt.event.ActionListener
14 import javax.swing.JOptionPane
15 import javax.imageio.ImageIO
17 import static Services.*
18 import static ServiceControl.*
20 * open CMD -> gradle health
25 version '1.01-SNAPSHOT'
27 apply plugin: 'groovy'
29 apply plugin: "org.hidetake.ssh"
30 apply plugin: 'java-gradle-plugin'
33 sourceCompatibility = 1.8
41 classpath 'org.codehaus.groovy:groovy-all:2.4.12'
42 classpath "org.hidetake:gradle-ssh-plugin:2.9.0"
50 CACHING , //elawsrticsearch
62 OLD_VAGRANT , PROD_VAGRANT , ONAP_VAGRANT
65 //fill YOUR_WINDOWS_USER_HOME
66 project.ext.set("VM_TYPE", Environment.ONAP_VAGRANT) //flags to use new vagrant configuration
67 //project.ext.set("NEW_VAG",Boolean.FALSE) //flags to use new vagrant configuration
68 project.ext.set("IS_HOTSWAP",Boolean.FALSE) //flags to use new vagrant configuration
69 project.ext.set("PROJECT_PATH", System.getenv("SDC")) //ex. 'C:\\GIT_WORK\\asdc\\sdc')
70 project.ext.set("VAGRANT_HOME", isProductionVM() ? System.getenv("NEW_VAG") : isOnapVM() ? System.getenv("ONAP_VAG") :System.getenv("VAG")) //ex. 'C:\\GIT_WORK\\vagrant-asdc-all-in-one')
71 project.ext.set("USER_HOME", "${System.getenv("USERPROFILE")}\\.ssh")
72 project.ext.set("BE_REMOTE", isProductionVM() ? '/opt/app/jetty/base/be' : '/home/vagrant/catalog-be' )
73 project.ext.set("FE_REMOTE", isProductionVM() ? '/opt/app/jetty/base/fe' : '/home/vagrant/catalog-fe' )
74 project.ext.set("VAGRANT_USER", isProductionVM() ? 'm11981' : 'vagrant' )
75 project.ext.set("RSA_PRIVATE_KEY_PATH", isProductionVM() ? "$VAGRANT_HOME/id_rsa" : '' )
76 project.ext.set("VAGRANT_PASSWORD", isProductionVM() ? 'Aa123456' : 'vagrant' )
77 project.ext.set("X_FOLDER",'/xFolder' )
78 project.ext.set("BE_DEPENDENCIES", 'common-be,common-app-api,catalog-dao,catalog-model,security-utils' )
79 project.ext.set("command", [ (ALL) : [ (HEALTH) : { isProductionVM() ? 'sudo curl -i http://localhost:8181/sdc1/rest/healthCheck' : isOnapVM() ? 'sudo -i /data/scripts/docker_health.sh' : 'curl -i localhost:8080/sdc2/rest/healthCheck' } ,
80 (KILL) : { isProductionVM() ? 'sudo pkill java' : isOnapVM() ? 'sudo -i docker kill $(docker ps -q)' : 'pkill java'} ] , // TODO: refine kill only for services
81 (BACKEND) : [ (START) : { isProductionVM() ? 'sudo service jettyBE start' : isOnapVM() ? 'sudo -i docker start sdc-BE' : 'service catalog-be start'} ,
82 (STOP) : { isProductionVM() ? 'sudo service jettyBE stop' : isOnapVM() ? 'sudo -i docker stop sdc-BE' : 'service catalog-be stop'} ,
83 (RESTART) : { isProductionVM() ? 'sudo service jettyBE restart' : isOnapVM() ? 'sudo -i docker restart sdc-BE' : 'service catalog-be restart'}] ,
84 (DB) : [ (START) : { isProductionVM() ? 'sudo service cassandra start' : isOnapVM() ? 'sudo -i docker start sdc-cs' : 'start-asdc-storage.sh' } ,
85 (STOP) : { isProductionVM() ? 'sudo service cassandra stop' : isOnapVM() ? 'sudo -i docker stop sdc-cs' : 'service cassandra stop'} ,
86 (RESTART) : { isProductionVM() ? 'sudo service cassandra restart' : isOnapVM() ? 'sudo -i docker restart sdc-cs' : 'service cassandra restart'} ] ,
87 (FRONTEND): [ (START) : { isProductionVM() ? 'sudo service jettyFE start' : isOnapVM() ? 'sudo -i docker start sdc-FE' : 'service catalog-fe start' } ,
88 (STOP) : { isProductionVM() ? 'sudo service jettyFE stop' : isOnapVM() ? 'sudo -i docker stop sdc-FE' : 'service catalog-fe stop'} ,
89 (RESTART) : { isProductionVM() ? 'sudo service jettyFE restart' : isOnapVM() ? 'sudo -i docker restart sdc-FE' : 'service catalog-fe restart' } ] ,
90 (CACHING): [ (START) : { isProductionVM() ? 'sudo service elasticsearch start' : isOnapVM() ? 'sudo -i docker start sdc-es' : 'echo "starting es is not yet supported"' } ],
91 (SECURITY): [ (START) : { isProductionVM() ? 'sudo docker start sdc-WebSeal-Simulator' : isOnapVM() ? 'sudo -i /data/scripts/simulator_docker_run.sh -r $(echo $(sudo -i docker images onap/sdc-simulator | grep onap/sdc-simulator | head -1 | awk \'{print $2}\'))' : 'service webseal-simulator start' } ,
92 (STOP) : { isProductionVM() ? 'sudo docker stop sdc-WebSeal-Simulator' : isOnapVM() ? 'sudo -i docker stop sdc-sim' : 'service webseal-simulator stop'} ,
93 (RESTART) : { isProductionVM() ? 'sudo docker restart sdc-WebSeal-Simulator' : isOnapVM() ? 'sudo -i docker restart sdc-sim' : 'service webseal-simulator restart'}]
94 ] ) //abstraction level to shell scripts , support old and new vagrant bash commands
97 project.ext.set("warnImg",'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAAADvSURBVDhPY2RgYPgPxGQDiAGLXkB4UMD56DuD9YFUhj179oD5Li4uDEcdZjN8l+ME8+EgTgLTAJDm7zWKYPb/enUwzdh4E0xzttxHNQRoABOUCQYYmj+9QrCBACQHUoMM4AYga74ZDiRAmvnEwHwQGywGBOiGgA1A16wmJYjQDAJANkgMmyEosYBVMzIAuuTWs/cM6iuhfCCAGwDWrAHxKyFw68ZNuCE40wGygcga0AEkEEHRiIxxASzqUKKRHIAwAJgo4BgXwKIGxQUgf8MwOsAlh+EFUMDBMAxgE0MGoLwAignSMFQPzmgkDjAwAACSmn13nChk1QAAAABJRU5ErkJggg==')
98 project.ext.set("okImg1",'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAAAD4SURBVDhPY2RgYPgPxGQDiAGLXkB4UMD56DuD9YFUhj179oD5Li4uDEcdZjN8l+ME8+EgTgLTAJDm7zWKYLbSRh8wfc9/C5jmbLmPagjQACYoEwwwNLMxgzHMIJAcSA0ygBuArFm81gyi+ddfCAaywWJAgG4I2AB0zdxWkhCNMABkg8SwGYISC1g1IwOgS74ee87wsvkUVADJAJjpyIDbRAxMfz3zCkwjA5ghONMB2DVIBiDbigwggQiKRmSMC2BRhxKN5ACEAcBEAce4ABY1LFAaDLAFJAwgyyGHB4YXQAEHwzCATQwZgPICKCZIw1A9OKOROMDAAAA4gXvZorg7ZgAAAABJRU5ErkJggg==')
99 project.ext.set("okImg2" , 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAAADjSURBVDhPY2RgYPgPxGQDiAGLXkB4UMD56DuD9YFUhj179oD5Li4uDEcdZjN8l+ME8+EgTgLTAJDm7zWKYPbWZ7Jg2lvqMZjmbLmPagjQACYoEwywaQYBGBskB1KDDOAGIGuetFsUTCMDmBi6IWAD0DUra3OA2cgAJIbNEJRYwKUZGdy9+oMhz/U1lIdkADZnwwwDaUIHMENwpgNk16DbigwggQiKRmSMC2BRhxKN5ACEAcBEAce4ABY1LFAaDLAFJAwgyyGHB4YXQAEHwzCATQwZgPICKCZIw1A9OKOROMDAAAAZD3X55epfOAAAAABJRU5ErkJggg==')
100 project.ext.set("errorImg" , 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAAADlSURBVDhPY2RgYPgPxGQDiAGLXkB4UMD56DuD9YFUhj179oD5Li4uDEcdZjN8l+ME8+EgTgLTAJDm7zWKYPZbGRUwLfzkDpjmbLmPagjQACYoEwywaQYBGBskB1KDDOAGIGtexisCppEBTAzdELAB6Jrd+QXAbGQAEsNmCEos4NKMDHZ+/MAQ9fkNlIdkADZnwwwDaUIHyIaADMDAQAP/AwMPjEFsbGpAGGs6AEUPsnfgzsaiDiUayQUgF2A4jaAXoHpQXAByNgyjA1xyGF4A+RuGYQCbGDLA6gWCGKoHJSGRDhgYAL/hkunRq+joAAAAAElFTkSuQmCC')
101 project.ext.set("unavailableImg" , 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAABJ0AAASdAHeZh94AAAAB3RJTUUH4QwNDgEDrNoaqgAAAOhJREFUOMulkz8OgjAUhz8MQ7mBkwnnkBAH4mbCCdxcXLwAoxdwYXHjBCRupoMheg4TJ29QNhwshMofSfpLOry2v6/vta8OUGEhF4DsbUx6L8XytkNKCUAURTxWZ9TCM93buQb8mFXiI4E43gCQ5xeQPt7x2YG4fWa0OQwDhBANRCVdyGyKOQyDJhuV+HgvZQLGzABCiEGI036FPnNbZVlSFPfvnWg1gJpea72OjPh6lUZcQ5yhPkjTkxHv94fpfcB23t81PftmWMr9e+pQZjobd6zuobX2fViXAFCRvSv9GtOH9ji23/kDswRrCVqtQOAAAAAASUVORK5CYII=')
105 project.ext.set("trayIcon", null)
106 project.ext.set("lastStatus", null)
107 project.ext.set("isStopHealthCheck", false)
108 project.ext.set("isHaltHealth", new AtomicBoolean(false) )
109 project.ext.set("startedAwait", Long.MAX_VALUE)
110 project.ext.set("logFile", 'C:/ProgramData/all.log')
111 project.ext.set("pomList" , ["${System?.getenv('SDC')}/catalog-fe/pom.xml" ,"${System?.getenv('SDC')}/catalog-be/pom.xml" ] ) //empty list will scan all openecomp poms
112 project.ext.set("pomChangesMap" , [:] )
113 project.ext.set("beConfigFilesToCopyMapping" , [ 'src/main/resources/config/*.yaml' : 'config/catalog-be/' ,
114 'src/main/resources/config/*.properties' : 'config/catalog-be/'] )
117 project.ext.set("toggleHealthString" , "Halt Health" )
119 project.ext.set("toggleHealthItemView" , null )
122 project.ext.set("IS_MVN_INSTALL",false)
123 project.ext.set("executor" , null )
124 project.ext.set("lockObj" , new Object() )
126 def hash( List list ){
127 def map = list?.collectEntries { File file -> [(file?.absolutePath) : file?.text?.hashCode() ]}
133 long started = System.currentTimeMillis()
137 def changes = pomList?.findAll {
138 def File file = new File(it);
139 pomChangesMap[it] != file?.text?.hashCode()
141 println "\n\n[MasterD][POM]--> detected changes for -> $changes"
142 //update changes in map
143 changes?.each { pomChangesMap[it] = new File(it)?.text?.hashCode() }
144 println "\n\n[MasterD][POM]--> pom map -> $pomChangesMap"
147 ****** POM changes detection finished after -> ${System.currentTimeMillis()- started}ms ******
152 //list pom with updated file hashes
154 long started = System.currentTimeMillis()
156 def tree = fileTree( PROJECT_PATH ).include '**/pom.xml'//.filter { it.isFile() && it?.toString()?.toLowerCase()?.endsWith('pom.xml') }
157 //println "$PROJECT_PATH list is ->${ list?.collect { it?.absolutePath } }"
158 //flatten and filter openecomp poms
159 pomList = tree?.flatten()?.findAll { File file -> file?.text?.contains('org.openecomp.sdc') }?.collect {File file -> file?.absolutePath }
161 pomChangesMap = pomList.collectEntries { absolutePath ->[ ( absolutePath ) : new File(absolutePath)?.text?.hashCode() ] }
163 println """ [MasterD][Init] intializing POM detector
165 ********* POM listing finished after -> ${System.currentTimeMillis()- started}ms *********
171 task initialization(){
173 executor = Executors.newCachedThreadPool();
176 def parallel( closure ){
177 executor?.submit(new Callable<Object>(){
179 public Object call() {
185 /*class Preferences {
187 def String IsNewVagrant
188 def String IsRapidMode
192 def folder = new File(X_FOLDER);
193 folder?.exists() ?: folder?.mkdirs()
195 new File("${folder?.absolutePath}/$PREFERENCES_FILENAME")
200 //postStat(10000, "shay" , "report/index")
202 new File('catalog-be\\pom.xml') << "#hello"
208 def fetchFilesByExtention(remote, local , ext ){
210 def started = System.currentTimeMillis()
211 println "folder diff"
212 session(remotes.vagrant) {
213 //execute "cd /home/vagrant/catalog-be/tmp ; ls -lt | grep catalog-be" //todo- use my dates to filter
214 get from: remote , into: local , filter: { it?.absolutePath =~ /jetty.*catalog-be.*\.dir.*\.$ext/ } // { it?.absolutePath =~ /.*catalog-be.*dir.*classes.*/ }
216 println "fetched files in ${System.currentTimeMillis() - started} ms"
220 def updateRemoteFile(String remote , String local){
222 def to = "$BE_REMOTE${remote[remote?.indexOf("tmp\\")..remote.size()-1].replaceAll("\\\\","/")}"
223 println "copying $local \nto\n $to"
224 session(remotes.vagrant) {
225 put from: local , into: to }
229 def compareAndSwap(){
231 def newClasses = new File("$PROJECT_PATH\\catalog-be\\target\\classes")
232 def File jettyClasses ;
234 println "traversing.."
235 new File("build/hotswap").traverse { if (it?.directory && it?.name?.equals("classes")){
239 def jettyClassesList = []
240 jettyClasses?.traverse { jettyClassesList << it }
242 println "$jettyClasses"
243 //Sort compiled classes
245 newClasses?.traverse { files << it }
246 def result = files.sort{ a,b -> b.lastModified() <=> a.lastModified() }
247 println "show only last $LIMIT changes"
248 result[0..LIMIT]?.each{ println it?.lastModified() +" | "+ it?.name + (it?.directory ? "[Directory]" : "") } //show only last 10 changes
251 def changesMap = [ : ] //<old,new>
252 println "updating changes"
253 result[0..LIMIT]?.each { File f -> def File other = jettyClassesList.find{ File other-> other?.absolutePath?.endsWith(f?.name) };
254 if ( !(f.directory) && f?.text?.hashCode() != other?.text?.hashCode() )
255 updateRemoteFile( other?.getAbsolutePath() , f?.getAbsolutePath() )
261 new File("build/hotswap")?.deleteDir()
262 new File("build/hotswap")?.mkdirs()
264 knownHosts = allowAnyHosts
266 fetchFilesByExtention( "$BE_REMOTE/tmp/" , 'build/hotswap' , "class")
276 password = VAGRANT_PASSWORD
277 identity = isProductionVM() ? new File(RSA_PRIVATE_KEY_PATH) : null
282 def isProductionVM(){
283 return VM_TYPE?.equals(Environment.PROD_VAGRANT)
287 return VM_TYPE?.equals(Environment.ONAP_VAGRANT)
296 backupDB() //and clean all
297 //restoreDB() //restore latest
302 //todo- conside updating from git
306 def importHeatTypes(){
314 // add conformence level
316 def createSchemaPreStep(){
319 def createSchemaPostStep(){
320 ////todo- impl create amdocs dox
323 createSchemaPreStep()
324 //todo- create schema
326 createSchemaPostStep()
332 knownHosts = allowAnyHosts
335 session(remotes.vagrant) {
336 execute "sudo cqlsh -e 'DROP KEYSPACE titan;'"
337 println "[MasterD][DB_DROP]-> Dropped 'titan' KEYSPACE."
356 knownHosts = allowAnyHosts
359 session(remotes.vagrant) {
360 def tmp = '$CASSANDRA_HOME/backup/e2e'
361 //execute 'mkdir $CASSANDRA_HOME/backup/e2e/'
362 //execute 'wget http://135.76.210.202:8080/ETE_backup_files/latest_ETE_backup_file.zip -P /vagrant/db'
363 println "[MasterD] download finished, unzipping.."
364 execute "unzip -u $tmp/latest_ETE_backup_file.zip" //execute 'unzip -u /vagrant/db/latest_ETE_backup_file.zip'//'
365 def folder = execute "cd $tmp; ls -d -- */"
366 println "[MasterD] unzipping finished into -> $folder , untaring.."
367 execute "tar zxf $tmp/$folder/* --strip 3 -C" +'$CASSANDRA_HOME/data | pv -l >/dev/null'
368 println "[MasterD][E2E_DB]-> Downloaded & unzipped e2e data successfully."
373 def copyExplodedBE() {
375 println "[MasterD][BackEnd] copying exploded war."
377 knownHosts = allowAnyHosts
379 long started = System.currentTimeMillis()
380 def dirPath = "${PROJECT_PATH}/catalog-be/target/catalog-be-1.1.0-SNAPSHOT"
381 def dir = new File(dirPath);
382 println "[MasterD][BackEnd] copying ${dir?.directorySize()/(1024*1024)} MB, from ${dir?.name} to $BE_REMOTE/webapps"
384 session(remotes.vagrant) {
385 execute "rm -R $BE_REMOTE/webapps/catalog-be-1.1.0-SNAPSHOT"
386 put from: dir?.absolutePath , into: "$BE_REMOTE/webapps"
389 println "[MasterD][BackEnd] Successfully copied exploded war in ${System.currentTimeMillis()-started}ms."
392 task copyExplodedBE(){
400 knownHosts = allowAnyHosts
403 session(remotes.vagrant) {
404 execute 'mkdir -p $CASSANDRA_HOME/backup'
405 def res = execute 'mv $CASSANDRA_HOME/data $CASSANDRA_HOME/backup/data_$(date +\'%Y_%m_%d__%H:%M:%S\')'
406 println "[MasterD][DB_BACKUP]-> snapshot DB finished. $res"
420 knownHosts = allowAnyHosts
423 session(remotes.vagrant) {
424 println "[MasterD]-> restoring DB"
425 execute 'mkdir -p $CASSANDRA_HOME/data'
426 def res = execute 'mv $CASSANDRA_HOME/backup/data_*/* $CASSANDRA_HOME/data'
427 println "[MasterD]-> DB restore FINISHED!! $res"
441 workingDir VAGRANT_HOME //vagrant path
442 println "*****************\nworking dir -> $VAGRANT_HOME"
443 commandLine "cmd","/c", "vagrant up"
446 println "[MasterD]--> please define windows enviroment variable VAG pointing to vagrant project"
458 println "[MasterD][FrontEnd] starting war copy."
460 knownHosts = allowAnyHosts
462 long started = System.currentTimeMillis()
463 def target = "${PROJECT_PATH}/catalog-fe/target/"
464 def files = GFileUtils.listFiles( new File(target) , ["war"] as String[] , false);
465 files?.each{ File file ->
466 if (!file?.name?.contains('classes')){
467 println "[MasterD][FrontEnd] copying ${file.length()/(1024*1024)} MB, from ${file?.name} to $FE_REMOTE/webapps"
469 session(remotes.vagrant) {
470 if ( isProductionVM() )
471 execute 'sudo chmod -R 777 /opt/app/jetty/base/fe/webapps'
472 put from: file?.absolutePath , into: "$FE_REMOTE/webapps"
478 println "[MasterD][FrontEnd] Successfully copied war in ${System.currentTimeMillis()-started}ms."
489 println "[MasterD][BackEnd] starting war copy."
491 knownHosts = allowAnyHosts
493 def target = "${PROJECT_PATH}/catalog-be/target/"
494 def files = GFileUtils.listFiles( new File(target) , ["war"] as String[] , false);
495 long started = System.currentTimeMillis()
496 files?.each{ File file ->
497 if (!file?.name?.contains('classes')){
498 println "[MasterD][BackEnd] copying ${file.length()/(1024*1024)} MB, from ${file?.name} to $BE_REMOTE/webapps"
500 session(remotes.vagrant) {
501 if (isProductionVM())
502 execute 'sudo chmod -R 777 /opt/app/jetty/base/be/webapps'
503 put from: file?.absolutePath , into: "$BE_REMOTE/webapps"
508 println "[MasterD][BackEnd] SUCCESSFULY copied be war in ${System.currentTimeMillis()-started}ms."
518 println "[MasterD][FE]--> compiling project at -> ${PROJECT_PATH}\\catalog-fe"
519 workingDir "${PROJECT_PATH}" //vagrant path
520 commandLine 'cmd','/c','mvn -T 2 compile -pl catalog-fe,catalog-ui -am -Pcatalog -Dmaven.test.skip'
530 println "[MasterD][BE]--> compiling project at -> ${PROJECT_PATH}\\catalog-be"
531 workingDir "${PROJECT_PATH}" //vagrant path
532 commandLine 'cmd','/c','mvn -T 2 compile -pl catalog-be -Pcatalog -Dmaven.test.skip'
543 println "[MasterD]--> compiling project at -> ${PROJECT_PATH}"
544 workingDir "${PROJECT_PATH}" //vagrant path
545 commandLine 'cmd','/c','mvn -T 2 compile -am -Pcatalog -Dmaven.test.skip'
554 def compileDependencies(){
555 def cmd = IS_MVN_INSTALL ? 'install' : 'compile'
557 println "[MasterD]--> compiling BE dependencies -> $BE_DEPENDENCIES [ SKIPPING TESTS!! ]"
558 workingDir "${PROJECT_PATH}" //vagrant path
559 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'
562 task compileDependencies {
564 compileDependencies()
568 def cmd = IS_MVN_INSTALL ? 'install' : 'compile'
570 println "--> compiling project at -> ${PROJECT_PATH}\\catalog-be"
571 workingDir "${PROJECT_PATH}" //vagrant path
572 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'
581 //deprecated - use deployBE()
584 def started = System.currentTimeMillis();
586 println "[MasterD]--> copying be... [from $VAGRANT_HOME]"
587 workingDir VAGRANT_HOME //vagrant path
588 commandLine 'cmd','/c', 'copy_war_be.bat','localhost' , "$PROJECT_PATH\\catalog-be\\target\\catalog-be*.war" , "$BE_REMOTE/webapps"
592 **** copying finished in -> ${System.currentTimeMillis() - started}ms ****
600 workingDir "${System.env.VAG}" //vagrant path
601 commandLine 'cmd','/c','copy_war_be_with_configuration','localhost' , "$PROJECT_PATH\\catalog-be\\target\\catalog-be*.war" , "$BE_REMOTE/webapps"
610 workingDir "${System.env.VAG}" //vagrant path
611 commandLine 'cmd','/c','copy_war_fe_with_configuration','localhost' , "$PROJECT_PATH\\catalog-fe\\target\\catalog-fe*.war" , "$FE_REMOTE/webapps"
621 workingDir "${System.env.VAG}" //vagrant path
622 commandLine 'cmd','/c', 'copy_war_fe.bat', 'localhost', "$PROJECT_PATH\\catalog-fe\\target\\catalog-fe*.war", "$FE_REMOTE/webapps"
628 def installAllProject(){
630 println "[MasterD]--> Compiling&Installing project at -> ${PROJECT_PATH}"
631 workingDir "${PROJECT_PATH}" //vagrant path
632 commandLine 'cmd','/c','mvn -T 2 clean install -U -Pcatalog -Dmaven.test.skip'
635 task installAllProject {
643 println '[MasterD]--> Finished!!'
646 installAll.dependsOn { tasks.findAll { task -> task.name.startsWith('install_') } }
650 println '[MasterD][Install]--> Installing BE!!'
651 workingDir "${PROJECT_PATH}"
652 commandLine 'cmd','/c', 'mvn clean install -pl catalog-be -am -Pcatalog -Dmaven.test.skip'
665 workingDir "${PROJECT_PATH}"
666 commandLine 'cmd','/c', 'mvn clean install -pl catalog-ui,catalog-fe -am -Pcatalog -Dmaven.test.skip'
675 def updaterBERapid(){
676 /* if ( ticket() > PREVIOUS_BUILD_VAR ){
677 PREVIOUS_BUILD_VAR = ticket()*/
678 def started = System.currentTimeMillis();
679 println "[MasterD][Rapid]--> compiling changes using maven"
681 println "[MasterD][Rapid]--> copying war"
682 copyBE() //use this if you want to deploy entire war //hotswap.execute()
684 println msg(" redeploy finished in -> ${System.currentTimeMillis() - started}ms ")
686 task updaterBERapid(){
692 def started = System.currentTimeMillis();
693 IS_MVN_INSTALL = pomChanges() ? true : false
694 println "[MasterD]--> compiling changes using maven"
695 compileDependencies()
697 println "[MasterD]--> copying war"
698 IS_HOTSWAP ? copyExplodedBE() : copyBE() //execute() //use this if you want to deploy entire war //hotswap.execute()
700 println msg("redeploy finished in -> ${System.currentTimeMillis() - started}ms ")
707 def copyBEConfiguration(){
710 knownHosts = allowAnyHosts
713 session(remotes.vagrant) {
714 println msg("Stopping BackEnd Server")
715 execute command[BACKEND][STOP]()
721 def started = System.currentTimeMillis();
723 println "[MasterD]--> copying war"
724 copyBE() //use this if you want to deploy entire war //hotswap.execute()
725 copyBEConfiguration()
726 println msg("redeploy finished in -> ${System.currentTimeMillis() - started}ms ")
728 task updaterBEFull(){
733 def copyFEConfiguration(){
737 def started = System.currentTimeMillis();
738 println "[MasterD]--> compiling changes using maven"
740 println "[MasterD]--> copying war"
741 copyFE() //.execute() //use this if you want to deploy entire war //hotswap.execute()
742 copyFEConfiguration()
743 println msg("redeploy finished in -> ${System.currentTimeMillis() - started}ms ")
753 knownHosts = allowAnyHosts
756 session(remotes.vagrant) {
757 println msg("Stopping BackEnd Server")
758 execute command[BACKEND][STOP]()
772 knownHosts = allowAnyHosts
775 session(remotes.vagrant) {
776 println msg("[MasterD] starting backend sever")
778 execute command[BACKEND][START]()
782 println """[MasterD]-> finished !!
791 def restartBackend(){
794 knownHosts = allowAnyHosts
797 session(remotes.vagrant) {
798 println msg("[MasterD] restarting backend server")
800 execute command[BACKEND][RESTART]()
804 println """[MasterD]-> finished !!
809 println "[MasterD] starting security&simulator engine"
812 knownHosts = allowAnyHosts
815 session(remotes.vagrant) {
816 execute command[SECURITY][START]()
820 println """[MasterD]-> finished !!
823 task startSecurity(){
830 println "[MasterD] stopping security&simulator engine"
833 knownHosts = allowAnyHosts
836 session(remotes.vagrant) {
837 execute command[SECURITY][STOP]()
841 println """[MasterD]-> finished !!
852 //todo- remove this if you want to auto-deploy on every file save
858 enum STATUS { UP, DOWN , UNKNOWN , UNAVAILABLE }
866 def execSafe( closure){
868 [0..4].forEach( {println "Critical ERROR : lock object is not initialized\n\nCritical ERROR : cannot run tasks\n"}() )
871 synchronized (lockObj){
872 boolean prev = isHaltHealth.get()
874 isHaltHealth.set(true)
876 } catch (Exception e) {
879 isHaltHealth.set(prev)
884 def fetchFiles( remote, local ){
886 session(remotes.vagrant) {
887 //execute "cd /home/vagrant/catalog-be/tmp ; ls -lt | grep catalog-be" //todo- use my dates to filter
888 def f = get from: remote , into: local
892 //println "fetched files in ${System.currentTimeMillis() - started} ms"
903 session( remotes.vagrant ) {
904 println """ *-*-****************************-*-*
905 killing all java proccesses
906 *-*-****************************-*-*
908 res = execute command[ALL][KILL]()
911 println res?.toString()
915 def importNormative(){
918 session(remotes.vagrant) {
919 println """ *-*-************************************-*-*
921 *-*-************************************-*-*
923 execute "sudo python -v $BE_REMOTE/scripts/import/tosca/importNormativeAll.py"
930 def startCassandra = """
937 until curl localhost:9200/_cluster/health;
943 # Create Elastic Mapping if not exist in ES
948 session(remotes.vagrant) {
949 println """ *-*-************************************-*-*
950 starting all SDC services(DB,BE,FE,Webseal)
951 *-*-************************************-*-*
953 if ( isProductionVM() ){
954 execute command[DB][START]()
956 execute command[CACHING][START]()
959 execute startCassandra
960 //[0..4]?.forEach( Thread?.sleep(2000) )
963 execute command[BACKEND][START]()
964 execute command[FRONTEND][START]()
965 execute command[SECURITY][START]()
972 /*def clearLog(type: Delete){
974 delete 'C:/ProgramData/all.log'
975 followSymlinks = true
978 task clearLog(type: Delete){
980 delete 'C:/ProgramData/all.log'
981 followSymlinks = true
986 println "\n*** logging BE all.log ***\n"
989 session( remotes.vagrant ) {
990 //String now = execute 'echo \"\$(date +\'%Y_%m_%d\')\"'
991 //println "\n\n*******************************************************\n\n"+now?.toString()
992 clearLog?.execute() //todo- remove this .execute()
993 fetchFiles( '/home/vagrant/catalog-be/logs/SDC/SDC-BE/all.log' , 'C:/ProgramData') //"%USERPROFILE%\AppData\Local\")
994 //project.ext.set( "logFile" , 'C:/ProgramData/all.log' )
996 // -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*'
1003 String notepad = 'C:\\Program Files (x86)\\Notepad++\\notepad++.exe'
1004 println "logging $logFile to notepad++ [$notepad]"
1005 commandLine 'cmd','/c' , notepad ,logFile
1008 }catch(Exception e){
1009 println "cannot open logs!!!"
1019 def toggleHealthPolling(){
1020 isHaltHealth.set(!isHaltHealth.get())
1022 //converts predefined icon to Image
1023 def Image convert( imageName ){
1024 String encodedimage = project.ext.get(imageName);
1025 byte[] byteImage = encodedimage?.split(',')[1]?.decodeBase64()
1026 Image image = ImageIO.read(new ByteArrayInputStream(byteImage));
1029 def refreshMenu(String imageName){
1030 switch( imageName ) {
1031 case 'unavailableImg' : toggleHealthString = "Resume Health"; break;
1032 default : toggleHealthString = "Halt Health";
1034 if (((MenuItem)toggleHealthItemView).getLabel() != toggleHealthString)
1035 ((MenuItem)toggleHealthItemView).setLabel(toggleHealthString);
1038 println "[MasterD] Starting database.."
1041 knownHosts = allowAnyHosts
1044 session(remotes.vagrant) {
1045 execute command[DB][START]()
1058 knownHosts = allowAnyHosts
1061 session(remotes.vagrant) {
1062 execute command[DB][STOP]()
1075 knownHosts = allowAnyHosts
1078 session(remotes.vagrant) {
1079 execute command[FRONTEND][START]()
1092 knownHosts = allowAnyHosts
1095 session(remotes.vagrant) {
1096 execute command[FRONTEND][STOP]()
1107 def ActionListener newListener( closure ){
1108 ActionListener listener = new ActionListener() {
1109 public void actionPerformed(ActionEvent e) {
1112 } catch (AWTException e1) {
1113 System.err.println(e1);
1121 ext.updateTray = { STATUS status ->
1123 if (SystemTray.isSupported()) {
1124 // get the SystemTray instance
1125 SystemTray tray = SystemTray.getSystemTray();
1127 String imageName = status==STATUS.UP ? (Math.random()>0.5 ?'okImg1':'okImg2') : status==STATUS.UNAVAILABLE ? 'unavailableImg' : status==STATUS.DOWN ? 'errorImg' : 'warnImg'
1128 Image image = convert imageName
1129 if (trayIcon != null) {
1130 trayIcon.setImage(image)
1131 refreshMenu(imageName);
1135 // create a popup menu
1136 PopupMenu popup = new PopupMenu();
1137 // create menu item for the default action
1139 MenuItem hotswapItem = new MenuItem("===> WAR <===");
1140 hotswapItem.setFont(new Font("MONOSPACED" , Font.BOLD ,15f ))
1142 //region Multilevel Menus
1143 Menu deployMasterMenu = new Menu("DeployMaster");
1144 Menu backendMenu = new Menu("Backend");
1145 Menu frontendMenu = new Menu("Frontend");
1146 Menu dbMenu = new Menu("Database");
1147 Menu securityMenu = new Menu("Security");
1149 deployMasterMenu.setFont(new Font("Cooper Black" ,Font.BOLD ,14f ))
1150 backendMenu.setFont(new Font("Cooper Black" ,Font.PLAIN ,13f ))
1151 frontendMenu.setFont(new Font("Cooper Black" ,Font.PLAIN ,13f ))
1152 dbMenu.setFont(new Font("Cooper Black" ,Font.PLAIN ,13f ))
1153 securityMenu.setFont(new Font("Cooper Black" ,Font.PLAIN ,13f ))
1154 }catch(Exception e){
1159 MenuItem updaterBeWithDependenciesItem = new MenuItem("[BE] Quick Compile -> Deploy");
1160 MenuItem updaterFullBeItem = new MenuItem("[BE] Full Install -> Deploy");
1161 MenuItem updaterFeItem = new MenuItem("[FE] Quick Compile -> Deploy");
1162 MenuItem updaterFullFeItem = new MenuItem("[FE] Full Install -> Deploy");
1166 deployMasterMenu.add(updaterFullBeItem);
1167 deployMasterMenu.add(updaterBeWithDependenciesItem);
1169 deployMasterMenu.addSeparator();
1170 deployMasterMenu.add(updaterFullFeItem);
1171 deployMasterMenu.add(updaterFeItem);
1175 MenuItem startItem = new MenuItem("[BE] Start");
1176 MenuItem stopItem = new MenuItem("[BE] Stop BackEnd");
1177 MenuItem copyBeWarItem = new MenuItem("[BE] Copy War");
1178 backendMenu.add(startItem);
1179 backendMenu.add(stopItem);
1180 (isOnapVM()) ?: backendMenu.add(copyBeWarItem);
1183 MenuItem startFEItem = new MenuItem("[FE] Start");
1184 MenuItem stopFEItem = new MenuItem("[FE] Stop");
1185 MenuItem copyFeWarItem = new MenuItem("[FE] Copy War");
1186 frontendMenu.add(startFEItem);
1187 frontendMenu.add(stopFEItem);
1188 (isOnapVM()) ?: frontendMenu.add(copyFeWarItem);
1191 MenuItem startDBItem = new MenuItem("[DB] Start");
1192 MenuItem stopDBItem = new MenuItem("[DB] Stop");
1193 MenuItem backupDBItem = new MenuItem("[DB] Backup");
1194 MenuItem restoreDBItem = new MenuItem("[DB] Restore");
1195 dbMenu.add(startDBItem);
1196 dbMenu.add(stopDBItem);
1197 dbMenu.add(backupDBItem);
1198 dbMenu.add(restoreDBItem);
1201 MenuItem startSecurityItem = new MenuItem("[Security] Start");
1202 MenuItem stopSecurityItem = new MenuItem("[Security] Stop");
1203 securityMenu.add(startSecurityItem)
1204 securityMenu.add(stopSecurityItem)
1206 MenuItem killItem = new MenuItem("Kill All");
1207 MenuItem startAllItem = new MenuItem("Start All");
1208 MenuItem importItem = new MenuItem("Import Normative");
1209 MenuItem healthInfoItem = new MenuItem("[Info] Health");
1210 MenuItem toggleHealthItem = new MenuItem(toggleHealthString);
1211 MenuItem logsItem = new MenuItem("Logs [Beta]");
1212 MenuItem exitItem = new MenuItem("Exit");
1214 toggleHealthItemView = toggleHealthItem;
1216 (isOnapVM()) ?: popup.add(hotswapItem);
1217 (isOnapVM()) ?:popup?.addSeparator();
1218 (isOnapVM()) ?: popup.add(deployMasterMenu);
1219 (isOnapVM()) ?:popup?.addSeparator();
1220 popup.add(backendMenu)
1221 popup.add(frontendMenu)
1222 (isOnapVM()) ?: popup.add(dbMenu)
1223 popup?.addSeparator();
1224 popup?.add(securityMenu)
1225 popup?.addSeparator();
1226 popup.add(startAllItem);
1227 popup.add(killItem);
1228 popup?.addSeparator();
1229 popup.add(toggleHealthItem);
1230 popup.add(healthInfoItem);
1231 (isOnapVM()) ?:popup?.addSeparator();
1232 (isOnapVM()) ?: popup.add(importItem);
1233 (isOnapVM()) ?: popup.add(logsItem);
1234 popup?.addSeparator();
1235 popup.add(exitItem);
1237 // construct a TrayIcon
1238 trayIcon = new TrayIcon(image, "HealthTray", popup);
1240 //region -> Button actions
1241 def listenerHotswap = newListener { project.ext.set("IS_HOTSWAP", !IS_HOTSWAP); hotswapItem?.setLabel( IS_HOTSWAP ? "==> HotSwap <==" : "===> WAR <===") }
1242 // create a action listener to listen for default action executed on the tray icon
1243 def listenerFullBE = newListener { parallel { install_BE(); IS_HOTSWAP ? copyExplodedBE() : copyBE(); restartBackend() } }
1244 def listenerFullFE = newListener { parallel { install_FE(); copyFE() } }
1245 ActionListener listenerFE = newListener { parallel { updaterFE() } }
1246 ActionListener listenerBE = newListener { parallel { updaterBE() } }
1247 ActionListener exitListener = newListener {
1248 executor?.isShutdown() ?: executor?.shutdown()
1249 tray.remove(trayIcon);
1250 project.ext.set("isStopHealthCheck", true)
1251 println "Shutting down.. bye bye.."
1253 ActionListener stopBackendListener = newListener { stopBackend() }
1254 ActionListener startBEListener = newListener { parallel { startBackend() } }
1255 ActionListener killJavaListener = newListener { killJava() }
1257 ActionListener startAllListener = newListener { parallel { startAll() } }
1259 ActionListener startSecurityListener = newListener { startSecurity() }
1260 ActionListener stopSecurityListener = newListener { stopSecurity() }
1262 ActionListener listener5 = new ActionListener() {
1263 public void actionPerformed(ActionEvent e) {
1265 parallel { importNormative() }
1266 } catch (AWTException e1) {
1267 System.err.println(e1);
1272 ActionListener listener6 = new ActionListener() {
1273 public void actionPerformed(ActionEvent e) {
1275 parallel { healthPopup() }
1276 } catch (AWTException e1) {
1277 System.err.println(e1);
1282 ActionListener listener7 = new ActionListener() {
1283 public void actionPerformed(ActionEvent e) {
1285 logBE()//tasks.logger.execute()
1286 } catch (AWTException e1) {
1287 System.err.println(e1);
1291 ActionListener listener8 = new ActionListener() {
1292 public void actionPerformed(ActionEvent e) {
1294 toggleHealthPolling()//tasks.logger.execute()
1295 } catch (AWTException e1) {
1296 System.err.println(e1);
1300 ActionListener copyBeWarListener = new ActionListener() {
1301 public void actionPerformed(ActionEvent e) {
1303 parallel { copyBE() }//.execute()//tasks.logger.execute()
1304 } catch (AWTException e1) {
1305 System.err.println(e1);
1310 ActionListener startDBListener = new ActionListener() {
1311 public void actionPerformed(ActionEvent e) {
1315 }//tasks.logger.execute()
1316 } catch (AWTException e1) {
1317 System.err.println(e1);
1322 ActionListener stopDBListener = new ActionListener() {
1323 public void actionPerformed(ActionEvent e) {
1325 stopDB()//tasks.logger.execute()
1326 } catch (AWTException e1) {
1327 System.err.println(e1);
1332 ActionListener dbBackupListener = new ActionListener() {
1333 public void actionPerformed(ActionEvent e) {
1336 backupDB()//tasks.logger.execute()
1338 } catch (AWTException e1) {
1339 System.err.println(e1);
1344 ActionListener feStartListener = new ActionListener() {
1345 public void actionPerformed(ActionEvent e) {
1349 }//tasks.logger.execute()
1350 } catch (AWTException e1) {
1351 System.err.println(e1);
1356 ActionListener feStopListener = new ActionListener() {
1357 public void actionPerformed(ActionEvent e) {
1359 stopFE()//tasks.logger.execute()
1360 } catch (AWTException e1) {
1361 System.err.println(e1);
1366 ActionListener feCopyListener = new ActionListener() {
1367 public void actionPerformed(ActionEvent e) {
1370 copyFE() //.execute()//tasks.logger.execute()
1372 } catch (AWTException e1) {
1373 System.err.println(e1);
1379 //def listenerFullModules = newListener { parallel { installAllProject() } }
1380 //region -> Button<=Listener
1381 hotswapItem.addActionListener(listenerHotswap)
1382 updaterFeItem.addActionListener(listenerFE)
1383 updaterFullBeItem.addActionListener( listenerFullBE )
1384 updaterBeWithDependenciesItem.addActionListener( listenerBE )
1385 updaterFullFeItem.addActionListener( listenerFullFE )
1386 stopItem.addActionListener(stopBackendListener)
1387 startItem.addActionListener(startBEListener)
1388 copyBeWarItem.addActionListener(copyBeWarListener);
1389 startSecurityItem.addActionListener(startSecurityListener)
1390 stopSecurityItem.addActionListener(stopSecurityListener)
1391 killItem.addActionListener(killJavaListener)
1392 startAllItem.addActionListener(startAllListener)
1393 importItem.addActionListener(listener5)
1394 healthInfoItem.addActionListener(listener6)
1395 toggleHealthItem.addActionListener(listener8)
1396 logsItem.addActionListener(listener7)
1397 exitItem.addActionListener(exitListener)
1399 startDBItem.addActionListener( startDBListener )
1400 stopDBItem.addActionListener( stopDBListener )
1401 backupDBItem.addActionListener( dbBackupListener )
1402 copyFeWarItem.addActionListener( feCopyListener )
1403 startFEItem.addActionListener( feStartListener )
1404 stopFEItem.addActionListener( feStopListener )
1407 // set the TrayIcon properties
1410 // add the tray image
1414 } catch (AWTException e) {
1415 System.err.println(e);
1419 println "Java TrayIcon Option is not supported in your System, try enabling it. Bye Bye"
1425 long UPDATE_THRESHOLD = 3500
1428 knownHosts = allowAnyHosts
1430 while(!isStopHealthCheck) {
1431 if (!isHaltHealth.get()) { //if await or await is more then 60 second return health check
1433 session(remotes.vagrant) {
1435 def healthOutput = execute command[ALL][HEALTH]()
1436 if (healthOutput?.contains("Failed command .* with status 7") || healthOutput?.contains("Problem accessing /sdc2/rest/healthCheck"))
1437 updateTray(STATUS.DOWN)
1438 def statusCollecion = healthOutput?.findAll "\"healthCheckStatus\": \".*\""
1439 def upCount = statusCollecion?.count { it?.contains("UP") }
1440 def downCount = statusCollecion?.count { it?.contains("DOWN") }
1441 def uknownCount = (statusCollecion?.size() - upCount) - downCount
1442 println " UP -> $upCount | downCount=$downCount | uknownCount=$uknownCount "
1443 (uknownCount > 0 || (downCount > 0 && upCount > 0)) ? updateTray(STATUS.UNKNOWN) : ((upCount > 0) ? updateTray(STATUS.UP) : updateTray(STATUS.DOWN))
1445 } catch (Exception e) {
1446 updateTray(STATUS.DOWN)
1448 SCALAR = Math.min(SCALAR * 1.1, 5) //slow down on errors
1450 //green color effects
1451 if (lastStatus && lastStatus == STATUS.UP) {
1452 trayIcon.setImage(convert(Math.random() > 0.5 ? 'okImg1' : 'okImg2'))
1453 //randomly green change color
1456 Thread?.sleep((long) (UPDATE_THRESHOLD * SCALAR))
1460 updateTray(STATUS.UNAVAILABLE)
1468 session(remotes.vagrant) {
1469 def healthOutput = execute command[ALL][HEALTH]()
1470 JOptionPane.showMessageDialog(null,
1473 JOptionPane.INFORMATION_MESSAGE);
1478 project.ext.set("msg", { content -> """
1479 ************************************************************************************************
1480 ************************************************************************************************
1482 ************** ****************
1485 ************************************************************************************************
1486 ************************************************************************************************