2 import java.util.concurrent.Callable
3 import java.util.concurrent.Executors
4 import java.util.concurrent.atomic.AtomicBoolean
6 import static Services.*
7 import static ServiceControl.*
8 import java.awt.AWTException
12 import java.awt.MenuItem
13 import java.awt.PopupMenu
14 import java.awt.SystemTray
15 import java.awt.TrayIcon
16 import java.awt.event.ActionEvent
17 import java.awt.event.ActionListener
18 import javax.swing.JOptionPane
19 import javax.imageio.ImageIO
23 version '1.01-SNAPSHOT'
25 apply plugin: 'groovy'
27 apply plugin: "org.hidetake.ssh"
28 apply plugin: 'java-gradle-plugin'
31 sourceCompatibility = 1.8
39 classpath 'org.codehaus.groovy:groovy-all:2.4.12'
40 classpath "org.hidetake:gradle-ssh-plugin:2.9.0"
48 CACHING , //elawsrticsearch
60 //fill YOUR_WINDOWS_USER_HOME
61 project.ext.set("NEW_VAG",Boolean.FALSE) //flags to use new vagrant configuration
62 project.ext.set("IS_HOTSWAP",Boolean.FALSE) //flags to use new vagrant configuration
63 project.ext.set("PROJECT_PATH", System.getenv("SDC")) //ex. 'C:\\GIT_WORK\\asdc\\sdc')
64 project.ext.set("VAGRANT_HOME", NEW_VAG ? System.getenv("NEW_VAG") : System.getenv("VAG")) //ex. 'C:\\GIT_WORK\\vagrant-asdc-all-in-one')
65 project.ext.set("USER_HOME", "${System.getenv("USERPROFILE")}\\.ssh")
66 project.ext.set("BE_REMOTE", NEW_VAG ? '/opt/app/jetty/base/be' : '/home/vagrant/catalog-be' )
67 project.ext.set("FE_REMOTE", NEW_VAG ? '/opt/app/jetty/base/fe' : '/home/vagrant/catalog-fe' )
68 project.ext.set("VAGRANT_USER", NEW_VAG ? 'm11981' : 'vagrant' )
69 project.ext.set("RSA_PRIVATE_KEY_PATH", NEW_VAG ? "$VAGRANT_HOME/id_rsa" : '' )
70 project.ext.set("VAGRANT_PASSWORD", NEW_VAG ? 'Aa123456' : 'vagrant' )
71 project.ext.set("X_FOLDER",'/xFolder' )
72 project.ext.set("BE_DEPENDENCIES", 'common-be,common-app-api,catalog-dao,catalog-model,security-utils' )
73 project.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
91 project.ext.set("warnImg",'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAAADvSURBVDhPY2RgYPgPxGQDiAGLXkB4UMD56DuD9YFUhj179oD5Li4uDEcdZjN8l+ME8+EgTgLTAJDm7zWKYPb/enUwzdh4E0xzttxHNQRoABOUCQYYmj+9QrCBACQHUoMM4AYga74ZDiRAmvnEwHwQGywGBOiGgA1A16wmJYjQDAJANkgMmyEosYBVMzIAuuTWs/cM6iuhfCCAGwDWrAHxKyFw68ZNuCE40wGygcga0AEkEEHRiIxxASzqUKKRHIAwAJgo4BgXwKIGxQUgf8MwOsAlh+EFUMDBMAxgE0MGoLwAignSMFQPzmgkDjAwAACSmn13nChk1QAAAABJRU5ErkJggg==')
92 project.ext.set("okImg1",'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAAAD4SURBVDhPY2RgYPgPxGQDiAGLXkB4UMD56DuD9YFUhj179oD5Li4uDEcdZjN8l+ME8+EgTgLTAJDm7zWKYLbSRh8wfc9/C5jmbLmPagjQACYoEwwwNLMxgzHMIJAcSA0ygBuArFm81gyi+ddfCAaywWJAgG4I2AB0zdxWkhCNMABkg8SwGYISC1g1IwOgS74ee87wsvkUVADJAJjpyIDbRAxMfz3zCkwjA5ghONMB2DVIBiDbigwggQiKRmSMC2BRhxKN5ACEAcBEAce4ABY1LFAaDLAFJAwgyyGHB4YXQAEHwzCATQwZgPICKCZIw1A9OKOROMDAAAA4gXvZorg7ZgAAAABJRU5ErkJggg==')
93 project.ext.set("okImg2" , 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAAADjSURBVDhPY2RgYPgPxGQDiAGLXkB4UMD56DuD9YFUhj179oD5Li4uDEcdZjN8l+ME8+EgTgLTAJDm7zWKYPbWZ7Jg2lvqMZjmbLmPagjQACYoEwywaQYBGBskB1KDDOAGIGuetFsUTCMDmBi6IWAD0DUra3OA2cgAJIbNEJRYwKUZGdy9+oMhz/U1lIdkADZnwwwDaUIHMENwpgNk16DbigwggQiKRmSMC2BRhxKN5ACEAcBEAce4ABY1LFAaDLAFJAwgyyGHB4YXQAEHwzCATQwZgPICKCZIw1A9OKOROMDAAAAZD3X55epfOAAAAABJRU5ErkJggg==')
94 project.ext.set("errorImg" , 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAAADlSURBVDhPY2RgYPgPxGQDiAGLXkB4UMD56DuD9YFUhj179oD5Li4uDEcdZjN8l+ME8+EgTgLTAJDm7zWKYPZbGRUwLfzkDpjmbLmPagjQACYoEwywaQYBGBskB1KDDOAGIGtexisCppEBTAzdELAB6Jrd+QXAbGQAEsNmCEos4NKMDHZ+/MAQ9fkNlIdkADZnwwwDaUIHyIaADMDAQAP/AwMPjEFsbGpAGGs6AEUPsnfgzsaiDiUayQUgF2A4jaAXoHpQXAByNgyjA1xyGF4A+RuGYQCbGDLA6gWCGKoHJSGRDhgYAL/hkunRq+joAAAAAElFTkSuQmCC')
95 project.ext.set("unavailableImg" , 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAABJ0AAASdAHeZh94AAAAB3RJTUUH4QwNDgEDrNoaqgAAAOhJREFUOMulkz8OgjAUhz8MQ7mBkwnnkBAH4mbCCdxcXLwAoxdwYXHjBCRupoMheg4TJ29QNhwshMofSfpLOry2v6/vta8OUGEhF4DsbUx6L8XytkNKCUAURTxWZ9TCM93buQb8mFXiI4E43gCQ5xeQPt7x2YG4fWa0OQwDhBANRCVdyGyKOQyDJhuV+HgvZQLGzABCiEGI036FPnNbZVlSFPfvnWg1gJpea72OjPh6lUZcQ5yhPkjTkxHv94fpfcB23t81PftmWMr9e+pQZjobd6zuobX2fViXAFCRvSv9GtOH9ji23/kDswRrCVqtQOAAAAAASUVORK5CYII=')
99 project.ext.set("trayIcon", null)
100 project.ext.set("lastStatus", null)
101 project.ext.set("isStopHealthCheck", false)
102 project.ext.set("isHaltHealth", new AtomicBoolean(false) )
103 project.ext.set("startedAwait", Long.MAX_VALUE)
104 project.ext.set("logFile", 'C:/ProgramData/all.log')
105 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
106 project.ext.set("pomChangesMap" , [:] )
107 project.ext.set("beConfigFilesToCopyMapping" , [ 'src/main/resources/config/*.yaml' : 'config/catalog-be/' ,
108 'src/main/resources/config/*.properties' : 'config/catalog-be/'] )
111 project.ext.set("toggleHealthString" , "Halt Health" )
113 project.ext.set("toggleHealthItemView" , null )
116 project.ext.set("IS_MVN_INSTALL",false)
117 project.ext.set("executor" , null )
118 project.ext.set("lockObj" , new Object() )
120 println "2. hello compile2"
123 /*def post(String host , String serviceName,String msg){
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();
133 if( postRC.equals(200)) {
134 println(post.getInputStream().getText());
138 def 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
145 def hash( List list ){
146 def map = list?.collectEntries { File file -> [(file?.absolutePath) : file?.text?.hashCode() ]}
152 long started = System.currentTimeMillis()
156 def changes = pomList?.findAll {
157 def File file = new File(it);
158 pomChangesMap[it] != file?.text?.hashCode()
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"
166 ****** POM changes detection finished after -> ${System.currentTimeMillis()- started}ms ******
171 //list pom with updated file hashes
173 long started = System.currentTimeMillis()
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 }
180 pomChangesMap = pomList.collectEntries { absolutePath ->[ ( absolutePath ) : new File(absolutePath)?.text?.hashCode() ] }
182 println """ [MasterD][Init] intializing POM detector
184 ********* POM listing finished after -> ${System.currentTimeMillis()- started}ms *********
190 task initialization(){
192 executor = Executors.newCachedThreadPool();
195 def parallel( closure ){
196 executor?.submit(new Callable<Object>(){
198 public Object call() {
204 /*class Preferences {
206 def String IsNewVagrant
207 def String IsRapidMode
211 def folder = new File(X_FOLDER);
212 folder?.exists() ?: folder?.mkdirs()
214 new File("${folder?.absolutePath}/$PREFERENCES_FILENAME")
219 //postStat(10000, "shay" , "report/index")
221 new File('catalog-be\\pom.xml') << "#hello"
227 def fetchFilesByExtention(remote, local , ext ){
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.*/ }
235 println "fetched files in ${System.currentTimeMillis() - started} ms"
239 def updateRemoteFile(String remote , String local){
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 }
248 def compareAndSwap(){
250 def newClasses = new File("$PROJECT_PATH\\catalog-be\\target\\classes")
251 def File jettyClasses ;
253 println "traversing.."
254 new File("build/hotswap").traverse { if (it?.directory && it?.name?.equals("classes")){
258 def jettyClassesList = []
259 jettyClasses?.traverse { jettyClassesList << it }
261 println "$jettyClasses"
262 //Sort compiled classes
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
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() )
280 new File("build/hotswap")?.deleteDir()
281 new File("build/hotswap")?.mkdirs()
283 knownHosts = allowAnyHosts
285 fetchFilesByExtention( "$BE_REMOTE/tmp/" , 'build/hotswap' , "class")
295 password = VAGRANT_PASSWORD
296 identity = NEW_VAG ? new File(RSA_PRIVATE_KEY_PATH) : null
307 backupDB() //and clean all
308 //restoreDB() //restore latest
313 //todo- conside updating from git
317 def importHeatTypes(){
325 // add conformence level
327 def createSchemaPreStep(){
330 def createSchemaPostStep(){
331 ////todo- impl create amdocs dox
334 createSchemaPreStep()
335 //todo- create schema
337 createSchemaPostStep()
343 knownHosts = allowAnyHosts
346 session(remotes.vagrant) {
347 execute "cqlsh -e 'DROP KEYSPACE titan;'"
348 println "[MasterD][DB_DROP]-> Dropped 'titan' KEYSPACE."
367 knownHosts = allowAnyHosts
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."
384 def copyExplodedBE() {
386 println "[MasterD][BackEnd] copying exploded war."
388 knownHosts = allowAnyHosts
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"
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"
400 println "[MasterD][BackEnd] Successfully copied exploded war in ${System.currentTimeMillis()-started}ms."
403 task copyExplodedBE(){
411 knownHosts = allowAnyHosts
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"
431 knownHosts = allowAnyHosts
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"
452 workingDir VAGRANT_HOME //vagrant path
453 println "*****************\nworking dir -> $VAGRANT_HOME"
454 commandLine "cmd","/c", "vagrant up"
457 println "[MasterD]--> please define windows enviroment variable VAG pointing to vagrant project"
469 println "[MasterD][FrontEnd] starting war copy."
471 knownHosts = allowAnyHosts
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"
480 session(remotes.vagrant) {
481 put from: file?.absolutePath , into: "$FE_REMOTE/webapps"
487 println "[MasterD][FrontEnd] Successfully copied war in ${System.currentTimeMillis()-started}ms."
498 println "[MasterD][BackEnd] starting war copy."
500 knownHosts = allowAnyHosts
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"
509 session(remotes.vagrant) {
510 put from: file?.absolutePath , into: "$BE_REMOTE/webapps"
515 println "[MasterD][BackEnd] SUCCESSFULY copied be war in ${System.currentTimeMillis()-started}ms."
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'
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'
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'
561 def compileDependencies(){
562 def cmd = IS_MVN_INSTALL ? 'install' : 'compile'
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'
569 task compileDependencies {
571 compileDependencies()
575 def cmd = IS_MVN_INSTALL ? 'install' : 'compile'
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'
588 //deprecated - use deployBE()
591 def started = System.currentTimeMillis();
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"
599 **** copying finished in -> ${System.currentTimeMillis() - started}ms ****
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"
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"
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"
635 def installAllProject(){
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'
642 task installAllProject {
650 println '[MasterD]--> Finished!!'
653 installAll.dependsOn { tasks.findAll { task -> task.name.startsWith('install_') } }
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'
672 workingDir "${PROJECT_PATH}"
673 commandLine 'cmd','/c', 'mvn clean install -pl catalog-ui,catalog-fe -am -Pcatalog -Dmaven.test.skip'
682 def 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"
688 println "[MasterD][Rapid]--> copying war"
689 copyBE() //use this if you want to deploy entire war //hotswap.execute()
691 println msg(" redeploy finished in -> ${System.currentTimeMillis() - started}ms ")
693 task updaterBERapid(){
699 def started = System.currentTimeMillis();
700 IS_MVN_INSTALL = pomChanges() ? true : false
701 println "[MasterD]--> compiling changes using maven"
702 compileDependencies()
704 println "[MasterD]--> copying war"
705 IS_HOTSWAP ? copyExplodedBE() : copyBE() //execute() //use this if you want to deploy entire war //hotswap.execute()
707 println msg("redeploy finished in -> ${System.currentTimeMillis() - started}ms ")
714 def copyBEConfiguration(){
717 knownHosts = allowAnyHosts
720 session(remotes.vagrant) {
721 println msg("Stopping BackEnd Server")
722 execute command[BACKEND][STOP]()
728 def started = System.currentTimeMillis();
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 ")
735 task updaterBEFull(){
740 def copyFEConfiguration(){
744 def started = System.currentTimeMillis();
745 println "[MasterD]--> compiling changes using maven"
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 ")
760 knownHosts = allowAnyHosts
763 session(remotes.vagrant) {
764 println msg("Stopping BackEnd Server")
765 execute command[BACKEND][STOP]()
779 knownHosts = allowAnyHosts
782 session(remotes.vagrant) {
783 println msg("[MasterD] starting backend sever")
785 execute command[BACKEND][START]()
789 println """[MasterD]-> finished !!
798 def restartBackend(){
801 knownHosts = allowAnyHosts
804 session(remotes.vagrant) {
805 println msg("[MasterD] restarting backend sever")
807 execute command[BACKEND][RESTART]()
811 println """[MasterD]-> finished !!
814 //todo- remove this if you want to auto-deploy on every file save
820 enum STATUS { UP, DOWN , UNKNOWN , UNAVAILABLE }
828 def execSafe( closure){
830 [0..4].forEach( {println "Critical ERROR : lock object is not initialized\n\nCritical ERROR : cannot run tasks\n"}() )
833 synchronized (lockObj){
834 boolean prev = isHaltHealth.get()
836 isHaltHealth.set(true)
838 } catch (Exception e) {
841 isHaltHealth.set(prev)
846 def fetchFiles( remote, local ){
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
854 //println "fetched files in ${System.currentTimeMillis() - started} ms"
865 session( remotes.vagrant ) {
866 println """ *-*-****************************-*-*
867 killing all java proccesses
868 *-*-****************************-*-*
870 res = execute command[ALL][KILL]()
873 println res?.toString()
877 def importNormative(){
880 session(remotes.vagrant) {
881 println """ *-*-************************************-*-*
883 *-*-************************************-*-*
885 execute "python -v $BE_REMOTE/scripts/import/tosca/importNormativeAll.py"
892 def startCassandra = """
899 until curl localhost:9200/_cluster/health;
905 # Create Elastic Mapping if not exist in ES
910 session(remotes.vagrant) {
911 println """ *-*-************************************-*-*
912 starting all SDC services(DB,BE,FE,Webseal)
913 *-*-************************************-*-*
916 execute command[DB][START]()
918 execute command[CACHING][START]()
921 execute startCassandra
922 //[0..4]?.forEach( Thread?.sleep(2000) )
925 execute command[BACKEND][START]()
926 execute command[FRONTEND][START]()
927 execute command[SECURITY][START]()
934 /*def clearLog(type: Delete){
936 delete 'C:/ProgramData/all.log'
937 followSymlinks = true
940 task clearLog(type: Delete){
942 delete 'C:/ProgramData/all.log'
943 followSymlinks = true
948 println "\n*** logging BE all.log ***\n"
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' )
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*'
965 String notepad = 'C:\\Program Files (x86)\\Notepad++\\notepad++.exe'
966 println "logging $logFile to notepad++ [$notepad]"
967 commandLine 'cmd','/c' , notepad ,logFile
971 println "cannot open logs!!!"
981 def toggleHealthPolling(){
982 isHaltHealth.set(!isHaltHealth.get())
984 //converts predefined icon to Image
985 def 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));
991 def refreshMenu(String imageName){
992 switch( imageName ) {
993 case 'unavailableImg' : toggleHealthString = "Resume Health"; break;
994 default : toggleHealthString = "Halt Health";
996 if (((MenuItem)toggleHealthItemView).getLabel() != toggleHealthString)
997 ((MenuItem)toggleHealthItemView).setLabel(toggleHealthString);
1000 println "[MasterD] Starting database.."
1003 knownHosts = allowAnyHosts
1006 session(remotes.vagrant) {
1007 execute command[DB][START]()
1020 knownHosts = allowAnyHosts
1023 session(remotes.vagrant) {
1024 execute command[DB][STOP]()
1037 knownHosts = allowAnyHosts
1040 session(remotes.vagrant) {
1041 execute command[FRONTEND][START]()
1054 knownHosts = allowAnyHosts
1057 session(remotes.vagrant) {
1058 execute command[FRONTEND][STOP]()
1069 def ActionListener newListener( closure ){
1070 ActionListener listener = new ActionListener() {
1071 public void actionPerformed(ActionEvent e) {
1074 } catch (AWTException e1) {
1075 System.err.println(e1);
1083 ext.updateTray = { STATUS status ->
1085 if (SystemTray.isSupported()) {
1086 // get the SystemTray instance
1087 SystemTray tray = SystemTray.getSystemTray();
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);
1097 // create a popup menu
1098 PopupMenu popup = new PopupMenu();
1099 // create menu item for the default action
1101 MenuItem hotswapItem = new MenuItem("===> WAR <===");
1102 hotswapItem.setFont(new Font("MONOSPACED" , Font.BOLD ,15f ))
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");
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){
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");
1126 deployMasterMenu.add(updaterFullBeItem);
1127 deployMasterMenu.add(updaterBeWithDependenciesItem);
1129 deployMasterMenu.addSeparator();
1130 deployMasterMenu.add(updaterFullFeItem);
1131 deployMasterMenu.add(updaterFeItem);
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);
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);
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);
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");
1170 toggleHealthItemView = toggleHealthItem;
1172 popup.add(hotswapItem);
1173 popup?.addSeparator();
1174 popup.add(deployMasterMenu);
1175 popup?.addSeparator();
1176 popup.add(backendMenu)
1177 popup.add(frontendMenu)
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);
1191 // construct a TrayIcon
1192 trayIcon = new TrayIcon(image, "HealthTray", popup);
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.."
1207 ActionListener stopBackendListener = newListener { stopBackend() }
1208 ActionListener startBEListener = newListener { parallel { startBackend() } }
1209 ActionListener killJavaListener = newListener { killJava() }
1211 ActionListener startAllListener = newListener { parallel { startAll() } }
1213 ActionListener listener5 = new ActionListener() {
1214 public void actionPerformed(ActionEvent e) {
1216 parallel { importNormative() }
1217 } catch (AWTException e1) {
1218 System.err.println(e1);
1223 ActionListener listener6 = new ActionListener() {
1224 public void actionPerformed(ActionEvent e) {
1226 parallel { healthPopup() }
1227 } catch (AWTException e1) {
1228 System.err.println(e1);
1233 ActionListener listener7 = new ActionListener() {
1234 public void actionPerformed(ActionEvent e) {
1236 logBE()//tasks.logger.execute()
1237 } catch (AWTException e1) {
1238 System.err.println(e1);
1242 ActionListener listener8 = new ActionListener() {
1243 public void actionPerformed(ActionEvent e) {
1245 toggleHealthPolling()//tasks.logger.execute()
1246 } catch (AWTException e1) {
1247 System.err.println(e1);
1251 ActionListener copyBeWarListener = new ActionListener() {
1252 public void actionPerformed(ActionEvent e) {
1254 parallel { copyBE() }//.execute()//tasks.logger.execute()
1255 } catch (AWTException e1) {
1256 System.err.println(e1);
1261 ActionListener startDBListener = new ActionListener() {
1262 public void actionPerformed(ActionEvent e) {
1266 }//tasks.logger.execute()
1267 } catch (AWTException e1) {
1268 System.err.println(e1);
1273 ActionListener stopDBListener = new ActionListener() {
1274 public void actionPerformed(ActionEvent e) {
1276 stopDB()//tasks.logger.execute()
1277 } catch (AWTException e1) {
1278 System.err.println(e1);
1283 ActionListener dbBackupListener = new ActionListener() {
1284 public void actionPerformed(ActionEvent e) {
1287 backupDB()//tasks.logger.execute()
1289 } catch (AWTException e1) {
1290 System.err.println(e1);
1295 ActionListener feStartListener = new ActionListener() {
1296 public void actionPerformed(ActionEvent e) {
1300 }//tasks.logger.execute()
1301 } catch (AWTException e1) {
1302 System.err.println(e1);
1307 ActionListener feStopListener = new ActionListener() {
1308 public void actionPerformed(ActionEvent e) {
1310 stopFE()//tasks.logger.execute()
1311 } catch (AWTException e1) {
1312 System.err.println(e1);
1317 ActionListener feCopyListener = new ActionListener() {
1318 public void actionPerformed(ActionEvent e) {
1321 copyFE() //.execute()//tasks.logger.execute()
1323 } catch (AWTException e1) {
1324 System.err.println(e1);
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)
1348 startDBItem.addActionListener( startDBListener )
1349 stopDBItem.addActionListener( stopDBListener )
1350 backupDBItem.addActionListener( dbBackupListener )
1351 copyFeWarItem.addActionListener( feCopyListener )
1352 startFEItem.addActionListener( feStartListener )
1353 stopFEItem.addActionListener( feStopListener )
1356 // set the TrayIcon properties
1359 // add the tray image
1363 } catch (AWTException e) {
1364 System.err.println(e);
1368 println "Java TrayIcon Option is not supported in your System, try enabling it. Bye Bye"
1374 long UPDATE_THRESHOLD = 3500
1377 knownHosts = allowAnyHosts
1379 while(!isStopHealthCheck) {
1380 if (!isHaltHealth.get()) { //if await or await is more then 60 second return health check
1382 session(remotes.vagrant) {
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))
1394 } catch (Exception e) {
1395 updateTray(STATUS.DOWN)
1397 SCALAR = Math.min(SCALAR * 1.1, 5) //slow down on errors
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
1405 Thread?.sleep((long) (UPDATE_THRESHOLD * SCALAR))
1409 updateTray(STATUS.UNAVAILABLE)
1417 session(remotes.vagrant) {
1418 def healthOutput = execute command[ALL][HEALTH]()
1419 JOptionPane.showMessageDialog(null,
1422 JOptionPane.INFORMATION_MESSAGE);
1427 project.ext.set("msg", { content -> """
1428 ************************************************************************************************
1429 ************************************************************************************************
1431 ************** ****************
1434 ************************************************************************************************
1435 ************************************************************************************************