use of javax.ws.rs.ServiceUnavailableException in project cdap by caskdata.
the class RuntimeMonitor method run.
@Override
protected void run() {
runThread = Thread.currentThread();
try {
while (!stopped) {
try {
if (topicsToRequest.isEmpty()) {
initializeTopics();
}
HttpResponse response = restClient.execute(HttpRequest.builder(HttpMethod.POST, clientConfig.resolveURL("runtime/metadata")).withBody(GSON.toJson(topicsToRequest)).build());
if (response.getResponseCode() == HttpURLConnection.HTTP_UNAVAILABLE) {
throw new ServiceUnavailableException(response.getResponseBodyAsString());
}
Map<String, List<MonitorMessage>> monitorResponses = GSON.fromJson(response.getResponseBodyAsString(StandardCharsets.UTF_8), MAP_STRING_MESSAGE_TYPE);
processResponse(monitorResponses);
} catch (Exception e) {
OUTAGE_LOG.warn("Failed to fetch monitoring data from program {}, run {}. Will be retried in next iteration.", programId.getProgram(), programId.getRun(), e);
}
Thread.sleep(pollTimeMillis);
}
} catch (InterruptedException e) {
// Interruption means stopping the service.
}
}
use of javax.ws.rs.ServiceUnavailableException in project cdap by caskdata.
the class RuntimeMonitor method initializeTopics.
private void initializeTopics() throws Exception {
Set<String> topicsToMonitor = new HashSet<>();
topicsToMonitor.addAll(Arrays.asList(cConf.get(Constants.RuntimeMonitor.TOPICS).split(",")));
HttpResponse response = restClient.execute(HttpMethod.POST, clientConfig.resolveURL("runtime/monitor/topics"), GSON.toJson(topicsToMonitor), Collections.emptyMap(), null);
if (response.getResponseCode() == HttpURLConnection.HTTP_UNAVAILABLE) {
throw new ServiceUnavailableException(response.getResponseBodyAsString());
}
Map<String, String> configToTopic = GSON.fromJson(response.getResponseBodyAsString(StandardCharsets.UTF_8), MAP_STRING_STRING_TYPE);
// TODO initialize from offset table for a given programId
for (Map.Entry<String, String> entry : configToTopic.entrySet()) {
topicsToRequest.put(entry.getKey(), new MonitorConsumeRequest(entry.getValue(), entry.getKey(), null, limit));
}
}
use of javax.ws.rs.ServiceUnavailableException in project incubator-pulsar by apache.
the class BaseResource method getApiException.
public PulsarAdminException getApiException(Throwable e) {
if (e instanceof PulsarAdminException) {
return (PulsarAdminException) e;
} else if (e instanceof ServiceUnavailableException) {
if (e.getCause() instanceof java.net.ConnectException) {
return new ConnectException(e.getCause());
} else {
ServerErrorException see = (ServerErrorException) e;
int statusCode = see.getResponse().getStatus();
String httpError = getReasonFromServer(see);
return new PulsarAdminException(e, httpError, statusCode);
}
} else if (e instanceof WebApplicationException) {
// Handle 5xx exceptions
if (e instanceof ServerErrorException) {
ServerErrorException see = (ServerErrorException) e;
int statusCode = see.getResponse().getStatus();
String httpError = getReasonFromServer(see);
return new ServerSideErrorException(see, httpError, httpError, statusCode);
} else if (e instanceof ClientErrorException) {
// Handle 4xx exceptions
ClientErrorException cee = (ClientErrorException) e;
int statusCode = cee.getResponse().getStatus();
String httpError = getReasonFromServer(cee);
switch(statusCode) {
case 401:
case 403:
return new NotAuthorizedException(cee, httpError, statusCode);
case 404:
return new NotFoundException(cee, httpError, statusCode);
case 405:
return new NotAllowedException(cee, httpError, statusCode);
case 409:
return new ConflictException(cee, httpError, statusCode);
case 412:
return new PreconditionFailedException(cee, httpError, statusCode);
default:
return new PulsarAdminException(httpError, cee, httpError, statusCode);
}
} else {
WebApplicationException wae = (WebApplicationException) e;
int statusCode = wae.getResponse().getStatus();
String httpError = getReasonFromServer(wae);
return new PulsarAdminException(httpError, wae, httpError, statusCode);
}
} else {
return new PulsarAdminException(e);
}
}
use of javax.ws.rs.ServiceUnavailableException in project dataverse by IQSS.
the class Access method tabularDatafileMetadataDDI.
/*
* This has been moved here, under /api/access, from the /api/meta hierarchy
* which we are going to retire.
*/
@Path("datafile/{fileId}/metadata/ddi")
@GET
@Produces({ "text/xml" })
public String tabularDatafileMetadataDDI(@PathParam("fileId") String fileId, @QueryParam("fileMetadataId") Long fileMetadataId, @QueryParam("exclude") String exclude, @QueryParam("include") String include, @Context HttpHeaders header, @Context HttpServletResponse response) throws NotFoundException, ServiceUnavailableException /*, PermissionDeniedException, AuthorizationRequiredException*/
{
String retValue = "";
DataFile dataFile = null;
dataFile = findDataFileOrDieWrapper(fileId);
if (!dataFile.isTabularData()) {
throw new BadRequestException("tabular data required");
}
if (dataFile.isRestricted() || FileUtil.isActivelyEmbargoed(dataFile)) {
boolean hasPermissionToDownloadFile = false;
DataverseRequest dataverseRequest;
try {
dataverseRequest = createDataverseRequest(findUserOrDie());
} catch (WrappedResponse ex) {
throw new BadRequestException("cannot find user");
}
if (dataverseRequest != null && dataverseRequest.getUser() instanceof GuestUser) {
// We must be in the UI. Try to get a non-GuestUser from the session.
dataverseRequest = dvRequestService.getDataverseRequest();
}
hasPermissionToDownloadFile = permissionService.requestOn(dataverseRequest, dataFile).has(Permission.DownloadFile);
if (!hasPermissionToDownloadFile) {
throw new BadRequestException("no permission to download file");
}
}
response.setHeader("Content-disposition", "attachment; filename=\"dataverse_files.zip\"");
FileMetadata fm = null;
if (fileMetadataId == null) {
fm = dataFile.getFileMetadata();
} else {
fm = dataFileService.findFileMetadata(fileMetadataId);
}
String fileName = fm.getLabel().replaceAll("\\.tab$", "-ddi.xml");
response.setHeader("Content-disposition", "attachment; filename=\"" + fileName + "\"");
response.setHeader("Content-Type", "application/xml; name=\"" + fileName + "\"");
ByteArrayOutputStream outStream = null;
outStream = new ByteArrayOutputStream();
Long dataFileId = dataFile.getId();
try {
ddiExportService.exportDataFile(dataFileId, outStream, exclude, include, fileMetadataId);
retValue = outStream.toString();
} catch (Exception e) {
// We return Service Unavailable.
throw new ServiceUnavailableException();
}
return retValue;
}
use of javax.ws.rs.ServiceUnavailableException in project dataverse by IQSS.
the class Meta method dataset.
@Deprecated
@Path("dataset/{datasetId}")
@GET
@Produces({ "application/xml" })
public String dataset(@PathParam("datasetId") Long datasetId, @QueryParam("exclude") String exclude, @QueryParam("include") String include, @Context HttpHeaders header, @Context HttpServletResponse response) throws NotFoundException /*, ServiceUnavailableException, PermissionDeniedException, AuthorizationRequiredException*/
{
Dataset dataset = datasetService.find(datasetId);
if (dataset == null) {
throw new NotFoundException();
}
String retValue = "";
ByteArrayOutputStream outStream = null;
outStream = new ByteArrayOutputStream();
try {
ddiExportService.exportDataset(datasetId, outStream, exclude, include);
retValue = outStream.toString();
} catch (Exception e) {
// metadata record requested. We simply return an empty string.
throw new ServiceUnavailableException();
}
return retValue;
}
Aggregations