# IGNITE-414: More precise exceptions.

Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/8cd807ac
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/8cd807ac
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/8cd807ac

Branch: refs/heads/ignite-414
Commit: 8cd807acf01245aca2f4a719ee1fbbbfdcd1c33b
Parents: c24583c
Author: vozerov-gridgain <voze...@gridgain.com>
Authored: Tue Mar 10 15:14:33 2015 +0300
Committer: vozerov-gridgain <voze...@gridgain.com>
Committed: Tue Mar 10 15:14:33 2015 +0300

----------------------------------------------------------------------
 .../igfs/IgfsPathIsDirectoryException.java      | 56 ++++++++++++++++++++
 .../igfs/IgfsPathIsNotDirectoryException.java   | 56 ++++++++++++++++++++
 .../internal/processors/igfs/IgfsImpl.java      | 18 +++----
 .../processors/igfs/IgfsMetaManager.java        | 22 ++++----
 4 files changed, 133 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8cd807ac/modules/core/src/main/java/org/apache/ignite/igfs/IgfsPathIsDirectoryException.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/igfs/IgfsPathIsDirectoryException.java
 
b/modules/core/src/main/java/org/apache/ignite/igfs/IgfsPathIsDirectoryException.java
new file mode 100644
index 0000000..4892ee8
--- /dev/null
+++ 
b/modules/core/src/main/java/org/apache/ignite/igfs/IgfsPathIsDirectoryException.java
@@ -0,0 +1,56 @@
+/*
+ * 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.ignite.igfs;
+
+import org.jetbrains.annotations.*;
+
+/**
+ * Exception indicating that path is directory, while it is expected to be a 
file.
+ */
+public class IgfsPathIsDirectoryException extends IgfsException {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /**
+     * Constructor.
+     *
+     * @param msg Message.
+     */
+    public IgfsPathIsDirectoryException(String msg) {
+        super(msg);
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param cause Cause.
+     */
+    public IgfsPathIsDirectoryException(Throwable cause) {
+        super(cause);
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param msg   Message.
+     * @param cause Cause.
+     */
+    public IgfsPathIsDirectoryException(@Nullable String msg, @Nullable 
Throwable cause) {
+        super(msg, cause);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8cd807ac/modules/core/src/main/java/org/apache/ignite/igfs/IgfsPathIsNotDirectoryException.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/igfs/IgfsPathIsNotDirectoryException.java
 
b/modules/core/src/main/java/org/apache/ignite/igfs/IgfsPathIsNotDirectoryException.java
new file mode 100644
index 0000000..d4b5ff9
--- /dev/null
+++ 
b/modules/core/src/main/java/org/apache/ignite/igfs/IgfsPathIsNotDirectoryException.java
@@ -0,0 +1,56 @@
+/*
+ * 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.ignite.igfs;
+
+import org.jetbrains.annotations.*;
+
+/**
+ * Exception indicating that path is not directory.
+ */
+public class IgfsPathIsNotDirectoryException extends IgfsException {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /**
+     * Constructor.
+     *
+     * @param msg Message.
+     */
+    public IgfsPathIsNotDirectoryException(String msg) {
+        super(msg);
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param cause Cause.
+     */
+    public IgfsPathIsNotDirectoryException(Throwable cause) {
+        super(cause);
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param msg   Message.
+     * @param cause Cause.
+     */
+    public IgfsPathIsNotDirectoryException(@Nullable String msg, @Nullable 
Throwable cause) {
+        super(msg, cause);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8cd807ac/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsImpl.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsImpl.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsImpl.java
index abbfe1e..6c12b0b 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsImpl.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsImpl.java
@@ -654,7 +654,7 @@ public final class IgfsImpl implements IgfsEx {
 
                 // Cannot rename root directory.
                 if (src.parent() == null)
-                    throw new IgfsInvalidPathException("Failed to rename root 
directory.");
+                    throw new IgfsInvalidPathException("Root directory cannot 
be renamed.");
 
                 // Cannot move directory of upper level to self sub-dir.
                 if (dest.isSubDirectoryOf(src))
@@ -1120,7 +1120,7 @@ public final class IgfsImpl implements IgfsEx {
                 }
 
                 if (!info.isFile())
-                    throw new IgfsInvalidPathException("Failed to open file 
(not a file): " + path);
+                    throw new IgfsPathIsDirectoryException("Failed to open 
file (not a file): " + path);
 
                 // Input stream to read data from grid cache with separate 
blocks.
                 IgfsEventAwareInputStream os = new 
IgfsEventAwareInputStream(igfsCtx, path, info,
@@ -1227,7 +1227,7 @@ public final class IgfsImpl implements IgfsEx {
                 IgniteUuid parentId = ids.size() >= 2 ? ids.get(ids.size() - 
2) : null;
 
                 if (parentId == null)
-                    throw new IgfsInvalidPathException("Failed to resolve 
parent directory: " + path);
+                    throw new IgfsPathNotFoundException("Failed to resolve 
parent directory: " + parent);
 
                 String fileName = path.name();
 
@@ -1305,7 +1305,7 @@ public final class IgfsImpl implements IgfsEx {
 
                 IgfsMode mode = modeRslvr.resolveMode(path);
 
-                IgfsFileWorkerBatch batch = null;
+                IgfsFileWorkerBatch batch;
 
                 if (mode == PROXY)
                     throw new IgniteException("PROXY mode cannot be used in 
IGFS directly: " + path);
@@ -1337,7 +1337,7 @@ public final class IgfsImpl implements IgfsEx {
                     }
 
                     if (parentId == null)
-                        throw new IgfsInvalidPathException("Failed to resolve 
parent directory: " + path);
+                        throw new IgfsPathNotFoundException("Failed to resolve 
parent directory: " + path.parent());
 
                     info = new IgfsFileInfo(cfg.getBlockSize(), /**affinity 
key*/null, evictExclude(path, true), props);
 
@@ -1353,7 +1353,7 @@ public final class IgfsImpl implements IgfsEx {
                 assert info != null;
 
                 if (!info.isFile())
-                    throw new IgfsInvalidPathException("Failed to open file 
(not a file): " + path);
+                    throw new IgfsPathIsDirectoryException("Failed to open 
file (not a file): " + path);
 
                 info = meta.lock(info.id());
 
@@ -1361,7 +1361,7 @@ public final class IgfsImpl implements IgfsEx {
                     evts.record(new IgfsEvent(path, localNode(), 
EVT_IGFS_FILE_OPENED_WRITE));
 
                 return new IgfsEventAwareOutputStream(path, info, parentId, 
bufSize == 0 ?
-                    cfg.getStreamBufferSize() : bufSize, mode, batch);
+                    cfg.getStreamBufferSize() : bufSize, mode, null);
             }
             catch (IgniteCheckedException e) {
                 throw U.convertException(e);
@@ -1460,8 +1460,8 @@ public final class IgfsImpl implements IgfsEx {
                     throw new IgfsPathNotFoundException("File not found: " + 
path);
 
                 if (!info.isFile())
-                    throw new IgfsInvalidPathException("Failed to get affinity 
info for file (not a file): " +
-                        path);
+                    throw new IgfsPathIsDirectoryException("Failed to get 
affinity for path because it is not " +
+                        "a file: " + path);
 
                 return data.affinity(info, start, len, maxLen);
             }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8cd807ac/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsMetaManager.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsMetaManager.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsMetaManager.java
index cbc20d6..2ad10d5 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsMetaManager.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsMetaManager.java
@@ -742,7 +742,7 @@ public class IgfsMetaManager extends IgfsManager {
             throw fsException(new IgfsPathNotFoundException("Failed to lock 
parent directory (not found): " + parentId));
 
         if (!parentInfo.isDirectory())
-            throw fsException(new IgfsInvalidPathException("Parent file is not 
a directory: " + parentInfo));
+            throw fsException(new IgfsPathIsNotDirectoryException("Parent file 
is not a directory: " + parentInfo));
 
         Map<String, IgfsListingEntry> parentListing = parentInfo.listing();
 
@@ -843,7 +843,7 @@ public class IgfsMetaManager extends IgfsManager {
                 " [srcParentId=" + srcParentId + ']'));
 
         if (!srcInfo.isDirectory())
-            throw fsException(new IgfsInvalidPathException("Source is not a 
directory: " + srcInfo));
+            throw fsException(new IgfsPathIsNotDirectoryException("Source is 
not a directory: " + srcInfo));
 
         IgfsFileInfo destInfo = infoMap.get(destParentId);
 
@@ -852,7 +852,7 @@ public class IgfsMetaManager extends IgfsManager {
                 " [destParentId=" + destParentId + ']'));
 
         if (!destInfo.isDirectory())
-            throw fsException(new IgfsInvalidPathException("Destination is not 
a directory: " + destInfo));
+            throw fsException(new IgfsPathIsNotDirectoryException("Destination 
is not a directory: " + destInfo));
 
         IgfsFileInfo fileInfo = infoMap.get(fileId);
 
@@ -871,8 +871,8 @@ public class IgfsMetaManager extends IgfsManager {
 
         // If stored file already exist.
         if (destEntry != null)
-            throw fsException(new IgfsInvalidPathException("Failed to add file 
name into the destination directory " +
-                "(file already exists) [fileId=" + fileId + ", destFileName=" 
+ destFileName +
+            throw fsException(new IgfsPathAlreadyExistsException("Failed to 
add file name into the destination " +
+                " directory (file already exists) [fileId=" + fileId + ", 
destFileName=" + destFileName +
                 ", destParentId=" + destParentId + ", destEntry=" + destEntry 
+ ']'));
 
         assert metaCache.get(srcParentId) != null;
@@ -1846,7 +1846,8 @@ public class IgfsMetaManager extends IgfsManager {
 
                 if (info != null) {
                     if (!info.isFile())
-                        throw fsException(new IgfsInvalidPathException("Failed 
to open file (not a file): " + path));
+                        throw fsException(new 
IgfsPathIsDirectoryException("Failed to open file (not a file): " +
+                            path));
 
                     return new IgfsSecondaryInputStreamDescriptor(info, 
fs.open(path, bufSize));
                 }
@@ -1861,7 +1862,8 @@ public class IgfsMetaManager extends IgfsManager {
                             if (info == null)
                                 throw fsException(new 
IgfsPathNotFoundException("File not found: " + path));
                             if (!info.isFile())
-                                throw fsException(new 
IgfsInvalidPathException("Failed to open file (not a file): " + path));
+                                throw fsException(new 
IgfsPathIsDirectoryException("Failed to open file " +
+                                    "(not a file): " + path));
 
                             return new 
IgfsSecondaryInputStreamDescriptor(infos.get(path), fs.open(path, bufSize));
                         }
@@ -2617,14 +2619,14 @@ public class IgfsMetaManager extends IgfsManager {
                     IgfsFileInfo parentInfo = infoMap.get(parentId);
 
                     if (parentInfo == null)
-                        throw fsException(new IgfsInvalidPathException("Failed 
to update times " +
-                                "(parent was not found): " + fileName));
+                        throw fsException(new 
IgfsPathNotFoundException("Failed to update times " +
+                            "(parent was not found): " + fileName));
 
                     IgfsListingEntry entry = 
parentInfo.listing().get(fileName);
 
                     // Validate listing.
                     if (entry == null || !entry.fileId().equals(fileId))
-                        throw fsException(new IgfsInvalidPathException("Failed 
to update times " +
+                        throw fsException(new 
IgfsConcurrentModificationException("Failed to update times " +
                                 "(file concurrently modified): " + fileName));
 
                     assert parentInfo.isDirectory();

Reply via email to