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

Bound {namespace} to NamespaceName #391

Merged
merged 8 commits into from
Mar 7, 2019
Merged
9 changes: 5 additions & 4 deletions src/main/java/marquez/api/resources/DatasetResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,18 @@ public DatasetResource(
@Path("/namespaces/{namespace}/datasets")
@Produces(APPLICATION_JSON)
public Response list(
@PathParam("namespace") String namespaceString,
@PathParam("namespace") NamespaceName namespaceName,
@QueryParam("limit") @DefaultValue("100") Integer limit,
@QueryParam("offset") @DefaultValue("0") Integer offset)
throws MarquezServiceException, WebApplicationException {
if (!namespaceService.exists(namespaceString)) {
if (!namespaceService.exists(namespaceName.getValue())) {
throw new WebApplicationException(
String.format("The namespace %s does not exist.", namespaceString), NOT_FOUND);
String.format("The namespace %s does not exist.", namespaceName.getValue()), NOT_FOUND);
}
try {
String namespaceNameString = namespaceName.getValue();
final List<Dataset> datasets =
datasetService.getAll(NamespaceName.fromString(namespaceString), limit, offset);
datasetService.getAll(NamespaceName.fromString(namespaceNameString), limit, offset);
final List<DatasetResponse> datasetResponses = map(datasets);
return Response.ok(new DatasetsResponse(datasetResponses)).build();
} catch (Exception e) {
Expand Down
30 changes: 16 additions & 14 deletions src/main/java/marquez/api/resources/JobResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import marquez.api.models.JobRunRequest;
import marquez.api.models.JobsResponse;
import marquez.common.models.JobName;
import marquez.common.models.NamespaceName;
import marquez.service.JobService;
import marquez.service.NamespaceService;
import marquez.service.exceptions.MarquezServiceException;
Expand Down Expand Up @@ -68,11 +69,11 @@ public JobResource(final NamespaceService namespaceService, final JobService job
@Produces(APPLICATION_JSON)
@Timed
public Response create(
@PathParam("namespace") final String namespace,
@PathParam("namespace") NamespaceName namespaceName,
@PathParam("job") JobName jobName,
@Valid final JobRequest request)
throws MarquezServiceException {
if (!namespaceService.exists(namespace)) {
if (!namespaceService.exists(namespaceName.getValue())) {
return Response.status(Response.Status.NOT_FOUND).build();
}
final Job jobToCreate =
Expand All @@ -84,8 +85,8 @@ public Response create(
request.getOutputDatasetUrns(),
request.getLocation(),
request.getDescription().orElse(null)));
jobToCreate.setNamespaceGuid(namespaceService.get(namespace).get().getGuid());
final Job createdJob = jobService.createJob(namespace, jobToCreate);
jobToCreate.setNamespaceGuid(namespaceService.get(namespaceName.getValue()).get().getGuid());
final Job createdJob = jobService.createJob(namespaceName.getValue(), jobToCreate);
return Response.status(Response.Status.CREATED)
.entity(coreJobToApiJobMapper.map(createdJob))
.build();
Expand All @@ -96,12 +97,13 @@ public Response create(
@Produces(APPLICATION_JSON)
@Timed
public Response getJob(
@PathParam("namespace") final String namespace, @PathParam("job") final JobName jobName)
@PathParam("namespace") NamespaceName namespaceName, @PathParam("job") final JobName jobName)
throws MarquezServiceException {
if (!namespaceService.exists(namespace)) {
if (!namespaceService.exists(namespaceName.getValue())) {
return Response.status(Response.Status.NOT_FOUND).entity("Namespace not found").build();
}
final Optional<Job> returnedJob = jobService.getJob(namespace, jobName.getValue());
final Optional<Job> returnedJob =
jobService.getJob(namespaceName.getValue(), jobName.getValue());
if (returnedJob.isPresent()) {
return Response.ok().entity(coreJobToApiJobMapper.map(returnedJob.get())).build();
}
Expand All @@ -112,12 +114,12 @@ public Response getJob(
@Timed
@Produces(APPLICATION_JSON)
@Path("/namespaces/{namespace}/jobs")
public Response listJobs(@PathParam("namespace") final String namespace)
public Response listJobs(@PathParam("namespace") NamespaceName namespaceName)
throws MarquezServiceException {
if (!namespaceService.exists(namespace)) {
if (!namespaceService.exists(namespaceName.getValue())) {
return Response.status(Response.Status.NOT_FOUND).build();
}
final List<Job> jobList = jobService.getAllJobsInNamespace(namespace);
final List<Job> jobList = jobService.getAllJobsInNamespace(namespaceName.getValue());
final JobsResponse response = new JobsResponse(coreJobToApiJobMapper.map(jobList));
return Response.ok().entity(response).build();
}
Expand All @@ -127,20 +129,20 @@ public Response listJobs(@PathParam("namespace") final String namespace)
@Consumes(APPLICATION_JSON)
@Path("namespaces/{namespace}/jobs/{job}/runs")
public Response create(
@PathParam("namespace") final String namespace,
@PathParam("namespace") NamespaceName namespaceName,
@PathParam("job") JobName jobName,
@Valid final JobRunRequest request)
throws MarquezServiceException {
if (!namespaceService.exists(namespace)) {
if (!namespaceService.exists(namespaceName.getValue())) {
return Response.status(Response.Status.NOT_FOUND).build();
}
if (!jobService.getJob(namespace, jobName.getValue()).isPresent()) {
if (!jobService.getJob(namespaceName.getValue(), jobName.getValue()).isPresent()) {
log.error("Could not find job: " + jobName.getValue());
return Response.status(Response.Status.NOT_FOUND).build();
}
JobRun createdJobRun =
jobService.createJobRun(
namespace,
namespaceName.getValue(),
jobName.getValue(),
request.getRunArgs().orElse(null),
request.getNominalStartTime().map(Timestamp::valueOf).orElse(null),
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/marquez/api/resources/NamespaceResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
import marquez.api.models.NamespaceRequest;
import marquez.api.models.NamespaceResponse;
import marquez.api.models.NamespacesResponse;
import marquez.common.models.NamespaceName;
import marquez.service.NamespaceService;
import marquez.service.exceptions.MarquezServiceException;
import marquez.service.models.Namespace;
import org.hibernate.validator.constraints.NotBlank;

@Slf4j
@Path("/api/v1")
Expand All @@ -58,10 +58,10 @@ public NamespaceResource(@NonNull final NamespaceService namespaceService) {
@Timed
@Path("/namespaces/{namespace}")
public Response create(
@PathParam("namespace") @NotBlank String namespaceString, @Valid NamespaceRequest request)
@PathParam("namespace") NamespaceName namespaceName, @Valid NamespaceRequest request)
throws MarquezServiceException {
final Namespace namespace =
namespaceService.create(namespaceApiMapper.of(namespaceString, request));
namespaceService.create(namespaceApiMapper.of(namespaceName.getValue(), request));
final NamespaceResponse response = NamespaceResponseMapper.map(namespace);
return Response.ok(response).build();
}
Expand All @@ -70,10 +70,10 @@ public Response create(
@Produces(APPLICATION_JSON)
@Timed
@Path("/namespaces/{namespace}")
public Response get(@PathParam("namespace") String namespaceString)
public Response get(@PathParam("namespace") NamespaceName namespaceName)
throws MarquezServiceException {
final Optional<NamespaceResponse> namespaceResponse =
namespaceService.get(namespaceString).map(NamespaceResponseMapper::map);
namespaceService.get(namespaceName.getValue()).map(NamespaceResponseMapper::map);
if (namespaceResponse.isPresent()) {
return Response.ok(namespaceResponse.get()).build();
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/marquez/api/resources/DatasetResourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void testListDatasets200() throws MarquezServiceException {
final List<Dataset> datasets = Arrays.asList(dataset);
when(mockDatasetService.getAll(NAMESPACE_NAME, LIMIT, OFFSET)).thenReturn(datasets);

final Response response = datasetResource.list(NAMESPACE_NAME.getValue(), LIMIT, OFFSET);
final Response response = datasetResource.list(NAMESPACE_NAME, LIMIT, OFFSET);
assertEquals(OK, response.getStatusInfo());

final DatasetsResponse datasetsResponse = (DatasetsResponse) response.getEntity();
Expand All @@ -85,6 +85,6 @@ public void testListDatasets200() throws MarquezServiceException {
public void testListDatasetsNamespaceDoesNotExist() throws MarquezServiceException {
when(mockNamespaceService.exists(NAMESPACE_NAME.getValue())).thenReturn(false);

datasetResource.list(NAMESPACE_NAME.getValue(), LIMIT, OFFSET);
datasetResource.list(NAMESPACE_NAME, LIMIT, OFFSET);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import marquez.api.mappers.CoreNamespaceToApiNamespaceMapper;
import marquez.api.models.NamespaceResponse;
import marquez.api.models.NamespacesResponse;
import marquez.common.models.NamespaceName;
import marquez.service.NamespaceService;
import marquez.service.exceptions.MarquezServiceException;
import marquez.service.models.Namespace;
Expand All @@ -45,6 +46,7 @@

public class NamespaceResourceTest extends NamespaceBaseTest {

NamespaceName namespaceName = NamespaceName.fromString(NAMESPACE_NAME);
CoreNamespaceToApiNamespaceMapper namespaceMapper = new CoreNamespaceToApiNamespaceMapper();
private static final NamespaceService NAMESPACE_SERVICE = mock(NamespaceService.class);

Expand Down Expand Up @@ -80,7 +82,7 @@ public void testValidNamespace() throws MarquezServiceException {
NamespaceResource namespaceResource = new NamespaceResource(namespaceService);

when(namespaceService.get(NAMESPACE_NAME)).thenReturn(returnedOptionalNamespace);
Response res = namespaceResource.get(NAMESPACE_NAME);
Response res = namespaceResource.get(namespaceName);
NamespaceResponse responseBody = (NamespaceResponse) res.getEntity();

assertEquals(Response.Status.OK.getStatusCode(), res.getStatus());
Expand Down