Search in sources :

Example 6 with Synchronized

use of lombok.Synchronized in project pravega by pravega.

the class MockController method getSegmentsForStream.

@Synchronized
List<Segment> getSegmentsForStream(Stream stream) {
    StreamConfiguration config = createdStreams.get(stream);
    Preconditions.checkArgument(config != null, "Stream must be created first");
    ScalingPolicy scalingPolicy = config.getScalingPolicy();
    if (scalingPolicy.getScaleType() != ScalingPolicy.ScaleType.FIXED_NUM_SEGMENTS) {
        throw new IllegalArgumentException("Dynamic scaling not supported with a mock controller");
    }
    List<Segment> result = new ArrayList<>(scalingPolicy.getMinNumSegments());
    for (int i = 0; i < scalingPolicy.getMinNumSegments(); i++) {
        result.add(new Segment(config.getScope(), config.getStreamName(), i));
    }
    return result;
}
Also used : ScalingPolicy(io.pravega.client.stream.ScalingPolicy) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) ArrayList(java.util.ArrayList) CreateSegment(io.pravega.shared.protocol.netty.WireCommands.CreateSegment) Segment(io.pravega.client.segment.impl.Segment) DeleteSegment(io.pravega.shared.protocol.netty.WireCommands.DeleteSegment) Synchronized(lombok.Synchronized)

Example 7 with Synchronized

use of lombok.Synchronized in project pravega by pravega.

the class InProcPravegaCluster method close.

@Override
@Synchronized
public void close() throws Exception {
    if (isInProcSegmentStore) {
        for (ServiceStarter starter : this.nodeServiceStarter) {
            starter.shutdown();
        }
    }
    if (isInProcController) {
        for (ControllerServiceMain controller : this.controllerServers) {
            controller.stopAsync();
        }
    }
    if (this.zkService != null) {
        this.zkService.close();
        this.zkService = null;
    }
}
Also used : ServiceStarter(io.pravega.segmentstore.server.host.ServiceStarter) ControllerServiceMain(io.pravega.controller.server.ControllerServiceMain) Synchronized(lombok.Synchronized)

Example 8 with Synchronized

use of lombok.Synchronized in project pravega by pravega.

the class InProcPravegaCluster method start.

/**
 * Kicks off the cluster creation. right now it can be done only once in lifetime of a process.
 * @throws Exception Exception thrown by ZK/HDFS etc.
 */
@Synchronized
public void start() throws Exception {
    /*Start the ZK*/
    if (isInProcZK) {
        zkUrl = "localhost:" + zkPort;
        startLocalZK();
    } else {
        URI zkUri = new URI("temp://" + zkUrl);
        zkHost = zkUri.getHost();
        zkPort = zkUri.getPort();
    }
    if (isInProcHDFS) {
        startLocalHDFS();
        hdfsUrl = String.format("hdfs://localhost:%d/", localHdfs.getNameNodePort());
    }
    cleanUpZK();
    if (isInProcController) {
        startLocalControllers();
    }
    if (isInProcSegmentStore) {
        nodeServiceStarter = new ServiceStarter[segmentStoreCount];
        startLocalSegmentStores();
    }
}
Also used : URI(java.net.URI) Synchronized(lombok.Synchronized)

Example 9 with Synchronized

use of lombok.Synchronized in project pravega by pravega.

the class S3FileSystemImpl method completeMultipartUpload.

@Synchronized
@Override
public CompleteMultipartUploadResult completeMultipartUpload(CompleteMultipartUploadRequest request) {
    Map<Integer, CopyPartRequest> partMap = multipartUploads.get(request.getKey());
    if (partMap == null) {
        throw new S3Exception("NoSuchKey", HttpStatus.SC_NOT_FOUND, "NoSuchKey", "");
    }
    try {
        partMap.forEach((index, copyPart) -> {
            if (copyPart.getKey() != copyPart.getSourceKey()) {
                Path sourcePath = Paths.get(this.baseDir, copyPart.getBucketName(), copyPart.getSourceKey());
                Path targetPath = Paths.get(this.baseDir, copyPart.getBucketName(), copyPart.getKey());
                try (FileChannel sourceChannel = FileChannel.open(sourcePath, StandardOpenOption.READ);
                    FileChannel targetChannel = FileChannel.open(targetPath, StandardOpenOption.WRITE)) {
                    targetChannel.transferFrom(sourceChannel, Files.size(targetPath), copyPart.getSourceRange().getLast() + 1 - copyPart.getSourceRange().getFirst());
                    targetChannel.close();
                    AclSize aclMap = this.aclMap.get(copyPart.getKey());
                    this.aclMap.put(copyPart.getKey(), aclMap.withSize(Files.size(targetPath)));
                } catch (IOException e) {
                    throw new S3Exception("NoSuchKey", 404, "NoSuchKey", "");
                }
            }
        });
    } finally {
        multipartUploads.remove(request.getKey());
    }
    return new CompleteMultipartUploadResult();
}
Also used : Path(java.nio.file.Path) CopyPartRequest(com.emc.object.s3.request.CopyPartRequest) S3Exception(com.emc.object.s3.S3Exception) FileChannel(java.nio.channels.FileChannel) IOException(java.io.IOException) CompleteMultipartUploadResult(com.emc.object.s3.bean.CompleteMultipartUploadResult) Synchronized(lombok.Synchronized)

Example 10 with Synchronized

use of lombok.Synchronized in project pravega by pravega.

the class S3FileSystemImpl method putObject.

@Synchronized
@Override
public void putObject(String bucketName, String key, Range range, Object content) {
    Path path = Paths.get(this.baseDir, bucketName, key);
    try (FileChannel channel = FileChannel.open(path, StandardOpenOption.WRITE)) {
        long startOffset = range.getFirst();
        long length = range.getLast() + 1 - range.getFirst();
        do {
            long bytesTransferred = channel.transferFrom(Channels.newChannel((InputStream) content), range.getFirst(), range.getLast() + 1 - range.getFirst());
            length -= bytesTransferred;
            startOffset += bytesTransferred;
        } while (length > 0);
        AclSize aclKey = aclMap.get(key);
        aclMap.put(key, aclKey.withSize(range.getLast() + 1));
    } catch (IOException e) {
        throw new S3Exception("NoObject", 404, "NoSuchKey", key);
    }
}
Also used : Path(java.nio.file.Path) FileChannel(java.nio.channels.FileChannel) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) S3Exception(com.emc.object.s3.S3Exception) IOException(java.io.IOException) Synchronized(lombok.Synchronized)

Aggregations

Synchronized (lombok.Synchronized)22 IOException (java.io.IOException)6 Segment (io.pravega.client.segment.impl.Segment)4 ArrayList (java.util.ArrayList)4 S3Exception (com.emc.object.s3.S3Exception)3 CreateSegment (io.pravega.shared.protocol.netty.WireCommands.CreateSegment)3 DeleteSegment (io.pravega.shared.protocol.netty.WireCommands.DeleteSegment)3 ScheduledReporter (com.codahale.metrics.ScheduledReporter)2 Stream (io.pravega.client.stream.Stream)2 StreamImpl (io.pravega.client.stream.impl.StreamImpl)2 PravegaNodeUri (io.pravega.shared.protocol.netty.PravegaNodeUri)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 ByteBuffer (java.nio.ByteBuffer)2 FileChannel (java.nio.channels.FileChannel)2 Path (java.nio.file.Path)2 SneakyThrows (lombok.SneakyThrows)2 PersistentNode (org.apache.curator.framework.recipes.nodes.PersistentNode)2 ChainingMetadataResolver (org.opensaml.saml.metadata.resolver.ChainingMetadataResolver)2 JmxReporter (com.codahale.metrics.JmxReporter)1