wuxiaofei
4 years ago
259 changed files with 5254 additions and 3546 deletions
@ -1,51 +0,0 @@ |
|||||||
# |
|
||||||
# Licensed to the Apache Software Foundation (ASF) under one or more |
|
||||||
# contributor license agreements. See the NOTICE file distributed with |
|
||||||
# this work for additional information regarding copyright ownership. |
|
||||||
# The ASF licenses this file to You under the Apache License, Version 2.0 |
|
||||||
# (the "License"); you may not use this file except in compliance with |
|
||||||
# the License. You may obtain a copy of the License at |
|
||||||
# |
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0 |
|
||||||
# |
|
||||||
# Unless required by applicable law or agreed to in writing, software |
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS, |
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
||||||
# See the License for the specific language governing permissions and |
|
||||||
# limitations under the License. |
|
||||||
# |
|
||||||
|
|
||||||
server { |
|
||||||
listen 8888; |
|
||||||
server_name localhost; |
|
||||||
#charset koi8-r; |
|
||||||
#access_log /var/log/nginx/host.access.log main; |
|
||||||
location / { |
|
||||||
root /opt/dolphinscheduler/ui; |
|
||||||
index index.html index.html; |
|
||||||
} |
|
||||||
location /dolphinscheduler/ui{ |
|
||||||
alias /opt/dolphinscheduler/ui; |
|
||||||
} |
|
||||||
location /dolphinscheduler { |
|
||||||
proxy_pass http://FRONTEND_API_SERVER_HOST:FRONTEND_API_SERVER_PORT; |
|
||||||
proxy_set_header Host $host; |
|
||||||
proxy_set_header X-Real-IP $remote_addr; |
|
||||||
proxy_set_header x_real_ipP $remote_addr; |
|
||||||
proxy_set_header remote_addr $remote_addr; |
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
|
||||||
proxy_http_version 1.1; |
|
||||||
proxy_connect_timeout 300s; |
|
||||||
proxy_read_timeout 300s; |
|
||||||
proxy_send_timeout 300s; |
|
||||||
proxy_set_header Upgrade $http_upgrade; |
|
||||||
proxy_set_header Connection "upgrade"; |
|
||||||
} |
|
||||||
#error_page 404 /404.html; |
|
||||||
# redirect server error pages to the static page /50x.html |
|
||||||
# |
|
||||||
error_page 500 502 503 504 /50x.html; |
|
||||||
location = /50x.html { |
|
||||||
root /usr/share/nginx/html; |
|
||||||
} |
|
||||||
} |
|
@ -1,47 +0,0 @@ |
|||||||
# |
|
||||||
# Licensed to the Apache Software Foundation (ASF) under one or more |
|
||||||
# contributor license agreements. See the NOTICE file distributed with |
|
||||||
# this work for additional information regarding copyright ownership. |
|
||||||
# The ASF licenses this file to You under the Apache License, Version 2.0 |
|
||||||
# (the "License"); you may not use this file except in compliance with |
|
||||||
# the License. You may obtain a copy of the License at |
|
||||||
# |
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0 |
|
||||||
# |
|
||||||
# Unless required by applicable law or agreed to in writing, software |
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS, |
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
||||||
# See the License for the specific language governing permissions and |
|
||||||
# limitations under the License. |
|
||||||
# |
|
||||||
|
|
||||||
# The number of milliseconds of each tick |
|
||||||
tickTime=2000 |
|
||||||
# The number of ticks that the initial |
|
||||||
# synchronization phase can take |
|
||||||
initLimit=10 |
|
||||||
# The number of ticks that can pass between |
|
||||||
# sending a request and getting an acknowledgement |
|
||||||
syncLimit=5 |
|
||||||
# the directory where the snapshot is stored. |
|
||||||
# do not use /tmp for storage, /tmp here is just |
|
||||||
# example sakes. |
|
||||||
dataDir=/tmp/zookeeper |
|
||||||
# the port at which the clients will connect |
|
||||||
clientPort=2181 |
|
||||||
# the maximum number of client connections. |
|
||||||
# increase this if you need to handle more clients |
|
||||||
#maxClientCnxns=60 |
|
||||||
# |
|
||||||
# Be sure to read the maintenance section of the |
|
||||||
# administrator guide before turning on autopurge. |
|
||||||
# |
|
||||||
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance |
|
||||||
# |
|
||||||
# The number of snapshots to retain in dataDir |
|
||||||
#autopurge.snapRetainCount=3 |
|
||||||
# Purge task interval in hours |
|
||||||
# Set to "0" to disable auto purge feature |
|
||||||
#autopurge.purgeInterval=1 |
|
||||||
#Four Letter Words commands:stat,ruok,conf,isro |
|
||||||
4lw.commands.whitelist=* |
|
@ -1,25 +0,0 @@ |
|||||||
# |
|
||||||
# Licensed to the Apache Software Foundation (ASF) under one or more |
|
||||||
# contributor license agreements. See the NOTICE file distributed with |
|
||||||
# this work for additional information regarding copyright ownership. |
|
||||||
# The ASF licenses this file to You under the Apache License, Version 2.0 |
|
||||||
# (the "License"); you may not use this file except in compliance with |
|
||||||
# the License. You may obtain a copy of the License at |
|
||||||
# |
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0 |
|
||||||
# |
|
||||||
# Unless required by applicable law or agreed to in writing, software |
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS, |
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
||||||
# See the License for the specific language governing permissions and |
|
||||||
# limitations under the License. |
|
||||||
# |
|
||||||
dependencies: |
|
||||||
- name: postgresql |
|
||||||
version: 8.x.x |
|
||||||
repository: https://charts.bitnami.com/bitnami |
|
||||||
condition: postgresql.enabled |
|
||||||
- name: zookeeper |
|
||||||
version: 5.x.x |
|
||||||
repository: https://charts.bitnami.com/bitnami |
|
||||||
condition: redis.enabled |
|
@ -1,25 +0,0 @@ |
|||||||
# |
|
||||||
# Licensed to the Apache Software Foundation (ASF) under one or more |
|
||||||
# contributor license agreements. See the NOTICE file distributed with |
|
||||||
# this work for additional information regarding copyright ownership. |
|
||||||
# The ASF licenses this file to You under the Apache License, Version 2.0 |
|
||||||
# (the "License"); you may not use this file except in compliance with |
|
||||||
# the License. You may obtain a copy of the License at |
|
||||||
# |
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0 |
|
||||||
# |
|
||||||
# Unless required by applicable law or agreed to in writing, software |
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS, |
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
||||||
# See the License for the specific language governing permissions and |
|
||||||
# limitations under the License. |
|
||||||
# |
|
||||||
dependencies: |
|
||||||
- name: postgresql |
|
||||||
version: 8.x.x |
|
||||||
repository: https://charts.bitnami.com/bitnami |
|
||||||
condition: postgresql.enabled |
|
||||||
- name: zookeeper |
|
||||||
version: 5.x.x |
|
||||||
repository: https://charts.bitnami.com/bitnami |
|
||||||
condition: redis.enabled |
|
@ -1,25 +0,0 @@ |
|||||||
# |
|
||||||
# Licensed to the Apache Software Foundation (ASF) under one or more |
|
||||||
# contributor license agreements. See the NOTICE file distributed with |
|
||||||
# this work for additional information regarding copyright ownership. |
|
||||||
# The ASF licenses this file to You under the Apache License, Version 2.0 |
|
||||||
# (the "License"); you may not use this file except in compliance with |
|
||||||
# the License. You may obtain a copy of the License at |
|
||||||
# |
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0 |
|
||||||
# |
|
||||||
# Unless required by applicable law or agreed to in writing, software |
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS, |
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
||||||
# See the License for the specific language governing permissions and |
|
||||||
# limitations under the License. |
|
||||||
# |
|
||||||
dependencies: |
|
||||||
- name: postgresql |
|
||||||
version: 8.x.x |
|
||||||
repository: https://charts.bitnami.com/bitnami |
|
||||||
condition: postgresql.enabled |
|
||||||
- name: zookeeper |
|
||||||
version: 5.x.x |
|
||||||
repository: https://charts.bitnami.com/bitnami |
|
||||||
condition: redis.enabled |
|
@ -1,25 +0,0 @@ |
|||||||
# |
|
||||||
# Licensed to the Apache Software Foundation (ASF) under one or more |
|
||||||
# contributor license agreements. See the NOTICE file distributed with |
|
||||||
# this work for additional information regarding copyright ownership. |
|
||||||
# The ASF licenses this file to You under the Apache License, Version 2.0 |
|
||||||
# (the "License"); you may not use this file except in compliance with |
|
||||||
# the License. You may obtain a copy of the License at |
|
||||||
# |
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0 |
|
||||||
# |
|
||||||
# Unless required by applicable law or agreed to in writing, software |
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS, |
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
||||||
# See the License for the specific language governing permissions and |
|
||||||
# limitations under the License. |
|
||||||
# |
|
||||||
dependencies: |
|
||||||
- name: postgresql |
|
||||||
version: 8.x.x |
|
||||||
repository: https://charts.bitnami.com/bitnami |
|
||||||
condition: postgresql.enabled |
|
||||||
- name: zookeeper |
|
||||||
version: 5.x.x |
|
||||||
repository: https://charts.bitnami.com/bitnami |
|
||||||
condition: redis.enabled |
|
@ -1,25 +0,0 @@ |
|||||||
# |
|
||||||
# Licensed to the Apache Software Foundation (ASF) under one or more |
|
||||||
# contributor license agreements. See the NOTICE file distributed with |
|
||||||
# this work for additional information regarding copyright ownership. |
|
||||||
# The ASF licenses this file to You under the Apache License, Version 2.0 |
|
||||||
# (the "License"); you may not use this file except in compliance with |
|
||||||
# the License. You may obtain a copy of the License at |
|
||||||
# |
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0 |
|
||||||
# |
|
||||||
# Unless required by applicable law or agreed to in writing, software |
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS, |
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
||||||
# See the License for the specific language governing permissions and |
|
||||||
# limitations under the License. |
|
||||||
# |
|
||||||
dependencies: |
|
||||||
- name: postgresql |
|
||||||
version: 8.x.x |
|
||||||
repository: https://charts.bitnami.com/bitnami |
|
||||||
condition: postgresql.enabled |
|
||||||
- name: zookeeper |
|
||||||
version: 5.x.x |
|
||||||
repository: https://charts.bitnami.com/bitnami |
|
||||||
condition: redis.enabled |
|
@ -1,119 +0,0 @@ |
|||||||
# |
|
||||||
# Licensed to the Apache Software Foundation (ASF) under one or more |
|
||||||
# contributor license agreements. See the NOTICE file distributed with |
|
||||||
# this work for additional information regarding copyright ownership. |
|
||||||
# The ASF licenses this file to You under the Apache License, Version 2.0 |
|
||||||
# (the "License"); you may not use this file except in compliance with |
|
||||||
# the License. You may obtain a copy of the License at |
|
||||||
# |
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0 |
|
||||||
# |
|
||||||
# Unless required by applicable law or agreed to in writing, software |
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS, |
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
||||||
# See the License for the specific language governing permissions and |
|
||||||
# limitations under the License. |
|
||||||
# |
|
||||||
apiVersion: apps/v1 |
|
||||||
kind: Deployment |
|
||||||
metadata: |
|
||||||
name: {{ include "dolphinscheduler.fullname" . }}-frontend |
|
||||||
labels: |
|
||||||
app.kubernetes.io/name: {{ include "dolphinscheduler.fullname" . }}-frontend |
|
||||||
app.kubernetes.io/instance: {{ .Release.Name }} |
|
||||||
app.kubernetes.io/managed-by: {{ .Release.Service }} |
|
||||||
app.kubernetes.io/component: frontend |
|
||||||
spec: |
|
||||||
replicas: {{ .Values.frontend.replicas }} |
|
||||||
selector: |
|
||||||
matchLabels: |
|
||||||
app.kubernetes.io/name: {{ include "dolphinscheduler.fullname" . }}-frontend |
|
||||||
app.kubernetes.io/instance: {{ .Release.Name }} |
|
||||||
app.kubernetes.io/managed-by: {{ .Release.Service }} |
|
||||||
app.kubernetes.io/component: frontend |
|
||||||
strategy: |
|
||||||
type: {{ .Values.frontend.strategy.type | quote }} |
|
||||||
rollingUpdate: |
|
||||||
maxSurge: {{ .Values.frontend.strategy.rollingUpdate.maxSurge | quote }} |
|
||||||
maxUnavailable: {{ .Values.frontend.strategy.rollingUpdate.maxUnavailable | quote }} |
|
||||||
template: |
|
||||||
metadata: |
|
||||||
labels: |
|
||||||
app.kubernetes.io/name: {{ include "dolphinscheduler.fullname" . }}-frontend |
|
||||||
app.kubernetes.io/instance: {{ .Release.Name }} |
|
||||||
app.kubernetes.io/managed-by: {{ .Release.Service }} |
|
||||||
app.kubernetes.io/component: frontend |
|
||||||
{{- if .Values.alert.annotations }} |
|
||||||
annotations: |
|
||||||
{{- toYaml .Values.alert.annotations | nindent 8 }} |
|
||||||
{{- end }} |
|
||||||
spec: |
|
||||||
{{- if .Values.frontend.affinity }} |
|
||||||
affinity: {{- toYaml .Values.frontend.affinity | nindent 8 }} |
|
||||||
{{- end }} |
|
||||||
{{- if .Values.frontend.nodeSelector }} |
|
||||||
nodeSelector: {{- toYaml .Values.frontend.nodeSelector | nindent 8 }} |
|
||||||
{{- end }} |
|
||||||
{{- if .Values.frontend.tolerations }} |
|
||||||
tolerations: {{- toYaml . | nindent 8 }} |
|
||||||
{{- end }} |
|
||||||
{{- if .Values.image.pullSecrets }} |
|
||||||
imagePullSecrets: |
|
||||||
- name: {{ include "dolphinscheduler.image.pullSecrets" . }} |
|
||||||
{{- end }} |
|
||||||
containers: |
|
||||||
- name: {{ include "dolphinscheduler.fullname" . }}-frontend |
|
||||||
image: {{ include "dolphinscheduler.image.repository" . | quote }} |
|
||||||
args: |
|
||||||
- "frontend" |
|
||||||
ports: |
|
||||||
- containerPort: 8888 |
|
||||||
name: tcp-port |
|
||||||
imagePullPolicy: {{ .Values.image.pullPolicy }} |
|
||||||
env: |
|
||||||
- name: TZ |
|
||||||
value: {{ .Values.timezone }} |
|
||||||
- name: FRONTEND_API_SERVER_HOST |
|
||||||
value: '{{ include "dolphinscheduler.fullname" . }}-api' |
|
||||||
- name: FRONTEND_API_SERVER_PORT |
|
||||||
value: "12345" |
|
||||||
{{- if .Values.frontend.resources }} |
|
||||||
resources: |
|
||||||
limits: |
|
||||||
memory: {{ .Values.frontend.resources.limits.memory | quote }} |
|
||||||
cpu: {{ .Values.frontend.resources.limits.cpu | quote }} |
|
||||||
requests: |
|
||||||
memory: {{ .Values.frontend.resources.requests.memory | quote }} |
|
||||||
cpu: {{ .Values.frontend.resources.requests.cpu | quote }} |
|
||||||
{{- end }} |
|
||||||
{{- if .Values.frontend.livenessProbe.enabled }} |
|
||||||
livenessProbe: |
|
||||||
tcpSocket: |
|
||||||
port: 8888 |
|
||||||
initialDelaySeconds: {{ .Values.frontend.livenessProbe.initialDelaySeconds }} |
|
||||||
periodSeconds: {{ .Values.frontend.livenessProbe.periodSeconds }} |
|
||||||
timeoutSeconds: {{ .Values.frontend.livenessProbe.timeoutSeconds }} |
|
||||||
successThreshold: {{ .Values.frontend.livenessProbe.successThreshold }} |
|
||||||
failureThreshold: {{ .Values.frontend.livenessProbe.failureThreshold }} |
|
||||||
{{- end }} |
|
||||||
{{- if .Values.frontend.readinessProbe.enabled }} |
|
||||||
readinessProbe: |
|
||||||
tcpSocket: |
|
||||||
port: 8888 |
|
||||||
initialDelaySeconds: {{ .Values.frontend.readinessProbe.initialDelaySeconds }} |
|
||||||
periodSeconds: {{ .Values.frontend.readinessProbe.periodSeconds }} |
|
||||||
timeoutSeconds: {{ .Values.frontend.readinessProbe.timeoutSeconds }} |
|
||||||
successThreshold: {{ .Values.frontend.readinessProbe.successThreshold }} |
|
||||||
failureThreshold: {{ .Values.frontend.readinessProbe.failureThreshold }} |
|
||||||
{{- end }} |
|
||||||
volumeMounts: |
|
||||||
- mountPath: "/var/log/nginx" |
|
||||||
name: {{ include "dolphinscheduler.fullname" . }}-frontend |
|
||||||
volumes: |
|
||||||
- name: {{ include "dolphinscheduler.fullname" . }}-frontend |
|
||||||
{{- if .Values.frontend.persistentVolumeClaim.enabled }} |
|
||||||
persistentVolumeClaim: |
|
||||||
claimName: {{ include "dolphinscheduler.fullname" . }}-frontend |
|
||||||
{{- else }} |
|
||||||
emptyDir: {} |
|
||||||
{{- end }} |
|
@ -0,0 +1,82 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<!-- |
||||||
|
~ Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
~ contributor license agreements. See the NOTICE file distributed with |
||||||
|
~ this work for additional information regarding copyright ownership. |
||||||
|
~ The ASF licenses this file to You under the Apache License, Version 2.0 |
||||||
|
~ (the "License"); you may not use this file except in compliance with |
||||||
|
~ the License. You may obtain a copy of the License at |
||||||
|
~ |
||||||
|
~ http://www.apache.org/licenses/LICENSE-2.0 |
||||||
|
~ |
||||||
|
~ Unless required by applicable law or agreed to in writing, software |
||||||
|
~ distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
~ See the License for the specific language governing permissions and |
||||||
|
~ limitations under the License. |
||||||
|
--> |
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||||
|
<parent> |
||||||
|
<artifactId>dolphinscheduler-alert-plugin</artifactId> |
||||||
|
<groupId>org.apache.dolphinscheduler</groupId> |
||||||
|
<version>1.3.4-SNAPSHOT</version> |
||||||
|
</parent> |
||||||
|
<modelVersion>4.0.0</modelVersion> |
||||||
|
|
||||||
|
<groupId>org.apache.dolphinscheduler</groupId> |
||||||
|
<artifactId>dolphinscheduler-alert-feishu</artifactId> |
||||||
|
<packaging>dolphinscheduler-plugin</packaging> |
||||||
|
|
||||||
|
<dependencies> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>org.apache.dolphinscheduler</groupId> |
||||||
|
<artifactId>dolphinscheduler-spi</artifactId> |
||||||
|
<scope>provided</scope> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>org.apache.httpcomponents</groupId> |
||||||
|
<artifactId>httpclient</artifactId> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>com.google.guava</groupId> |
||||||
|
<artifactId>guava</artifactId> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>ch.qos.logback</groupId> |
||||||
|
<artifactId>logback-classic</artifactId> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>org.slf4j</groupId> |
||||||
|
<artifactId>slf4j-api</artifactId> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>com.fasterxml.jackson.core</groupId> |
||||||
|
<artifactId>jackson-annotations</artifactId> |
||||||
|
<scope>provided</scope> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>junit</groupId> |
||||||
|
<artifactId>junit</artifactId> |
||||||
|
<scope>test</scope> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>org.mockito</groupId> |
||||||
|
<artifactId>mockito-core</artifactId> |
||||||
|
<type>jar</type> |
||||||
|
<scope>test</scope> |
||||||
|
</dependency> |
||||||
|
</dependencies> |
||||||
|
|
||||||
|
<build> |
||||||
|
<finalName>dolphinscheduler-alert-feishu-${project.version}</finalName> |
||||||
|
</build> |
||||||
|
|
||||||
|
</project> |
@ -0,0 +1,38 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||||
|
* (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.apache.dolphinscheduler.plugin.alert.feishu; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.spi.alert.AlertChannel; |
||||||
|
import org.apache.dolphinscheduler.spi.alert.AlertData; |
||||||
|
import org.apache.dolphinscheduler.spi.alert.AlertInfo; |
||||||
|
import org.apache.dolphinscheduler.spi.alert.AlertResult; |
||||||
|
|
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
public class FeiShuAlertChannel implements AlertChannel { |
||||||
|
@Override |
||||||
|
public AlertResult process(AlertInfo alertInfo) { |
||||||
|
|
||||||
|
AlertData alertData = alertInfo.getAlertData(); |
||||||
|
Map<String, String> paramsMap = alertInfo.getAlertParams(); |
||||||
|
if (null == paramsMap) { |
||||||
|
return new AlertResult("false", "fei shu params is null"); |
||||||
|
} |
||||||
|
return new FeiShuSender(paramsMap).sendFeiShuMsg(alertData); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,82 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||||
|
* (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.apache.dolphinscheduler.plugin.alert.feishu; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.spi.alert.AlertChannel; |
||||||
|
import org.apache.dolphinscheduler.spi.alert.AlertChannelFactory; |
||||||
|
import org.apache.dolphinscheduler.spi.params.InputParam; |
||||||
|
import org.apache.dolphinscheduler.spi.params.PasswordParam; |
||||||
|
import org.apache.dolphinscheduler.spi.params.RadioParam; |
||||||
|
import org.apache.dolphinscheduler.spi.params.base.ParamsOptions; |
||||||
|
import org.apache.dolphinscheduler.spi.params.base.PluginParams; |
||||||
|
import org.apache.dolphinscheduler.spi.params.base.Validate; |
||||||
|
|
||||||
|
import java.util.Arrays; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
public class FeiShuAlertChannelFactory implements AlertChannelFactory { |
||||||
|
@Override |
||||||
|
public String getName() { |
||||||
|
return "Feishu"; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public List<PluginParams> getParams() { |
||||||
|
InputParam webHookParam = InputParam.newBuilder(FeiShuParamsConstants.NAME_WEB_HOOK, FeiShuParamsConstants.WEB_HOOK) |
||||||
|
.addValidate(Validate.newBuilder() |
||||||
|
.setRequired(true) |
||||||
|
.build()) |
||||||
|
.build(); |
||||||
|
RadioParam isEnableProxy = |
||||||
|
RadioParam.newBuilder(FeiShuParamsConstants.NAME_FEI_SHU_PROXY_ENABLE, FeiShuParamsConstants.NAME_FEI_SHU_PROXY_ENABLE) |
||||||
|
.addParamsOptions(new ParamsOptions("YES", true, false)) |
||||||
|
.addParamsOptions(new ParamsOptions("NO", false, false)) |
||||||
|
.setValue(true) |
||||||
|
.addValidate(Validate.newBuilder() |
||||||
|
.setRequired(false) |
||||||
|
.build()) |
||||||
|
.build(); |
||||||
|
InputParam proxyParam = |
||||||
|
InputParam.newBuilder(FeiShuParamsConstants.NAME_FEI_SHU_PROXY, FeiShuParamsConstants.FEI_SHU_PROXY) |
||||||
|
.addValidate(Validate.newBuilder() |
||||||
|
.setRequired(false).build()) |
||||||
|
.build(); |
||||||
|
|
||||||
|
InputParam portParam = InputParam.newBuilder(FeiShuParamsConstants.NAME_FEI_SHU_PORT, FeiShuParamsConstants.FEI_SHU_PORT) |
||||||
|
.addValidate(Validate.newBuilder() |
||||||
|
.setRequired(false).build()) |
||||||
|
.build(); |
||||||
|
|
||||||
|
InputParam userParam = |
||||||
|
InputParam.newBuilder(FeiShuParamsConstants.NAME_FEI_SHU_USER, FeiShuParamsConstants.FEI_SHU_USER) |
||||||
|
.addValidate(Validate.newBuilder() |
||||||
|
.setRequired(false).build()) |
||||||
|
.build(); |
||||||
|
PasswordParam passwordParam = PasswordParam.newBuilder(FeiShuParamsConstants.NAME_FEI_SHU_PASSWORD, FeiShuParamsConstants.FEI_SHU_PASSWORD) |
||||||
|
.setPlaceholder("if enable use authentication, you need input password") |
||||||
|
.build(); |
||||||
|
|
||||||
|
return Arrays.asList(webHookParam, isEnableProxy, proxyParam, portParam, userParam, passwordParam); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public AlertChannel create() { |
||||||
|
return new FeiShuAlertChannel(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,49 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||||
|
* (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.apache.dolphinscheduler.plugin.alert.feishu; |
||||||
|
|
||||||
|
public class FeiShuParamsConstants { |
||||||
|
|
||||||
|
private FeiShuParamsConstants() { |
||||||
|
throw new IllegalStateException("Utility class"); |
||||||
|
} |
||||||
|
|
||||||
|
static final String WEB_HOOK = "webhook"; |
||||||
|
|
||||||
|
static final String NAME_WEB_HOOK = "webHook"; |
||||||
|
|
||||||
|
public static final String FEI_SHU_PROXY_ENABLE = "isEnableProxy"; |
||||||
|
|
||||||
|
static final String NAME_FEI_SHU_PROXY_ENABLE = "isEnableProxy"; |
||||||
|
|
||||||
|
static final String FEI_SHU_PROXY = "proxy"; |
||||||
|
|
||||||
|
static final String NAME_FEI_SHU_PROXY = "proxy"; |
||||||
|
|
||||||
|
static final String FEI_SHU_PORT = "port"; |
||||||
|
|
||||||
|
static final String NAME_FEI_SHU_PORT = "port"; |
||||||
|
|
||||||
|
static final String FEI_SHU_USER = "user"; |
||||||
|
|
||||||
|
static final String NAME_FEI_SHU_USER = "user"; |
||||||
|
|
||||||
|
static final String FEI_SHU_PASSWORD = "password"; |
||||||
|
|
||||||
|
static final String NAME_FEI_SHU_PASSWORD = "password"; |
||||||
|
} |
@ -0,0 +1,214 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||||
|
* (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.apache.dolphinscheduler.plugin.alert.feishu; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.spi.alert.AlertData; |
||||||
|
import org.apache.dolphinscheduler.spi.alert.AlertResult; |
||||||
|
import org.apache.dolphinscheduler.spi.utils.JSONUtils; |
||||||
|
|
||||||
|
import org.apache.commons.codec.binary.StringUtils; |
||||||
|
import org.apache.http.HttpEntity; |
||||||
|
import org.apache.http.HttpStatus; |
||||||
|
import org.apache.http.client.methods.CloseableHttpResponse; |
||||||
|
import org.apache.http.client.methods.HttpPost; |
||||||
|
import org.apache.http.impl.client.CloseableHttpClient; |
||||||
|
import org.apache.http.util.EntityUtils; |
||||||
|
|
||||||
|
import java.io.IOException; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Iterator; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.Map.Entry; |
||||||
|
|
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty; |
||||||
|
|
||||||
|
public class FeiShuSender { |
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(FeiShuSender.class); |
||||||
|
|
||||||
|
private String url; |
||||||
|
|
||||||
|
private Boolean enableProxy; |
||||||
|
|
||||||
|
private String proxy; |
||||||
|
|
||||||
|
private Integer port; |
||||||
|
|
||||||
|
private String user; |
||||||
|
|
||||||
|
private String password; |
||||||
|
|
||||||
|
FeiShuSender(Map<String, String> config) { |
||||||
|
url = config.get(FeiShuParamsConstants.NAME_WEB_HOOK); |
||||||
|
enableProxy = Boolean.valueOf(config.get(FeiShuParamsConstants.NAME_FEI_SHU_PROXY_ENABLE)); |
||||||
|
if (Boolean.TRUE.equals(enableProxy)) { |
||||||
|
port = Integer.parseInt(config.get(FeiShuParamsConstants.NAME_FEI_SHU_PORT)); |
||||||
|
proxy = config.get(FeiShuParamsConstants.NAME_FEI_SHU_PROXY); |
||||||
|
user = config.get(FeiShuParamsConstants.NAME_FEI_SHU_USER); |
||||||
|
password = config.get(FeiShuParamsConstants.NAME_FEI_SHU_PASSWORD); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
private static String textToJsonString(AlertData alertData) { |
||||||
|
|
||||||
|
Map<String, Object> items = new HashMap<>(2); |
||||||
|
items.put("msg_type", "text"); |
||||||
|
Map<String, String> textContent = new HashMap<>(); |
||||||
|
byte[] byt = StringUtils.getBytesUtf8(formatContent(alertData)); |
||||||
|
String txt = StringUtils.newStringUtf8(byt); |
||||||
|
textContent.put("text", txt); |
||||||
|
items.put("content", textContent); |
||||||
|
return JSONUtils.toJsonString(items); |
||||||
|
} |
||||||
|
|
||||||
|
public static AlertResult checkSendFeiShuSendMsgResult(String result) { |
||||||
|
AlertResult alertResult = new AlertResult(); |
||||||
|
alertResult.setStatus("false"); |
||||||
|
|
||||||
|
if (org.apache.dolphinscheduler.spi.utils.StringUtils.isBlank(result)) { |
||||||
|
alertResult.setMessage("send fei shu msg error"); |
||||||
|
logger.info("send fei shu msg error,fei shu server resp is null"); |
||||||
|
return alertResult; |
||||||
|
} |
||||||
|
FeiShuSendMsgResponse sendMsgResponse = JSONUtils.parseObject(result, FeiShuSendMsgResponse.class); |
||||||
|
|
||||||
|
if (null == sendMsgResponse) { |
||||||
|
alertResult.setMessage("send fei shu msg fail"); |
||||||
|
logger.info("send fei shu msg error,resp error"); |
||||||
|
return alertResult; |
||||||
|
} |
||||||
|
if (sendMsgResponse.statusCode == 0) { |
||||||
|
alertResult.setStatus("true"); |
||||||
|
alertResult.setMessage("send fei shu msg success"); |
||||||
|
return alertResult; |
||||||
|
} |
||||||
|
alertResult.setMessage(String.format("alert send fei shu msg error : %s", sendMsgResponse.getStatusMessage())); |
||||||
|
logger.info("alert send fei shu msg error : {} ,Extra : {} ", sendMsgResponse.getStatusMessage(), sendMsgResponse.getExtra()); |
||||||
|
return alertResult; |
||||||
|
} |
||||||
|
|
||||||
|
public static String formatContent(AlertData alertData) { |
||||||
|
if (alertData.getContent() != null) { |
||||||
|
|
||||||
|
List<Map> list = JSONUtils.toList(alertData.getContent(), Map.class); |
||||||
|
if (list.isEmpty()) { |
||||||
|
return alertData.getTitle() + alertData.getContent(); |
||||||
|
} |
||||||
|
|
||||||
|
StringBuilder contents = new StringBuilder(100); |
||||||
|
contents.append(String.format("`%s`%n", alertData.getTitle())); |
||||||
|
for (Map map : list) { |
||||||
|
Iterator<Entry<String, Object>> entries = map.entrySet().iterator(); |
||||||
|
while (entries.hasNext()) { |
||||||
|
Entry<String, Object> entry = entries.next(); |
||||||
|
String key = entry.getKey(); |
||||||
|
String value = entry.getValue().toString(); |
||||||
|
contents.append(key + ":" + value); |
||||||
|
contents.append("\n"); |
||||||
|
} |
||||||
|
} |
||||||
|
return contents.toString(); |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
public AlertResult sendFeiShuMsg(AlertData alertData) { |
||||||
|
AlertResult alertResult; |
||||||
|
try { |
||||||
|
String resp = sendMsg(alertData); |
||||||
|
return checkSendFeiShuSendMsgResult(resp); |
||||||
|
} catch (Exception e) { |
||||||
|
logger.info("send fei shu alert msg exception : {}", e.getMessage()); |
||||||
|
alertResult = new AlertResult(); |
||||||
|
alertResult.setStatus("false"); |
||||||
|
alertResult.setMessage("send fei shu alert fail."); |
||||||
|
} |
||||||
|
return alertResult; |
||||||
|
} |
||||||
|
|
||||||
|
private String sendMsg(AlertData alertData) throws IOException { |
||||||
|
|
||||||
|
String msgToJson = textToJsonString(alertData); |
||||||
|
|
||||||
|
HttpPost httpPost = HttpRequestUtil.constructHttpPost(url, msgToJson); |
||||||
|
|
||||||
|
CloseableHttpClient httpClient; |
||||||
|
|
||||||
|
httpClient = HttpRequestUtil.getHttpClient(enableProxy, proxy, port, user, password); |
||||||
|
|
||||||
|
try { |
||||||
|
CloseableHttpResponse response = httpClient.execute(httpPost); |
||||||
|
|
||||||
|
int statusCode = response.getStatusLine().getStatusCode(); |
||||||
|
if (statusCode != HttpStatus.SC_OK) { |
||||||
|
logger.error("send feishu message error, return http status code: {} ", statusCode); |
||||||
|
} |
||||||
|
String resp; |
||||||
|
try { |
||||||
|
HttpEntity entity = response.getEntity(); |
||||||
|
resp = EntityUtils.toString(entity, "utf-8"); |
||||||
|
EntityUtils.consume(entity); |
||||||
|
} finally { |
||||||
|
response.close(); |
||||||
|
} |
||||||
|
logger.info("Fei Shu send title :{} ,content :{}, resp: {}", alertData.getTitle(), alertData.getContent(), resp); |
||||||
|
return resp; |
||||||
|
} finally { |
||||||
|
httpClient.close(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public static class FeiShuSendMsgResponse { |
||||||
|
@JsonProperty("Extra") |
||||||
|
private String extra; |
||||||
|
@JsonProperty("StatusCode") |
||||||
|
private Integer statusCode; |
||||||
|
@JsonProperty("StatusMessage") |
||||||
|
private String statusMessage; |
||||||
|
|
||||||
|
public String getExtra() { |
||||||
|
return extra; |
||||||
|
} |
||||||
|
|
||||||
|
public void setExtra(String extra) { |
||||||
|
this.extra = extra; |
||||||
|
} |
||||||
|
|
||||||
|
public Integer getStatusCode() { |
||||||
|
return statusCode; |
||||||
|
} |
||||||
|
|
||||||
|
public void setStatusCode(Integer statusCode) { |
||||||
|
this.statusCode = statusCode; |
||||||
|
} |
||||||
|
|
||||||
|
public String getStatusMessage() { |
||||||
|
return statusMessage; |
||||||
|
} |
||||||
|
|
||||||
|
public void setStatusMessage(String statusMessage) { |
||||||
|
this.statusMessage = statusMessage; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,50 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||||
|
* (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.apache.dolphinscheduler.plugin.alert.feishu; |
||||||
|
|
||||||
|
import org.apache.http.HttpHost; |
||||||
|
import org.apache.http.auth.AuthScope; |
||||||
|
import org.apache.http.auth.UsernamePasswordCredentials; |
||||||
|
import org.apache.http.client.CredentialsProvider; |
||||||
|
import org.apache.http.client.methods.HttpPost; |
||||||
|
import org.apache.http.entity.ContentType; |
||||||
|
import org.apache.http.entity.StringEntity; |
||||||
|
import org.apache.http.impl.client.BasicCredentialsProvider; |
||||||
|
import org.apache.http.impl.client.CloseableHttpClient; |
||||||
|
import org.apache.http.impl.client.HttpClients; |
||||||
|
|
||||||
|
public class HttpRequestUtil { |
||||||
|
|
||||||
|
public static CloseableHttpClient getHttpClient(boolean enableProxy, String proxy, Integer port, String user, String password) { |
||||||
|
if (enableProxy) { |
||||||
|
HttpHost httpProxy = new HttpHost(proxy, port); |
||||||
|
CredentialsProvider provider = new BasicCredentialsProvider(); |
||||||
|
provider.setCredentials(new AuthScope(httpProxy), new UsernamePasswordCredentials(user, password)); |
||||||
|
return HttpClients.custom().setDefaultCredentialsProvider(provider).build(); |
||||||
|
} else { |
||||||
|
return HttpClients.createDefault(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public static HttpPost constructHttpPost(String url, String msg) { |
||||||
|
HttpPost post = new HttpPost(url); |
||||||
|
StringEntity entity = new StringEntity(msg, ContentType.APPLICATION_JSON); |
||||||
|
post.setEntity(entity); |
||||||
|
return post; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,45 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||||
|
* (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.apache.dolphinscheduler.plugin.alert.feishu; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.spi.alert.AlertChannel; |
||||||
|
import org.apache.dolphinscheduler.spi.params.base.PluginParams; |
||||||
|
import org.apache.dolphinscheduler.spi.utils.JSONUtils; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
import org.junit.Assert; |
||||||
|
import org.junit.Test; |
||||||
|
|
||||||
|
public class FeiShuAlertChannelFactoryTest { |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testGetParams() { |
||||||
|
FeiShuAlertChannelFactory feiShuAlertChannelFactory = new FeiShuAlertChannelFactory(); |
||||||
|
List<PluginParams> params = feiShuAlertChannelFactory.getParams(); |
||||||
|
JSONUtils.toJsonString(params); |
||||||
|
Assert.assertEquals(6, params.size()); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testCreate() { |
||||||
|
FeiShuAlertChannelFactory feiShuAlertChannelFactory = new FeiShuAlertChannelFactory(); |
||||||
|
AlertChannel alertChannel = feiShuAlertChannelFactory.create(); |
||||||
|
Assert.assertNotNull(alertChannel); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,99 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||||
|
* (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.apache.dolphinscheduler.plugin.alert.feishu; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.spi.alert.AlertData; |
||||||
|
import org.apache.dolphinscheduler.spi.alert.AlertResult; |
||||||
|
|
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
import org.junit.Assert; |
||||||
|
import org.junit.Before; |
||||||
|
import org.junit.Test; |
||||||
|
|
||||||
|
public class FeiShuSenderTest { |
||||||
|
|
||||||
|
|
||||||
|
private static Map<String, String> feiShuConfig = new HashMap<>(); |
||||||
|
|
||||||
|
@Before |
||||||
|
public void initFeiShuConfig() { |
||||||
|
feiShuConfig.put(FeiShuParamsConstants.WEB_HOOK, "https://open.feishu.cn/open-apis/bot/v2/hook/xxxxx"); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testSend() { |
||||||
|
AlertData alertData = new AlertData(); |
||||||
|
alertData.setTitle("feishu test title"); |
||||||
|
alertData.setContent("feishu test content"); |
||||||
|
FeiShuSender feiShuSender = new FeiShuSender(feiShuConfig); |
||||||
|
AlertResult alertResult = feiShuSender.sendFeiShuMsg(alertData); |
||||||
|
Assert.assertEquals("false", alertResult.getStatus()); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testFormatContent() { |
||||||
|
String alertMsg = "[\n" |
||||||
|
+ " {\n" |
||||||
|
+ " \"owner\": \"dolphinscheduler\",\n" |
||||||
|
+ " \"processEndTime\": \"2021-01-29 19:01:11\",\n" |
||||||
|
+ " \"processHost\": \"10.81.129.4:5678\",\n" |
||||||
|
+ " \"processId\": 2926,\n" |
||||||
|
+ " \"processName\": \"3-20210129190038108\",\n" |
||||||
|
+ " \"processStartTime\": \"2021-01-29 19:00:38\",\n" |
||||||
|
+ " \"processState\": \"SUCCESS\",\n" |
||||||
|
+ " \"processType\": \"START_PROCESS\",\n" |
||||||
|
+ " \"projectId\": 2,\n" |
||||||
|
+ " \"projectName\": \"testdelproject\",\n" |
||||||
|
+ " \"recovery\": \"NO\",\n" |
||||||
|
+ " \"retryTimes\": 0,\n" |
||||||
|
+ " \"runTimes\": 1,\n" |
||||||
|
+ " \"taskId\": 0\n" |
||||||
|
+ " }\n" |
||||||
|
+ "]"; |
||||||
|
AlertData alertData = new AlertData(); |
||||||
|
alertData.setTitle(""); |
||||||
|
alertData.setContent(alertMsg); |
||||||
|
Assert.assertNotNull(FeiShuSender.formatContent(alertData)); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testSendWithFormatException() { |
||||||
|
AlertData alertData = new AlertData(); |
||||||
|
alertData.setTitle("feishu test title"); |
||||||
|
alertData.setContent("feishu test content"); |
||||||
|
FeiShuSender feiShuSender = new FeiShuSender(feiShuConfig); |
||||||
|
String alertResult = feiShuSender.formatContent(alertData); |
||||||
|
Assert.assertEquals(alertResult, alertData.getTitle() + alertData.getContent()); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testCheckSendFeiShuSendMsgResult() { |
||||||
|
|
||||||
|
FeiShuSender feiShuSender = new FeiShuSender(feiShuConfig); |
||||||
|
AlertResult alertResult = feiShuSender.checkSendFeiShuSendMsgResult(""); |
||||||
|
Assert.assertFalse(Boolean.valueOf(alertResult.getStatus())); |
||||||
|
AlertResult alertResult2 = feiShuSender.checkSendFeiShuSendMsgResult("123"); |
||||||
|
Assert.assertEquals("send fei shu msg fail",alertResult2.getMessage()); |
||||||
|
|
||||||
|
String response = "{\"StatusCode\":\"0\",\"extra\":\"extra\",\"StatusMessage\":\"StatusMessage\"}"; |
||||||
|
AlertResult alertResult3 = feiShuSender.checkSendFeiShuSendMsgResult(response); |
||||||
|
Assert.assertTrue(Boolean.valueOf(alertResult3.getStatus())); |
||||||
|
} |
||||||
|
} |
@ -1,55 +0,0 @@ |
|||||||
///*
|
|
||||||
// * Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
// * contributor license agreements. See the NOTICE file distributed with
|
|
||||||
// * this work for additional information regarding copyright ownership.
|
|
||||||
// * The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
// * (the "License"); you may not use this file except in compliance with
|
|
||||||
// * the License. You may obtain a copy of the License at
|
|
||||||
// *
|
|
||||||
// * http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
// *
|
|
||||||
// * Unless required by applicable law or agreed to in writing, software
|
|
||||||
// * distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// * See the License for the specific language governing permissions and
|
|
||||||
// * limitations under the License.
|
|
||||||
// */
|
|
||||||
//package org.apache.dolphinscheduler.alert.manager;
|
|
||||||
//
|
|
||||||
//import org.apache.dolphinscheduler.alert.utils.MailUtils;
|
|
||||||
//
|
|
||||||
//import java.util.List;
|
|
||||||
//import java.util.Map;
|
|
||||||
//
|
|
||||||
///**
|
|
||||||
// * email send manager
|
|
||||||
// */
|
|
||||||
//public class EmailManager {
|
|
||||||
// /**
|
|
||||||
// * email send
|
|
||||||
// * @param receiversList the receiver list
|
|
||||||
// * @param receiversCcList the cc List
|
|
||||||
// * @param title the title
|
|
||||||
// * @param content the content
|
|
||||||
// * @param showType the showType
|
|
||||||
// * @return the send result
|
|
||||||
// */
|
|
||||||
// public Map<String,Object> send(List<String> receiversList,List<String> receiversCcList,String title,String content,String showType){
|
|
||||||
//
|
|
||||||
// return MailUtils.sendMails(receiversList, receiversCcList, title, content, showType);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * msg send
|
|
||||||
// * @param receiversList the receiver list
|
|
||||||
// * @param title the title
|
|
||||||
// * @param content the content
|
|
||||||
// * @param showType the showType
|
|
||||||
// * @return the send result
|
|
||||||
// */
|
|
||||||
// public Map<String,Object> send(List<String> receiversList,String title,String content,String showType){
|
|
||||||
//
|
|
||||||
// return MailUtils.sendMails(receiversList,title, content, showType);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//}
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue