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

feat(urn): add AzkabanFlow and AzkabanJob urn #1677

Merged
merged 2 commits into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions li-utils/src/main/java/com/linkedin/common/urn/AzkabanFlowUrn.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.linkedin.common.urn;

import com.linkedin.data.template.Custom;
import com.linkedin.data.template.DirectCoercer;
import com.linkedin.data.template.TemplateOutputCastException;
import java.net.URISyntaxException;


public final class AzkabanFlowUrn extends Urn {

public static final String ENTITY_TYPE = "azkabanFlow";

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

private final String clusterEntity;

private final String projectEntity;

private final String flowIdEntity;

public AzkabanFlowUrn(String cluster, String project, String flowId) {
super(ENTITY_TYPE, String.format(CONTENT_FORMAT, cluster, project, flowId));
this.clusterEntity = cluster;
this.projectEntity = project;
this.flowIdEntity = flowId;
}

public String getClusterEntity() {
return clusterEntity;
}

public String getProjectEntity() {
return projectEntity;
}

public String getFlowIdEntity() {
return flowIdEntity;
}

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

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

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

public AzkabanFlowUrn coerceOutput(Object object) throws TemplateOutputCastException {
try {
return AzkabanFlowUrn.createFromString((String) object);
} catch (URISyntaxException e) {
throw new TemplateOutputCastException("Invalid URN syntax: " + e.getMessage(), e);
}
}
}, AzkabanFlowUrn.class);
}
}
59 changes: 59 additions & 0 deletions li-utils/src/main/java/com/linkedin/common/urn/AzkabanJobUrn.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.linkedin.common.urn;

import com.linkedin.data.template.Custom;
import com.linkedin.data.template.DirectCoercer;
import com.linkedin.data.template.TemplateOutputCastException;
import java.net.URISyntaxException;


public final class AzkabanJobUrn extends Urn {

public static final String ENTITY_TYPE = "azkabanJob";

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

private final AzkabanFlowUrn flowEntity;

private final String jobIdEntity;

public AzkabanJobUrn(AzkabanFlowUrn flow, String jobId) {
super(ENTITY_TYPE, String.format(CONTENT_FORMAT, flow.toString(), jobId));
this.flowEntity = flow;
this.jobIdEntity = jobId;
}

public AzkabanFlowUrn getFlowEntity() {
return flowEntity;
}

public String getJobIdEntity() {
return jobIdEntity;
}

public static AzkabanJobUrn createFromString(String rawUrn) throws URISyntaxException {
String content = new Urn(rawUrn).getContent();
String flowParts = content.substring(1, content.lastIndexOf(",") + 1);
String[] parts = content.substring(1, content.length() - 1).split(",");
return new AzkabanJobUrn(AzkabanFlowUrn.createFromString(flowParts), parts[3]);
}

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

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

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