garydgregory commented on a change in pull request #85: URL: https://github.com/apache/commons-vfs/pull/85#discussion_r421752943
########## File path: commons-vfs2-zookeeper/src/main/java/org/apache/commons/vfs2/provider/zookeeper/ZkFileObject.java ########## @@ -0,0 +1,124 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.commons.vfs2.provider.zookeeper; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.List; +import java.util.Objects; + +import org.apache.commons.vfs2.FileSystemException; +import org.apache.commons.vfs2.FileType; +import org.apache.commons.vfs2.provider.AbstractFileName; +import org.apache.commons.vfs2.provider.AbstractFileObject; +import org.apache.commons.vfs2.provider.UriParser; +import org.apache.curator.framework.CuratorFramework; +import org.apache.zookeeper.data.Stat; + +public class ZkFileObject extends AbstractFileObject<ZkFileSystem> { Review comment: Public elements need Javadocs. ########## File path: commons-vfs2-zookeeper/src/main/java/org/apache/commons/vfs2/provider/zookeeper/ZkFileObject.java ########## @@ -0,0 +1,124 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.commons.vfs2.provider.zookeeper; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.List; +import java.util.Objects; + +import org.apache.commons.vfs2.FileSystemException; +import org.apache.commons.vfs2.FileType; +import org.apache.commons.vfs2.provider.AbstractFileName; +import org.apache.commons.vfs2.provider.AbstractFileObject; +import org.apache.commons.vfs2.provider.UriParser; +import org.apache.curator.framework.CuratorFramework; +import org.apache.zookeeper.data.Stat; + +public class ZkFileObject extends AbstractFileObject<ZkFileSystem> { + + private CuratorFramework framework; + private String path; + private Stat stat; + + protected ZkFileObject(final AbstractFileName name, + final ZkFileSystem fileSystem, final CuratorFramework framework, + final String path) { + super(name, fileSystem); + this.framework = Objects.requireNonNull(framework); + this.path = Objects.requireNonNull(path); + } + + @Override + protected long doGetContentSize() throws Exception { + return this.stat.getDataLength(); + } + + @Override + protected InputStream doGetInputStream() throws Exception { + if (this.stat == null) { + throw new FileSystemException("vfs.provider/read-not-file.error", + getName()); + } + + final byte[] data = (this.stat.getDataLength() == 0) ? new byte[0] Review comment: Extra ()'s are superfluous. ########## File path: commons-vfs2-zookeeper/src/main/java/org/apache/commons/vfs2/provider/zookeeper/ZkFileProvider.java ########## @@ -0,0 +1,99 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.commons.vfs2.provider.zookeeper; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; + +import org.apache.commons.lang3.ArrayUtils; +import org.apache.commons.vfs2.Capability; +import org.apache.commons.vfs2.FileName; +import org.apache.commons.vfs2.FileSystem; +import org.apache.commons.vfs2.FileSystemException; +import org.apache.commons.vfs2.FileSystemOptions; +import org.apache.commons.vfs2.provider.AbstractOriginatingFileProvider; +import org.apache.curator.RetryPolicy; +import org.apache.curator.framework.CuratorFramework; +import org.apache.curator.framework.CuratorFrameworkFactory; +import org.apache.curator.framework.CuratorFrameworkFactory.Builder; + +public class ZkFileProvider extends AbstractOriginatingFileProvider { Review comment: Missing Javadoc. ########## File path: commons-vfs2-zookeeper/src/main/java/org/apache/commons/vfs2/provider/zookeeper/ZkFileProvider.java ########## @@ -0,0 +1,99 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.commons.vfs2.provider.zookeeper; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; + +import org.apache.commons.lang3.ArrayUtils; +import org.apache.commons.vfs2.Capability; +import org.apache.commons.vfs2.FileName; +import org.apache.commons.vfs2.FileSystem; +import org.apache.commons.vfs2.FileSystemException; +import org.apache.commons.vfs2.FileSystemOptions; +import org.apache.commons.vfs2.provider.AbstractOriginatingFileProvider; +import org.apache.curator.RetryPolicy; +import org.apache.curator.framework.CuratorFramework; +import org.apache.curator.framework.CuratorFrameworkFactory; +import org.apache.curator.framework.CuratorFrameworkFactory.Builder; + +public class ZkFileProvider extends AbstractOriginatingFileProvider { + static final Collection<Capability> CAPABILITIES = + Collections.unmodifiableCollection(Arrays.asList(Capability.GET_TYPE, + Capability.READ_CONTENT, Capability.URI, Capability.WRITE_CONTENT, + Capability.DIRECTORY_READ_CONTENT, Capability.LIST_CHILDREN)); + + public ZkFileProvider() { Review comment: Not needed as explicit since all it does it call super(). ########## File path: commons-vfs2-zookeeper/src/main/java/org/apache/commons/vfs2/provider/zookeeper/ZkFileSystem.java ########## @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.commons.vfs2.provider.zookeeper; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; +import java.util.Collection; +import java.util.Objects; + +import org.apache.commons.vfs2.Capability; +import org.apache.commons.vfs2.FileName; +import org.apache.commons.vfs2.FileObject; +import org.apache.commons.vfs2.FileSystemException; +import org.apache.commons.vfs2.FileSystemOptions; +import org.apache.commons.vfs2.provider.AbstractFileName; +import org.apache.commons.vfs2.provider.AbstractFileSystem; +import org.apache.curator.framework.CuratorFramework; + +public class ZkFileSystem extends AbstractFileSystem { + + private CuratorFramework framework; + private boolean ownsClient = false; + + protected ZkFileSystem(final FileName rootName, + final CuratorFramework framework, + final FileSystemOptions fileSystemOptions) { + super(rootName, null, fileSystemOptions); + this.framework = Objects.requireNonNull(framework); + this.ownsClient = ZkFileSystemConfigBuilder.getInstance() + .getOwnsClient(fileSystemOptions); + } + + @Override + protected void doCloseCommunicationLink() { + if (framework != null && ownsClient) { + framework.close(); + framework = null; + } + } + + @Override + protected FileObject createFile(AbstractFileName name) throws Exception { + return null; + } + + /** + * Resolve FileName into FileObject. + * + * @param name The name of a file on the HdfsFileSystem. + * @return resolved FileObject. + * @throws FileSystemException if an error occurred. + */ + @Override + public FileObject resolveFile(final FileName name) + throws FileSystemException { + final boolean useCache = + null != getContext().getFileSystemManager().getFilesCache(); + + FileObject fileObject = null; + if (useCache) { + fileObject = getFileFromCache(name); + } + + if (fileObject == null) { + String path = null; + try { + path = URLDecoder.decode(name.getPath(), StandardCharsets.UTF_8.name()); + } catch (final UnsupportedEncodingException e) { + path = name.getPath(); + } + fileObject = + new ZkFileObject((AbstractFileName) name, this, framework, path); + } + if (useCache) { + this.putFileToCache(fileObject); + } + return fileObject; + } + + @Override + protected void addCapabilities(Collection<Capability> caps) { Review comment: No need for weird abbreviations: `caps` -> `capabilities` ########## File path: commons-vfs2-zookeeper/src/main/java/org/apache/commons/vfs2/provider/zookeeper/ZkFileProvider.java ########## @@ -0,0 +1,99 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.commons.vfs2.provider.zookeeper; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; + +import org.apache.commons.lang3.ArrayUtils; +import org.apache.commons.vfs2.Capability; +import org.apache.commons.vfs2.FileName; +import org.apache.commons.vfs2.FileSystem; +import org.apache.commons.vfs2.FileSystemException; +import org.apache.commons.vfs2.FileSystemOptions; +import org.apache.commons.vfs2.provider.AbstractOriginatingFileProvider; +import org.apache.curator.RetryPolicy; +import org.apache.curator.framework.CuratorFramework; +import org.apache.curator.framework.CuratorFrameworkFactory; +import org.apache.curator.framework.CuratorFrameworkFactory.Builder; + +public class ZkFileProvider extends AbstractOriginatingFileProvider { + static final Collection<Capability> CAPABILITIES = + Collections.unmodifiableCollection(Arrays.asList(Capability.GET_TYPE, + Capability.READ_CONTENT, Capability.URI, Capability.WRITE_CONTENT, + Capability.DIRECTORY_READ_CONTENT, Capability.LIST_CHILDREN)); + + public ZkFileProvider() { + super(); + } + + @Override + protected FileSystem doCreateFileSystem(FileName rootName, + FileSystemOptions fileSystemOptions) throws FileSystemException { + ZkFileSystemConfigBuilder configBuilder = + ZkFileSystemConfigBuilder.getInstance(); + + // did the caller provide a curator framework? + CuratorFramework framework = + configBuilder.getCuratorFramework(fileSystemOptions); + if (framework == null) { + String connectionString = + configBuilder.getZkConnectionSring(fileSystemOptions); + RetryPolicy retryPolicy = configBuilder.getRetryPolicy(fileSystemOptions); + String namespace = configBuilder.getZkNamespace(fileSystemOptions); + int connectionTimeout = Review comment: Please set your line length to 120 and reformat all; see `/commons-vfs2-project/checkstyle.properties` ########## File path: commons-vfs2-zookeeper/src/main/java/org/apache/commons/vfs2/provider/zookeeper/ZkFileSystem.java ########## @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.commons.vfs2.provider.zookeeper; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; +import java.util.Collection; +import java.util.Objects; + +import org.apache.commons.vfs2.Capability; +import org.apache.commons.vfs2.FileName; +import org.apache.commons.vfs2.FileObject; +import org.apache.commons.vfs2.FileSystemException; +import org.apache.commons.vfs2.FileSystemOptions; +import org.apache.commons.vfs2.provider.AbstractFileName; +import org.apache.commons.vfs2.provider.AbstractFileSystem; +import org.apache.curator.framework.CuratorFramework; + +public class ZkFileSystem extends AbstractFileSystem { + + private CuratorFramework framework; Review comment: Make all ivars final if they can be final. ########## File path: commons-vfs2-zookeeper/src/main/java/org/apache/commons/vfs2/provider/zookeeper/ZkFileSystemConfigBuilder.java ########## @@ -0,0 +1,176 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.commons.vfs2.provider.zookeeper; + +import org.apache.commons.vfs2.FileSystem; +import org.apache.commons.vfs2.FileSystemConfigBuilder; +import org.apache.commons.vfs2.FileSystemOptions; +import org.apache.curator.RetryPolicy; +import org.apache.curator.framework.CuratorFramework; +import org.apache.curator.retry.ExponentialBackoffRetry; + +public class ZkFileSystemConfigBuilder extends FileSystemConfigBuilder { Review comment: Add Javadoc for everything public. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
