Apache Oozie具有oozie.wf.workflow.notification.url
属性,用于通知自定义端点有关作业状态更新的信息。
<property>
<name>oozie.wf.workflow.notification.url</name>
<value>http://SERVER:8080/endpoint/oozieUpdate?jobId=$jobId%26status=$status</value>
</property>
我有一个用例,其中端点必须验证传入的请求,我找不到允许我配置Oozie的解决方案,以便它将验证头发送到此通知URL(例如Basic Auth)。有没有办法做到这一点?
答案 0 :(得分:1)
我怀疑你可以在oozie的当前状态下使用oozie.wf.workflow.notification.url
来做到这一点。我检查了oozie source code并发现了这个:
org.apache.oozie.client.OozieClient(以常量读取的属性):
public static final String WORKFLOW_NOTIFICATION_URL = "oozie.wf.workflow.notification.url";
org.apache.oozie.command.wf.WorkflowNotificationXCommand(常量用于形成proxyConf变量):
public WorkflowNotificationXCommand(WorkflowJobBean workflow) {
super("job.notification", "job.notification", 0);
ParamChecker.notNull(workflow, "workflow");
jobId = workflow.getId();
url = workflow.getWorkflowInstance().getConf().get(OozieClient.WORKFLOW_NOTIFICATION_URL);
if (url != null) {
url = url.replaceAll(JOB_ID_PATTERN, workflow.getId());
url = url.replaceAll(STATUS_PATTERN, workflow.getStatus().toString());
proxyConf = workflow.getWorkflowInstance().getConf()
.get(OozieClient.WORKFLOW_NOTIFICATION_PROXY, ConfigurationService.get(NOTIFICATION_PROXY_KEY));
LOG.debug("Proxy :" + proxyConf);
}
}
org.apache.oozie.command.NotificationXCommand(http调用本身在使用proxyConf变量的WorkflowNotificationXCommand的超类中):
protected void sendNotification() {
if (url != null) {
Proxy proxy = getProxy(proxyConf);
try {
URL url = new URL(this.url);
HttpURLConnection urlConn = (HttpURLConnection) url.openConnection(proxy);
urlConn.setConnectTimeout(getTimeOut());
urlConn.setReadTimeout(getTimeOut());
if (urlConn.getResponseCode() != HttpURLConnection.HTTP_OK) {
handleRetry();
}
}
catch (IOException ex) {
handleRetry();
}
}
else {
LOG.info("No Notification URL is defined. Therefore nothing to notify for job " + jobId);
}
}
正如您所见,使用httpURLConnection.setRequestProperty(,)
未设置任何标头。
您可以使用自定义java操作进行解决方法,但您可以使用任何标题从中进行http调用。
答案 1 :(得分:1)
作为一种解决方法,我为通知网址创建了一个替换变量。
<property>
<name>oozie.wf.workflow.notification.url</name>
<value>_NOTIFICATION_URL_</value>
</property>
然后,每次运行作业时,我都会在URL中包含一个不同的密钥。
confXml.replaceAll("_NOTIFICATION_URL_", server + "/" + getRandomSecret());
在这种情况下,信任锚是HTTPS。当我收到来自作业的通知时,我可以通过比较密钥来确保它不是来自攻击者。