-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #701 from atlanhq/DVX-522
Initial support for sending OpenLineage events via SDK
- Loading branch information
Showing
12 changed files
with
283 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* SPDX-License-Identifier: Apache-2.0 | ||
Copyright 2023 Atlan Pte. Ltd. */ | ||
package com.atlan.api; | ||
|
||
import com.atlan.AtlanClient; | ||
import com.atlan.exception.ApiConnectionException; | ||
|
||
/** | ||
* Base class for all API endpoints that ultimately access Chronos-surfaced services. | ||
*/ | ||
public abstract class ChronosEndpoint extends AbstractEndpoint { | ||
private static final String PREFIX = "/events/openlineage"; | ||
private static final String SERVICE = "http://chronos-service.kong.svc.cluster.local"; | ||
|
||
protected ChronosEndpoint(AtlanClient client) { | ||
super(client); | ||
} | ||
|
||
protected String getBaseUrl() throws ApiConnectionException { | ||
return getBaseUrl(SERVICE, PREFIX); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* SPDX-License-Identifier: Apache-2.0 | ||
Copyright 2022 Atlan Pte. Ltd. */ | ||
package com.atlan.api; | ||
|
||
import com.atlan.AtlanClient; | ||
import com.atlan.exception.AtlanException; | ||
import com.atlan.exception.AuthenticationException; | ||
import com.atlan.exception.ErrorCode; | ||
import com.atlan.exception.InvalidRequestException; | ||
import com.atlan.model.enums.AtlanConnectorType; | ||
import com.atlan.model.lineage.OpenLineageEvent; | ||
import com.atlan.net.ApiResource; | ||
import com.atlan.net.RequestOptions; | ||
|
||
/** | ||
* API endpoints for interacting with OpenLineage. | ||
*/ | ||
public class OpenLineageEndpoint extends ChronosEndpoint { | ||
|
||
private static final String endpoint = "api/v1/lineage"; | ||
|
||
public OpenLineageEndpoint(AtlanClient client) { | ||
super(client); | ||
} | ||
|
||
/** | ||
* Sends the OpenLineage event to Atlan to be consumed. | ||
* | ||
* @param request OpenLineage event to send | ||
* @param connectorType of the connection that should receive the OpenLineage event | ||
* @throws AtlanException on any issues with API communication | ||
*/ | ||
public void send(OpenLineageEvent request, AtlanConnectorType connectorType) throws AtlanException { | ||
send(request, connectorType, null); | ||
} | ||
|
||
/** | ||
* Sends the OpenLineage event to Atlan to be consumed. | ||
* | ||
* @param request OpenLineage event to send | ||
* @param connectorType of the connection that should receive the OpenLineage event | ||
* @param options to override default client settings | ||
* @throws AtlanException on any issues with API communication | ||
*/ | ||
public void send(OpenLineageEvent request, AtlanConnectorType connectorType, RequestOptions options) | ||
throws AtlanException { | ||
String url = String.format("%s/%s/%s", getBaseUrl(), connectorType.getValue(), endpoint); | ||
try { | ||
ApiResource.requestPlainText(client, ApiResource.RequestMethod.POST, url, request, options); | ||
} catch (AuthenticationException e) { | ||
if (e.getAtlanError() != null | ||
&& e.getAtlanError().getErrorMessage() != null | ||
&& e.getAtlanError() | ||
.getErrorMessage() | ||
.startsWith("Unauthorized: url path not configured to receive data, urlPath:")) { | ||
throw new InvalidRequestException(ErrorCode.OPENLINEAGE_NOT_CONFIGURED, e, connectorType.getValue()); | ||
} else { | ||
throw e; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
sdk/src/main/java/com/atlan/model/lineage/OpenLineageEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* SPDX-License-Identifier: Apache-2.0 | ||
Copyright 2022 Atlan Pte. Ltd. */ | ||
package com.atlan.model.lineage; | ||
|
||
import com.atlan.AtlanClient; | ||
import com.atlan.model.core.AtlanObject; | ||
import io.openlineage.client.OpenLineage; | ||
import io.openlineage.client.OpenLineageClientUtils; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
import lombok.experimental.SuperBuilder; | ||
import lombok.extern.jackson.Jacksonized; | ||
|
||
/** | ||
* Base class for handling OpenLineage events, passing through to the OpenLineage Java SDK | ||
* but wrapping events such that they are handled appropriately in the Atlan Java SDK. | ||
*/ | ||
@Getter | ||
@Jacksonized | ||
@SuperBuilder(toBuilder = true, builderMethodName = "_internal") | ||
@EqualsAndHashCode(callSuper = false) | ||
@ToString(callSuper = true) | ||
public class OpenLineageEvent extends AtlanObject { | ||
private static final long serialVersionUID = 2L; | ||
|
||
OpenLineage.BaseEvent event; | ||
|
||
public OpenLineageEvent(OpenLineage.BaseEvent event) { | ||
this.event = event; | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
@Override | ||
public String toJson(AtlanClient client) { | ||
return OpenLineageClientUtils.toJson(event); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.