In DataWorks, you can use extensions to define custom logic to govern user operations, such as intercepting and blocking inappropriate actions, receiving notifications for specific events, and implementing process control. This topic describes how to develop and deploy an extension using a self-managed service.
Background
Prerequisites
You have enabled event message subscription. Deploying an extension using a self-managed service relies on the message distribution capability of EventBridge. Ensure that you have specified an event bus in EventBridge to receive open event messages from DataWorks, and that messages from this event bus are routed to your service that is deployed on-premises or in the cloud.
Limitations
-
Only users of DataWorks Enterprise Edition can use the Extensions module.
-
The Extensions module is available in the following regions: China (Beijing), China (Hangzhou), China (Shanghai), China (Zhangjiakou), China (Shenzhen), China (Chengdu), US (Silicon Valley), US (Virginia), Germany (Frankfurt), Japan (Tokyo), China (Hong Kong), and Singapore.
Usage notes
-
Only the Open Platform administrator, tenant administrator, Alibaba Cloud accounts, and RAM users to which the AliyunDataWorksFullAccess policy is attached have read and write permissions on the developer backend. For more information about permission management, see Permission control for global services and Manage product-level and console access with RAM policies.
-
Version limitations: If your DataWorks Enterprise Edition subscription expires, all extensions become inactive and can no longer be triggered for event checks. Any checks that have been triggered but have not yet reached a final state are automatically passed.
-
Node limitations: When a composite node that contains inner nodes, such as a Platform for AI node, a do-while node, or a for-each node, triggers a check, all inner nodes must pass the check before subsequent operations can proceed.
-
Triggering: You can associate multiple extensions with the same extension point event. This means a single event can trigger multiple extensions.
How it works
The following diagram shows the basic workflow for deploying an extension with a self-managed service that consumes messages using EventBridge.
After an extension point event is triggered, the associated process enters the Checking state while waiting for the extension to return a result through an API callback. The process remains in this state until the extension sends the result to DataWorks. Based on the returned result, DataWorks determines whether to block the process.
Develop the service
Before you deploy an extension in DataWorks, you must develop the extension and deploy it on-premises or in the cloud. You can initialize your project using the code from Appendix: DataWorks Open Platform sample code library and get more examples from the Open Platform sample code on GitHub. When you develop the extension, you must deploy it based on the type of service that receives messages routed from the event bus.
Step 1: Configure dependencies
When you develop an extension, add the following dependencies to the pom.xml file. EventBridge supports various types of endpoints to process and consume events. In addition to the following dependencies, you may need to add other dependencies based on the event target that you configure in EventBridge.
DataWorks dependency library
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>dataworks_public20200518</artifactId>
<version>5.6.0</version>
</dependency>
Packaging plugin
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Step 2: Develop the extension code
The event bus in EventBridge routes messages to your deployed service. This service receives the DataWorks messages from the event bus, processes them, and then calls a specific DataWorks API to return the processing result.
-
Develop the service code.
Parse message content
For information about the format of event messages that DataWorks sends, see Appendix: Format of messages sent from DataWorks to EventBridge. In a message, the
datafield contains the specific message content. During development, you can identify the message type using thedata.eventCodefield and retrieve message details using theidfield.NoteOpenEvent uses EventBridge to distribute DataWorks event messages. Before you develop an extension, you must subscribe to DataWorks messages in EventBridge. For more information, see Enable event message subscription.
Write the processing logic
You must process the messages from the event bus based on your business requirements. You can use the following methods to improve development efficiency and application performance:
-
Use Advanced feature: Configure parameters for an extension. For example, you can use the
extension.project.disabledparameter to disable the extension for a specific workspace. -
When you process extension points related to the DataStudio module, call the GetIDEEventDetail operation and use the
MessageIdto obtain a data snapshot from when the extension point event was triggered.
NoteThe
MessageIdparameter corresponds to theidfield in the event message. For more information, see Appendix: Format of messages sent from DataWorks to EventBridge.Return result to DataWorks
Your service must return the processing result to DataWorks by calling an OpenAPI operation. The specific API operation that you call depends on the module in which the extension point event originated.
-
Extension point events in DataStudio: Call the UpdateIDEEventResult operation to return the processing result.
-
Extension point events in Operation Center: Call the UpdateWorkbenchEventResult operation to return the processing result.
-
Extension point events in other modules: Call the CallbackExtension operation to return the processing result.
The callback API request must include the following parameters: the extension to which the service applies (ExtensionCode), the event message (MessageId), and the processing result (CheckResult).
-
CheckResult: The processing result. Valid values:
-
OK: The extension check passed for this extension point event. -
FAIL: The extension check failed for this extension point event. You must investigate and resolve the error to ensure that subsequent processes run as expected. -
WARN: The extension check passed for this extension point event, but a warning was generated.
-
-
ExtensionCode: After you register the extension, you can obtain this code from the extension list page in DataWorks.
-
MessageId: Corresponds to the id field in the message. For more information, see Appendix: Format of messages sent from DataWorks to EventBridge.
-
-
After you finish developing the code, package the application into an executable
.jarfile for deployment.
Step 3: Deploy the extension
After you develop and debug the extension code, you must deploy the packaged code as an application service on an ECS instance or a server from another provider.
Configure the extension in DataWorks
After you finish developing the code, you can register and manage the extension in DataWorks.
Step 1: Register the extension
To develop and use an extension, you must first register it in DataWorks to obtain the ExtensionCode that is required for subsequent development. Perform the following steps:
Go to the Developer Backend tab.
Log on to the DataWorks console. In the top navigation bar, select the desired region. In the left-side navigation pane, choose . On the page that appears, click Go to Open Platform. The Developer Backend tab appears.
-
Register the extension.
-
In the left-side navigation pane, click Extensions to open the extension page.
-
Click , select Deploy Based on Self-managed Service, and configure the extension information.
-
-
Complete the extension registration.
Click OK to complete the registration.
NoteAfter the registration is complete, you can view the registered extension on the List of Extensions page.
Step 2: Publish the extension
After you develop, deploy, and register the extension in DataWorks, you must test, approve, and publish it. Once published, administrators other than the extension owner can enable the extension in Management Center. For more information, see Apply an extension.
Appendix: Message format from DataWorks to EventBridge
In the following code, DataWorks pushes the content of the data field to EventBridge. EventBridge adds other information to it.
{
"datacontenttype": "application/json;charset=utf-8", // The format of the content in the data field. The datacontenttype parameter supports only the application/json format.
"aliyunaccountid": "1111",// The ID of the Alibaba Cloud account.
"aliyunpublishtime": "2024-07-10T07:25:34.915Z",// The time when EventBridge received the event.
"data": {
"tenantId": 28378****10656,// The ID of the tenant. In DataWorks, each Alibaba Cloud account has a unique tenant ID. To find your ID, go to the DataStudio page and click the user information icon in the upper-right corner.
"eventCode": "xxxx"//
},
"aliyunoriginalaccountid": "11111",
"specversion": "1.0",
"aliyuneventbusname": "default",// The name of the event bus in EventBridge that is used to receive event messages from DataWorks.
"id": "45ef4dewdwe1-7c35-447a-bd93-fab****",// The unique ID of the event.
"source": "acs.dataworks",// The event source. `acs.dataworks` indicates that DataWorks pushed the message.
"time": "2024-07-10T15:25:34.897Z",// The time when the event was generated.
"aliyunregionid": "cn-shanghai",// The region where the event was received.
"type": "dataworks:ResourcesUpload:UploadDataToTable"// The event type. You can use this parameter in the EventBridge console to filter messages from DataWorks. The value of this parameter varies by event.
}
The content of the data field varies based on the message type. For more information about event messages, see Developer reference: Event list and message format.
Extension examples
You can now develop custom extension code based on your business requirements. The following topics provide examples of how to register, develop, and apply extensions in typical scenarios.
Related documents
-
For information about the message format of each event type, see Developer reference: Event list and message format.
-
OpenEvent allows you to subscribe to messages for some events by using EventBridge. For more information, see OpenEvent overview.
-
For a list of extension points that you can handle with extensions, see Extensions overview.
-
You can also deploy an extension using Function Compute. For more information, see Develop and deploy an extension by using Function Compute.