Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add DataProcess Urn #1673

Merged
merged 3 commits into from May 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
67 changes: 67 additions & 0 deletions li-utils/src/main/java/com/linkedin/common/urn/DataProcessUrn.java
@@ -0,0 +1,67 @@
package com.linkedin.common.urn;

import com.linkedin.common.FabricType;
import com.linkedin.data.template.Custom;
import com.linkedin.data.template.DirectCoercer;
import com.linkedin.data.template.TemplateOutputCastException;

import java.net.URISyntaxException;

import static com.linkedin.common.urn.UrnUtils.toFabricType;

public class DataProcessUrn extends Urn {
public static final String ENTITY_TYPE = "dataProcess";

private final String dataJobNameEntity;

private static final String CONTENT_FORMAT = "(%s,%s,%s)";

private final String dataJobOrchestrator;

private final FabricType originEntity;

public DataProcessUrn(String orchestrator, String name, FabricType origin) {
super(ENTITY_TYPE, String.format(CONTENT_FORMAT, orchestrator, name, origin.name()));
this.dataJobOrchestrator = orchestrator;
this.dataJobNameEntity = name;
this.originEntity = origin;
}

public String getJobNameEntity() {
return dataJobNameEntity;
}

public String getDataJobOrchestrator() {
return dataJobOrchestrator;
}

public FabricType getOriginEntity() {
return originEntity;
}

public static DataProcessUrn createFromString(String rawUrn) throws URISyntaxException {
String content = new Urn(rawUrn).getContent();
String[] parts = content.substring(1, content.length() - 1).split(",");
return new DataProcessUrn(parts[0], parts[1], toFabricType(parts[2]));
}

public static DataProcessUrn deserialize(String rawUrn) throws URISyntaxException {
return createFromString(rawUrn);
}

static {
Custom.registerCoercer(new DirectCoercer<DataProcessUrn>() {
public Object coerceInput(DataProcessUrn object) throws ClassCastException {
return object.toString();
}

public DataProcessUrn coerceOutput(Object object) throws TemplateOutputCastException {
try {
return DataProcessUrn.createFromString((String) object);
} catch (URISyntaxException e) {
throw new TemplateOutputCastException("Invalid URN syntax: " + e.getMessage(), e);
}
}
}, DataProcessUrn.class);
}
}