-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/59440/
-----------------------------------------------------------

Review request for Ambari, Alejandro Fernandez, Jonathan Hurley, Richard Zang, 
and Yusaku Sako.


Bugs: AMBARI-20739
    https://issues.apache.org/jira/browse/AMBARI-20739


Repository: ambari


Description
-------

Although we can create the alert target of type ALERT_SCRIPT by web ui, we 
still need access to ambari.properties to add the new script and then restart 
ambari server to make this function take effect.
It is better specify the script directly in alert target rather than in 
ambari.properties.In this way,we also don't need to restart ambari server.

So now on web ui we will two ways to configure the script location for 
script-based alert dispatchers:
1.By script dispatch property (ambari.dispatch-property.script).This is already 
supported in previous ambari release.
Please see 
https://cwiki.apache.org/confluence/display/AMBARI/Creating+a+Script-based+Alert+Dispatcher+-+2.4.0

2.By script filename(ambari.dispatch-property.script.filename).
This new way will lookup the script by filename in script directory,default in 
/var/lib/ambari-server/resources/scripts.
We can change the directory in ambari.properties by 
ambari.dispatch-property.script.directory property.


Diffs
-----

  
ambari-server/src/main/java/org/apache/ambari/server/notifications/dispatchers/AlertScriptDispatcher.java
 d65a11d 
  
ambari-server/src/test/java/org/apache/ambari/server/notifications/dispatchers/AlertScriptDispatcherTest.java
 68e7d02 
  
ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js 
df15513 
  ambari-web/app/messages.js 0c15a19 
  ambari-web/app/templates/main/alerts/create_alert_notification.hbs 7ec5b1e 
  ambari-web/app/utils/validator.js c069724 
  
ambari-web/test/controllers/main/alerts/manage_alert_notifications_controller_test.js
 0d58afa 


Diff: https://reviews.apache.org/r/59440/diff/1/


Testing
-------

Unit Tests
1.cd ambari-web & mvn test
  21212 passing (32s)
  128 pending

2.cd ambari-server & mvn test
  Results :
  Failed tests: 
     ExportBlueprintRequestTest.testExport_noConfigs:138 expected:<3> but 
was:<4>
  Tests run: 4990, Failures: 1, Errors: 0, Skipped: 39
 

Test Cases

Case 1:
a.Write a shell script named foo.sh and put it in the directory 
/var/lib/ambari-server/resources/scripts,its content is as following:
<code>
#!/bin/bash
logFile=/var/log/ambari-server/log_script_filename.log
definitionName=$1
definitionLabel=$2
serviceName=$3
alertState=$4 
alertText=$5
alertTimestamp=$6
hostname=$7
echo received $# parameters:  $definitionName, $definitionLabel, $serviceName, 
$alertState ,$alertText ,$alertTimestamp, $hostname  >> $logFile
</code>
b.Create an alert target of type ALERT_SCRIPT on web ui and set Script Filename 
with foo.sh.
c.Stop or start any service , wait for a moment, we can see the log in 
/var/ambari-server/log_script_filename.log


Case 2:
a.Add 
ambari.dispatch-property.script.directory=/var/lib/ambari-server/resources/scripts/alerts
 to ambari.properties and move foo.sh to this directory.
b.Restart ambari-server and delete /var/ambari-server/log_script_filename.log
c.Stop or start any service, wait for a moment, we can see the log in 
/var/ambari-server/log_script_filename.log


Case 3:
a.Modify previous alert target on web ui and set Script Dispatch Property with  
com.mycompany.dispatch.shell.script
b.Write a shell script named foo2.sh and put it in directory 
/var/lib/ambari-server/resources/scripts too,its content is as following:
<code>
#!/bin/bash
logFile=/var/log/ambari-server/log_script_dispatch_property.log
definitionName=$1
definitionLabel=$2
serviceName=$3
alertState=$4 
alertText=$5
alertTimestamp=$6
hostname=$7
</code>
b.Add 
com.mycompany.dispatch.shell.script=/var/lib/ambari-server/resources/scripts/foo2.sh
 to ambari.properties.
c.Restart ambari-server and delete /var/ambari-server/log_script_filename.log
d.Stop or start any service,wait for a moment, we should see log in 
/var/ambari-server/log_script_filename.log and 
/var/log/ambari-server/log_script_dispatch_property.log is not exited.


Case 4:
a.Modify previous target and set Script Filename with empty
b.Delete /var/ambari-server/log_script_filename.log
c.Stop or start any service , wait for a moment, we should see log in 
/var/log/ambari-server/log_script_dispatch_property.log and 
/var/ambari-server/log_script_filename.log is not exited any more.


Thanks,

yao lei

Reply via email to