Search in sources :

Example 51 with SequenceInputStream

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;
}
Also used : lombok.val(lombok.val) SequenceInputStream(java.io.SequenceInputStream) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 52 with SequenceInputStream

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);
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) BufferedInputStream(java.io.BufferedInputStream) SequenceInputStream(java.io.SequenceInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) KeyException(java.security.KeyException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) SchedulerRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.SchedulerRestException) InternalSchedulerException(org.ow2.proactive.scheduler.common.exception.InternalSchedulerException) LogForwardingRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.LogForwardingRestException) NodeException(org.objectweb.proactive.core.node.NodeException) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) JobCreationRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.JobCreationRestException) ConnectionException(org.ow2.proactive.scheduler.common.exception.ConnectionException) IOException(java.io.IOException) SchedulerException(org.ow2.proactive.scheduler.common.exception.SchedulerException) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) LoginException(javax.security.auth.login.LoginException) ActiveObjectCreationException(org.objectweb.proactive.ActiveObjectCreationException) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) URISyntaxException(java.net.URISyntaxException) UnknownTaskRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownTaskRestException) LogForwardingException(org.ow2.proactive.scheduler.common.util.logforwarder.LogForwardingException) JobAlreadyFinishedException(org.ow2.proactive.scheduler.common.exception.JobAlreadyFinishedException) UnknownJobRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException) SubmissionClosedException(org.ow2.proactive.scheduler.common.exception.SubmissionClosedException) JobAlreadyFinishedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.JobAlreadyFinishedRestException) SubmissionClosedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.SubmissionClosedRestException) SequenceInputStream(java.io.SequenceInputStream) UnknownJobRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) JobState(org.ow2.proactive.scheduler.common.job.JobState) TaskState(org.ow2.proactive.scheduler.common.task.TaskState) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) GZIP(org.jboss.resteasy.annotations.GZIP)

Aggregations

SequenceInputStream (java.io.SequenceInputStream)52 InputStream (java.io.InputStream)38 ByteArrayInputStream (java.io.ByteArrayInputStream)37 IOException (java.io.IOException)14 ArrayList (java.util.ArrayList)11 FileInputStream (java.io.FileInputStream)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 HashMap (java.util.HashMap)6 DataOutputStream (java.io.DataOutputStream)5 Charset (java.nio.charset.Charset)5 IStatus (org.eclipse.core.runtime.IStatus)5 Status (org.eclipse.core.runtime.Status)5 BufferedInputStream (java.io.BufferedInputStream)4 ByteBuffer (java.nio.ByteBuffer)4 CharacterCodingException (java.nio.charset.CharacterCodingException)4 CharsetEncoder (java.nio.charset.CharsetEncoder)4 IllegalCharsetNameException (java.nio.charset.IllegalCharsetNameException)4 UnmappableCharacterException (java.nio.charset.UnmappableCharacterException)4 UnsupportedCharsetException (java.nio.charset.UnsupportedCharsetException)4 Vector (java.util.Vector)4