use of java.io.SequenceInputStream in project pravega by pravega.
the class StorageTestBase method populate.
private HashMap<String, ByteArrayOutputStream> populate(Storage s, String context) throws Exception {
HashMap<String, ByteArrayOutputStream> appendData = new HashMap<>();
byte[] extraData = new byte[1024];
for (int segmentId = 0; segmentId < SEGMENT_COUNT; segmentId++) {
String segmentName = getSegmentName(segmentId, context);
createSegment(segmentName, s);
val writeHandle = s.openWrite(segmentName).join();
ByteArrayOutputStream writeStream = new ByteArrayOutputStream();
appendData.put(segmentName, writeStream);
long offset = 0;
for (int j = 0; j < APPENDS_PER_SEGMENT; j++) {
byte[] writeData = String.format(APPEND_FORMAT, segmentName, j).getBytes();
// Append some garbage at the end to make sure we only write as much as instructed, and not the whole InputStream.
val dataStream = new SequenceInputStream(new ByteArrayInputStream(writeData), new ByteArrayInputStream(extraData));
s.write(writeHandle, offset, dataStream, writeData.length, TIMEOUT).join();
writeStream.write(writeData);
offset += writeData.length;
}
}
return appendData;
}
use of java.io.SequenceInputStream in project scheduling by ow2-proactive.
the class SchedulerStateRest method jobFullLogs.
@Override
@GET
@GZIP
@Path("jobs/{jobid}/log/full")
@Produces("application/json")
public InputStream jobFullLogs(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId, @QueryParam("sessionid") String session) throws NotConnectedRestException, UnknownJobRestException, UnknownTaskRestException, PermissionRestException, IOException {
if (sessionId == null) {
sessionId = session;
}
try {
Scheduler scheduler = checkAccess(sessionId, "jobs/" + jobId + "/log/full");
JobState jobState = scheduler.getJobState(jobId);
List<TaskState> tasks = jobState.getTasks();
List<InputStream> streams = new ArrayList<>(tasks.size());
Collections.sort(tasks, TaskState.COMPARE_BY_FINISHED_TIME_ASC);
for (TaskState taskState : tasks) {
InputStream inputStream = null;
try {
if (taskState.isPreciousLogs()) {
inputStream = retrieveTaskLogsUsingDataspaces(sessionId, jobId, taskState.getId());
} else {
String taskLogs = retrieveTaskLogsUsingDatabase(sessionId, jobId, taskState.getName());
if (!taskLogs.isEmpty()) {
inputStream = IOUtils.toInputStream(taskLogs);
}
logger.warn("Retrieving truncated logs for task '" + taskState.getId() + "'");
}
} catch (Exception e) {
logger.info("Could not retrieve logs for task " + taskState.getId() + " (could be a non finished or killed task)", e);
}
if (inputStream != null) {
streams.add(inputStream);
}
}
if (streams.isEmpty()) {
// will produce HTTP 204 code
return null;
} else {
return new SequenceInputStream(Collections.enumeration(streams));
}
} catch (PermissionException e) {
throw new PermissionRestException(e);
} catch (UnknownJobException e) {
throw new UnknownJobRestException(e);
} catch (NotConnectedException e) {
throw new NotConnectedRestException(e);
}
}
Aggregations