DataWorks Open Platform provides sample code for related application scenarios to help you better understand and use the various features of Open Platform, such as OpenAPI, OpenEvent, and Extensions. This topic describes how to execute the sample code that is obtained from GitHub on your on-premises machine to demonstrate the openness capabilities of DataWorks in various business scenarios.
Background information
DataWorks Open Platform provides the OpenAPI, OpenEvent, and Extensions modules. You can use the modules to integrate DataWorks with your applications and subscribe to event messages. The modules allow you to interconnect various application systems with DataWorks for data process control, data governance, and data O&M. The modules also allow you to respond to changes in the business status of various application systems at the earliest opportunity. For more information about Open Platform, see Overview.
Project initialization
Step 1: Prepare the development environment
Install the Java Development Kit (JDK).
To install the JDK, go to the official website of Oracle and download the JDK whose version is compatible with your operating system.
NoteIn this example, the JDK version must be Java 1.8 or later. After the installation is complete, start Command Prompt or a terminal and run the
java -version
command to check the Java version.Install Maven.
Maven is a Java runtime environment tool. You can go to the official website of Maven and download a Maven package that is compatible with your operating system. After the download is complete, you can refer to Installing Apache Maven to decompress the package and install Maven.
Install Node.js.
In this example, a frontend page is used. Therefore, you must install the Node.js environment on the client to execute JavaScript code. To install the Node.js environment, go to the official website of Node.js and download the Node.js environment.
NoteIn this example, the version of Node.js must be later than 14. After the installation is complete, start Command Prompt or a terminal and run the
node --version
command to check the Node.js version.Install pnpm.
pnpm is a package management tool for JavaScript projects. In this example, the sample code library uses the workspace mode to prevent common components from being sent to npm. Therefore, you must install pnpm. You can click Installation to install the pnpm tool. If you have already installed Node.js, you can run the following command to install pnpm:
npm install -g pnpm
Check the development environment.
After you complete the preceding substeps, you can run the following commands to check whether the environment that is required in this example is installed:
java -version // If JDK is installed, the command output shows the JDK version. Otherwise, the "command not found" error is reported. mvn -v // If Maven is installed, the command output shows the Maven version. Otherwise, the "command not found" error is reported. npm -v // If Node.js is installed, the command output shows the Node.js version. Otherwise, the "command not found" error is reported. pnpm -v // If pnpm is installed, the command output shows the pnpm version. Otherwise, the "command not found" error is reported.
Step 2: Execute the sample code
Install dependencies.
After you prepare the development environment, you can download the sample project to your on-premises machine and execute the following code to install dependencies:
pnpm install
Enter your AccessKey ID and AccessKey secret.
After the installation is complete, find the application.properties configuration file in the root directory. In the configuration file, specify key information such as Access Key (AK), Secret Key (SK), Region-id, and endpoint. The preceding information will be read and synchronized to each sample application when the project starts.
NoteWhen you run the project, the key information that you specify in the configuration file is used to connect to the modules of DataWorks Open Platform.
## The AccessKey ID of a RAM user. api.access-key-id={access-key} ## The AccessKey secret of a RAM user. api.access-key-secret={secret-key} ## The ID of the region where the DataWorks service is deployed. Sample values: cn-shanghai and cn-hangzhou. # api.region-id=cn-hangzhou api.region-id={regionId} ## The service of DataWorks API operations. The default value is dataworks-public. api.product=dataworks-public ## The endpoint of DataWorks OpenAPI. ## If DataWorks OpenAPI is accessed over the Internet, the endpoint is in the format of dataworks.${regionId}.aliyuncs.com. By default, DataWorks OpenAPI is accessed over the Internet. ## If DataWorks OpenAPI is accessed over a virtual private cloud (VPC), the endpoint is in the format of dataworks-vpc.${regionId}.aliyuncs.com. # api.endpoint=dataworks.cn-hangzhou.aliyuncs.com api.endpoint={endpoint} ## Specify the network environment. For access over the Internet, set the parameter to false. For access over a VPC, set the parameter to true. api.vpc-env=false
Execute the sample code.
After you complete the preceding configurations, you can run the following commands to execute the sample code.
npm run example:workbench-screen // Execute the sample code for Operation Center. npm run example:meta-api // Execute the sample code for metadata. npm run example:event-instance-status // Execute the sample code for subscribing to the status change events of an auto triggered node instance. npm run example:extension-maxpt // Execute the sample code for prohibiting the use of the MAX_PT function. npm run example:extension-deploy-control // Execute the sample code for configuring the settings in DataWorks Open Platform to perform a lockdown.
View the execution result.
After the code is executed, you can view the results in a web browser.
For an example that has an interactive frontend page, you can access the page by using the following URL:
https://localhost:8080
For a backend-only example, you can access the backend by using the following URL:
http://localhost:8008
Obtain the sample code for an application scenario
You can obtain sample code for the following scenarios from the Open Platform sample code library:
Best practices for subscribing to the status change events of an auto triggered node instance
Best practices for prohibiting the use of the MAX_PT function
Best practices for configuring the settings in DataWorks Open Platform to perform a lockdown
Best practices for developing, committing, and running nodes