use of co.cask.cdap.common.BadRequestException in project cdap by caskdata.
the class MetadataHttpHandler method readArray.
private String[] readArray(HttpRequest request) throws BadRequestException {
ChannelBuffer content = request.getContent();
if (!content.readable()) {
throw new BadRequestException("Unable to read a list of tags from the request.");
}
List<String> toReturn;
try (Reader reader = new InputStreamReader(new ChannelBufferInputStream(content), Charsets.UTF_8)) {
toReturn = GSON.fromJson(reader, LIST_STRING_TYPE);
} catch (IOException e) {
throw new BadRequestException("Unable to read a list of tags from the request.", e);
}
if (toReturn == null) {
throw new BadRequestException("Null tags were read from the request.");
}
return toReturn.toArray(new String[toReturn.size()]);
}
use of co.cask.cdap.common.BadRequestException in project cdap by caskdata.
the class LineageHandler method parseRange.
// TODO: CDAP-3715 This is a fairly common operation useful in various handlers
private TimeRange parseRange(String startStr, String endStr) throws BadRequestException {
if (startStr == null) {
throw new BadRequestException("Start time is required.");
}
if (endStr == null) {
throw new BadRequestException("End time is required.");
}
long now = TimeMathParser.nowInSeconds();
long start;
long end;
try {
// start and end are specified in seconds from HTTP request,
// but specified in milliseconds to the LineageGenerator
start = TimeUnit.SECONDS.toMillis(TimeMathParser.parseTimeInSeconds(now, startStr));
end = TimeUnit.SECONDS.toMillis(TimeMathParser.parseTimeInSeconds(now, endStr));
} catch (IllegalArgumentException e) {
throw new BadRequestException(e);
}
if (start < 0) {
throw new BadRequestException(String.format("Invalid start time (%s -> %d), should be >= 0.", startStr, start));
}
if (end < 0) {
throw new BadRequestException(String.format("Invalid end time (%s -> %d), should be >= 0.", endStr, end));
}
if (start > end) {
throw new BadRequestException(String.format("Start time (%s -> %d) should be lesser than end time (%s -> %d).", startStr, start, endStr, end));
}
return new TimeRange(start, end);
}
use of co.cask.cdap.common.BadRequestException in project cdap by caskdata.
the class LineageHandler method getCollapseTypes.
private static Set<CollapseType> getCollapseTypes(@Nullable List<String> collapse) throws BadRequestException {
if (collapse == null) {
return Collections.emptySet();
}
Set<CollapseType> collapseTypes = new HashSet<>();
for (String c : collapse) {
try {
CollapseType type = CollapseType.valueOf(c.toUpperCase());
collapseTypes.add(type);
} catch (IllegalArgumentException e) {
throw new BadRequestException(String.format("Invalid collapse type %s", c));
}
}
return collapseTypes;
}
use of co.cask.cdap.common.BadRequestException in project cdap by caskdata.
the class AppFabricClient method getProgramSchedules.
public List<ScheduleDetail> getProgramSchedules(String namespace, String app, String workflow) throws NotFoundException {
MockResponder responder = new MockResponder();
String uri = String.format("%s/apps/%s/workflows/%s/schedules", getNamespacePath(namespace), app, workflow);
HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, uri);
try {
workflowHttpHandler.getWorkflowSchedules(request, responder, namespace, app, workflow, null);
} catch (BadRequestException e) {
// cannot happen
throw Throwables.propagate(e);
}
List<ScheduleDetail> schedules = responder.decodeResponseContent(SCHEDULE_DETAILS_TYPE, GSON);
verifyResponse(HttpResponseStatus.OK, responder.getStatus(), "Getting workflow schedules failed");
return schedules;
}
use of co.cask.cdap.common.BadRequestException in project cdap by caskdata.
the class MetadataHttpHandlerTestRun method testInvalidSearchParams.
@Test
public void testInvalidSearchParams() throws Exception {
NamespaceId namespace = new NamespaceId("invalid");
Set<EntityTypeSimpleName> targets = EnumSet.allOf(EntityTypeSimpleName.class);
try {
searchMetadata(namespace, "*", targets, AbstractSystemMetadataWriter.ENTITY_NAME_KEY);
Assert.fail();
} catch (BadRequestException e) {
// expected
}
// search with bad sort field
try {
searchMetadata(namespace, "*", targets, "name asc");
Assert.fail();
} catch (BadRequestException e) {
// expected
}
// search with bad sort order
try {
searchMetadata(namespace, "*", targets, AbstractSystemMetadataWriter.ENTITY_NAME_KEY + " unknown");
Assert.fail();
} catch (BadRequestException e) {
// expected
}
// search with numCursors for relevance sort
try {
searchMetadata(NamespaceId.DEFAULT, "search*", targets, null, 0, Integer.MAX_VALUE, 1, null);
Assert.fail();
} catch (BadRequestException e) {
// expected
}
// search with cursor for relevance sort
try {
searchMetadata(NamespaceId.DEFAULT, "search*", targets, null, 0, Integer.MAX_VALUE, 0, "cursor");
Assert.fail();
} catch (BadRequestException e) {
// expected
}
// search with invalid query
try {
searchMetadata(NamespaceId.DEFAULT, "");
Assert.fail();
} catch (BadRequestException e) {
// expected
}
}
Aggregations