|
@@ -0,0 +1,115 @@
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+"""Task shell."""
|
|
|
+
|
|
|
+from typing import Optional
|
|
|
+
|
|
|
+from pydolphinscheduler.constants import TaskType
|
|
|
+from pydolphinscheduler.core.task import Task, TaskParams
|
|
|
+
|
|
|
+
|
|
|
+class HttpMethod:
|
|
|
+ """Constant of HTTP method."""
|
|
|
+
|
|
|
+ GET = "GET"
|
|
|
+ POST = "POST"
|
|
|
+ HEAD = "HEAD"
|
|
|
+ PUT = "PUT"
|
|
|
+ DELETE = "DELETE"
|
|
|
+
|
|
|
+
|
|
|
+class HttpCheckCondition:
|
|
|
+ """Constant of HTTP check condition.
|
|
|
+
|
|
|
+ For now it contain four value:
|
|
|
+ - STATUS_CODE_DEFAULT: when http response code equal to 200, mark as success.
|
|
|
+ - STATUS_CODE_CUSTOM: when http response code equal to the code user define, mark as success.
|
|
|
+ - BODY_CONTAINS: when http response body contain text user define, mark as success.
|
|
|
+ - BODY_NOT_CONTAINS: when http response body do not contain text user define, mark as success.
|
|
|
+ """
|
|
|
+
|
|
|
+ STATUS_CODE_DEFAULT = "STATUS_CODE_DEFAULT"
|
|
|
+ STATUS_CODE_CUSTOM = "STATUS_CODE_CUSTOM"
|
|
|
+ BODY_CONTAINS = "BODY_CONTAINS"
|
|
|
+ BODY_NOT_CONTAINS = "BODY_NOT_CONTAINS"
|
|
|
+
|
|
|
+
|
|
|
+class HttpTaskParams(TaskParams):
|
|
|
+ """Parameter only for Http task types."""
|
|
|
+
|
|
|
+ def __init__(
|
|
|
+ self,
|
|
|
+ url: str,
|
|
|
+ http_method: Optional[str] = HttpMethod.GET,
|
|
|
+ http_params: Optional[str] = None,
|
|
|
+ http_check_condition: Optional[str] = HttpCheckCondition.STATUS_CODE_DEFAULT,
|
|
|
+ condition: Optional[str] = None,
|
|
|
+ connect_timeout: Optional[int] = 60000,
|
|
|
+ socket_timeout: Optional[int] = 60000,
|
|
|
+ *args,
|
|
|
+ **kwargs
|
|
|
+ ):
|
|
|
+ super().__init__(*args, **kwargs)
|
|
|
+ self.url = url
|
|
|
+ if not hasattr(HttpMethod, http_method):
|
|
|
+ raise ValueError("Parameter http_method %s not support.", http_method)
|
|
|
+ self.http_method = http_method
|
|
|
+ self.http_params = http_params or []
|
|
|
+ if not hasattr(HttpCheckCondition, http_check_condition):
|
|
|
+ raise ValueError(
|
|
|
+ "Parameter http_check_condition %s not support.", http_check_condition
|
|
|
+ )
|
|
|
+ self.http_check_condition = http_check_condition
|
|
|
+ if (
|
|
|
+ http_check_condition != HttpCheckCondition.STATUS_CODE_DEFAULT
|
|
|
+ and condition is None
|
|
|
+ ):
|
|
|
+ raise ValueError(
|
|
|
+ "Parameter condition must provider if http_check_condition not equal to STATUS_CODE_DEFAULT"
|
|
|
+ )
|
|
|
+ self.condition = condition
|
|
|
+ self.connect_timeout = connect_timeout
|
|
|
+ self.socket_timeout = socket_timeout
|
|
|
+
|
|
|
+
|
|
|
+class Http(Task):
|
|
|
+ """Task HTTP object, declare behavior for HTTP task to dolphinscheduler."""
|
|
|
+
|
|
|
+ def __init__(
|
|
|
+ self,
|
|
|
+ name: str,
|
|
|
+ url: str,
|
|
|
+ http_method: Optional[str] = HttpMethod.GET,
|
|
|
+ http_params: Optional[str] = None,
|
|
|
+ http_check_condition: Optional[str] = HttpCheckCondition.STATUS_CODE_DEFAULT,
|
|
|
+ condition: Optional[str] = None,
|
|
|
+ connect_timeout: Optional[int] = 60000,
|
|
|
+ socket_timeout: Optional[int] = 60000,
|
|
|
+ *args,
|
|
|
+ **kwargs
|
|
|
+ ):
|
|
|
+ task_params = HttpTaskParams(
|
|
|
+ url=url,
|
|
|
+ http_method=http_method,
|
|
|
+ http_params=http_params,
|
|
|
+ http_check_condition=http_check_condition,
|
|
|
+ condition=condition,
|
|
|
+ connect_timeout=connect_timeout,
|
|
|
+ socket_timeout=socket_timeout,
|
|
|
+ )
|
|
|
+ super().__init__(name, TaskType.HTTP, task_params, *args, **kwargs)
|