use of io.pravega.auth.AuthHandler.Permissions.READ_UPDATE in project pravega by pravega.
the class StreamMetadataResourceImpl method updateStream.
/**
* Implementation of updateStream REST API.
*
* @param scopeName The scope name of stream.
* @param streamName The name of stream.
* @param updateStreamRequest The object conforming to updateStreamConfig request json.
* @param securityContext The security for API access.
* @param asyncResponse AsyncResponse provides means for asynchronous server side response processing.
*/
@Override
public void updateStream(final String scopeName, final String streamName, final UpdateStreamRequest updateStreamRequest, final SecurityContext securityContext, final AsyncResponse asyncResponse) {
long traceId = LoggerHelpers.traceEnter(log, "updateStream");
try {
authenticate(scopeName + "/" + streamName, READ_UPDATE);
} catch (AuthenticationException e) {
log.warn("Update stream for {} failed due to authentication failure.", scopeName + "/" + streamName);
asyncResponse.resume(Response.status(Status.UNAUTHORIZED).build());
LoggerHelpers.traceLeave(log, "Update stream", traceId);
return;
}
StreamConfiguration streamConfiguration = ModelHelper.getUpdateStreamConfig(updateStreamRequest, scopeName, streamName);
controllerService.updateStream(streamConfiguration).thenApply(streamStatus -> {
if (streamStatus.getStatus() == UpdateStreamStatus.Status.SUCCESS) {
log.info("Successfully updated stream config for: {}/{}", scopeName, streamName);
return Response.status(Status.OK).entity(ModelHelper.encodeStreamResponse(streamConfiguration)).build();
} else if (streamStatus.getStatus() == UpdateStreamStatus.Status.STREAM_NOT_FOUND || streamStatus.getStatus() == UpdateStreamStatus.Status.SCOPE_NOT_FOUND) {
log.warn("Stream: {}/{} not found", scopeName, streamName);
return Response.status(Status.NOT_FOUND).build();
} else {
log.warn("updateStream failed for {}/{}", scopeName, streamName);
return Response.status(Status.INTERNAL_SERVER_ERROR).build();
}
}).exceptionally(exception -> {
log.warn("updateStream for {}/{} failed with exception: {}", scopeName, streamName, exception);
return Response.status(Status.INTERNAL_SERVER_ERROR).build();
}).thenApply(asyncResponse::resume).thenAccept(x -> LoggerHelpers.traceLeave(log, "updateStream", traceId));
}
use of io.pravega.auth.AuthHandler.Permissions.READ_UPDATE in project pravega by pravega.
the class StreamMetadataResourceImpl method createStream.
/**
* Implementation of createStream REST API.
*
* @param scopeName The scope name of stream.
* @param createStreamRequest The object conforming to createStream request json.
* @param securityContext The security for API access.
* @param asyncResponse AsyncResponse provides means for asynchronous server side response processing.
*/
@Override
public void createStream(final String scopeName, final CreateStreamRequest createStreamRequest, final SecurityContext securityContext, final AsyncResponse asyncResponse) {
long traceId = LoggerHelpers.traceEnter(log, "createStream");
try {
NameUtils.validateUserStreamName(createStreamRequest.getStreamName());
} catch (IllegalArgumentException | NullPointerException e) {
log.warn("Create stream failed due to invalid stream name {}", createStreamRequest.getStreamName());
asyncResponse.resume(Response.status(Status.BAD_REQUEST).build());
LoggerHelpers.traceLeave(log, "createStream", traceId);
return;
}
try {
authenticate(scopeName + "/" + createStreamRequest.getStreamName(), READ_UPDATE);
} catch (AuthenticationException e) {
log.warn("Create stream for {} failed due to authentication failure.", createStreamRequest.getStreamName());
asyncResponse.resume(Response.status(Status.UNAUTHORIZED).build());
LoggerHelpers.traceLeave(log, "createStream", traceId);
return;
}
StreamConfiguration streamConfiguration = ModelHelper.getCreateStreamConfig(createStreamRequest, scopeName);
controllerService.createStream(streamConfiguration, System.currentTimeMillis()).thenApply(streamStatus -> {
Response resp = null;
if (streamStatus.getStatus() == CreateStreamStatus.Status.SUCCESS) {
log.info("Successfully created stream: {}/{}", scopeName, streamConfiguration.getStreamName());
resp = Response.status(Status.CREATED).entity(ModelHelper.encodeStreamResponse(streamConfiguration)).build();
} else if (streamStatus.getStatus() == CreateStreamStatus.Status.STREAM_EXISTS) {
log.warn("Stream already exists: {}/{}", scopeName, streamConfiguration.getStreamName());
resp = Response.status(Status.CONFLICT).build();
} else if (streamStatus.getStatus() == CreateStreamStatus.Status.SCOPE_NOT_FOUND) {
log.warn("Scope not found: {}", scopeName);
resp = Response.status(Status.NOT_FOUND).build();
} else if (streamStatus.getStatus() == CreateStreamStatus.Status.INVALID_STREAM_NAME) {
log.warn("Invalid stream name: {}", streamConfiguration.getStreamName());
resp = Response.status(Status.BAD_REQUEST).build();
} else {
log.warn("createStream failed for : {}/{}", scopeName, streamConfiguration.getStreamName());
resp = Response.status(Status.INTERNAL_SERVER_ERROR).build();
}
return resp;
}).exceptionally(exception -> {
log.warn("createStream for {}/{} failed {}: ", scopeName, streamConfiguration.getStreamName(), exception);
return Response.status(Status.INTERNAL_SERVER_ERROR).build();
}).thenApply(asyncResponse::resume).thenAccept(x -> LoggerHelpers.traceLeave(log, "createStream", traceId));
}
use of io.pravega.auth.AuthHandler.Permissions.READ_UPDATE in project pravega by pravega.
the class PravegaRequestProcessor method createSegment.
@Override
public void createSegment(CreateSegment createStreamsSegment) {
Timer timer = new Timer();
Collection<AttributeUpdate> attributes = Arrays.asList(new AttributeUpdate(SCALE_POLICY_TYPE, AttributeUpdateType.Replace, ((Byte) createStreamsSegment.getScaleType()).longValue()), new AttributeUpdate(SCALE_POLICY_RATE, AttributeUpdateType.Replace, ((Integer) createStreamsSegment.getTargetRate()).longValue()));
if (!verifyToken(createStreamsSegment.getSegment(), createStreamsSegment.getRequestId(), createStreamsSegment.getDelegationToken(), READ_UPDATE, "Create Segment")) {
return;
}
segmentStore.createStreamSegment(createStreamsSegment.getSegment(), attributes, TIMEOUT).thenAccept(v -> {
createStreamSegment.reportSuccessEvent(timer.getElapsed());
connection.send(new SegmentCreated(createStreamsSegment.getRequestId(), createStreamsSegment.getSegment()));
}).whenComplete((res, e) -> {
if (e == null) {
if (statsRecorder != null) {
statsRecorder.createSegment(createStreamsSegment.getSegment(), createStreamsSegment.getScaleType(), createStreamsSegment.getTargetRate());
}
} else {
createStreamSegment.reportFailEvent(timer.getElapsed());
handleException(createStreamsSegment.getRequestId(), createStreamsSegment.getSegment(), "Create segment", e);
}
});
}
use of io.pravega.auth.AuthHandler.Permissions.READ_UPDATE in project pravega by pravega.
the class PravegaRequestProcessor method createTransaction.
@Override
public void createTransaction(CreateTransaction createTransaction) {
if (!verifyToken(createStreamSegment.getName(), createTransaction.getRequestId(), createTransaction.getDelegationToken(), READ_UPDATE, "Create Transaction")) {
return;
}
Collection<AttributeUpdate> attributes = Collections.singleton(new AttributeUpdate(CREATION_TIME, AttributeUpdateType.None, System.currentTimeMillis()));
log.debug("Creating transaction {} ", createTransaction);
long requestId = createTransaction.getRequestId();
segmentStore.createTransaction(createTransaction.getSegment(), createTransaction.getTxid(), attributes, TIMEOUT).thenAccept(txName -> connection.send(new TransactionCreated(requestId, createTransaction.getSegment(), createTransaction.getTxid()))).exceptionally(e -> handleException(requestId, createTransaction.getSegment(), "Create transaction", e));
}
use of io.pravega.auth.AuthHandler.Permissions.READ_UPDATE in project pravega by pravega.
the class PravegaRequestProcessor method truncateSegment.
@Override
public void truncateSegment(TruncateSegment truncateSegment) {
String segment = truncateSegment.getSegment();
if (!verifyToken(segment, truncateSegment.getRequestId(), truncateSegment.getDelegationToken(), READ_UPDATE, "Truncate Segment")) {
return;
}
long offset = truncateSegment.getTruncationOffset();
log.debug("Truncating segment {} at offset {} ", segment, offset);
segmentStore.truncateStreamSegment(segment, offset, TIMEOUT).thenAccept(v -> connection.send(new SegmentTruncated(truncateSegment.getRequestId(), segment))).exceptionally(e -> handleException(truncateSegment.getRequestId(), segment, "Truncate segment", e));
}
Aggregations