helper.rb 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #
  2. # Cookbook Name:: fmw_domain
  3. # Library:: helper
  4. #
  5. # Copyright 2015 Oracle. All Rights Reserved
  6. #
  7. module DomainHelper
  8. def self.listening?(command, port, column)
  9. cmd = Puppet::Util::Execution.execute command
  10. Puppet.info cmd
  11. cmd.each_line.select do |l|
  12. l.split[column] =~ /#{port}/
  13. end.any?
  14. end
  15. def self.wlst_execute(version, os_user, script_file, weblogic_home_dir, weblogic_password, repository_password)
  16. if version >= '12.2.1'
  17. wlst_script_dir = "#{weblogic_home_dir}/../oracle_common/common/bin"
  18. else
  19. wlst_script_dir = "#{weblogic_home_dir}/common/bin"
  20. end
  21. command = "export CONFIG_JVM_ARGS=-Djava.security.egd=file:/dev/./urandom;#{wlst_script_dir}/wlst.sh -skipWLSModuleScanning #{script_file} #{weblogic_password} #{repository_password}"
  22. Puppet.debug "fmw_domain_wlst #{command}"
  23. output = Puppet::Util::Execution.execute "su - #{os_user} -c '#{command}'", :failonfail => true
  24. Puppet.info "fmw_domain_wlst result: #{output}"
  25. end
  26. def self.wlst_execute_windows(version, script_file, weblogic_home_dir, weblogic_password, repository_password)
  27. if version >= '12.2.1'
  28. wlst_script_dir = "#{weblogic_home_dir}\\..\\oracle_common\\common\\bin"
  29. else
  30. wlst_script_dir = "#{weblogic_home_dir}\\common\\bin"
  31. end
  32. command = "#{wlst_script_dir}\\wlst.cmd -skipWLSModuleScanning #{script_file} #{weblogic_password} #{repository_password}"
  33. Puppet.debug "fmw_domain_wlst #{command}"
  34. output = Puppet::Util::Execution.execute command, :failonfail => true
  35. Puppet.info "fmw_domain_wlst result: #{output}"
  36. end
  37. def self.server_status(os_user, server_name, weblogic_home_dir, weblogic_user, weblogic_password, nodemanager_listen_address, nodemanager_port, domain_name, domain_dir)
  38. command = "export CONFIG_JVM_ARGS=-Djava.security.egd=file:/dev/./urandom;#{weblogic_home_dir}/common/bin/wlst.sh -skipWLSModuleScanning <<-EOF
  39. nmConnect(\"#{weblogic_user}\",\"#{weblogic_password}\",\"#{nodemanager_listen_address}\",#{nodemanager_port},\"#{domain_name}\",\"#{domain_dir}\")
  40. nmServerStatus(\"#{server_name}\")
  41. nmDisconnect()
  42. EOF"
  43. Puppet.debug command
  44. output = Puppet::Util::Execution.execute "su - #{os_user} -c '#{command}'", :failonfail => true
  45. end
  46. def self.server_status_windows(server_name, weblogic_home_dir, weblogic_user, weblogic_password, nodemanager_listen_address, nodemanager_port, domain_name, domain_dir)
  47. script = 'wlstScript'
  48. content = "nmConnect(\"#{weblogic_user}\",\"#{weblogic_password}\",\"#{nodemanager_listen_address}\",#{nodemanager_port},\"#{domain_name}\",\"#{domain_dir}\")
  49. nmServerStatus(\"#{server_name}\")
  50. nmDisconnect()
  51. "
  52. tmp_file = Tempfile.new([script, '.py'])
  53. tmp_file.write(content)
  54. tmp_file.close
  55. Puppet.debug content
  56. command = "#{weblogic_home_dir}\\common\\bin\\wlst.cmd -skipWLSModuleScanning #{tmp_file.path}"
  57. output = Puppet::Util::Execution.execute command, :failonfail => true
  58. end
  59. def self.server_control(os_user, server_name, weblogic_home_dir, weblogic_user, weblogic_password, nodemanager_listen_address, nodemanager_port, domain_name, domain_dir, action_command, check_command)
  60. command = "export CONFIG_JVM_ARGS=-Djava.security.egd=file:/dev/./urandom;#{weblogic_home_dir}/common/bin/wlst.sh -skipWLSModuleScanning <<-EOF
  61. nmConnect(\"#{weblogic_user}\",\"#{weblogic_password}\",\"#{nodemanager_listen_address}\",#{nodemanager_port},\"#{domain_name}\",\"#{domain_dir}\")
  62. #{action_command}
  63. nmDisconnect()
  64. EOF"
  65. Puppet.debug command
  66. result = false
  67. output = Puppet::Util::Execution.execute "su - #{os_user} -c '#{command}'", :failonfail => true
  68. Puppet.info output
  69. output.each_line do |line|
  70. unless line.nil?
  71. if line.include? check_command
  72. return true
  73. end
  74. end
  75. end
  76. fail if result == false
  77. end
  78. def self.server_control_windows(server_name, weblogic_home_dir, weblogic_user, weblogic_password, nodemanager_listen_address, nodemanager_port, domain_name, domain_dir, action_command, check_command)
  79. script = 'wlstScript'
  80. content = "nmConnect(\"#{weblogic_user}\",\"#{weblogic_password}\",\"#{nodemanager_listen_address}\",#{nodemanager_port},\"#{domain_name}\",\"#{domain_dir}\")
  81. #{action_command}
  82. nmDisconnect()
  83. "
  84. tmp_file = Tempfile.new([script, '.py'])
  85. tmp_file.write(content)
  86. tmp_file.close
  87. command = "#{weblogic_home_dir}\\common\\bin\\wlst.cmd -skipWLSModuleScanning #{tmp_file.path}"
  88. result = false
  89. output = Puppet::Util::Execution.execute command, :failonfail => true
  90. output.each_line do |line|
  91. unless line.nil?
  92. if line.include? check_command
  93. return true
  94. end
  95. end
  96. end
  97. fail if result == false
  98. end
  99. end