From 5f7072134f7516da381e5126ca0aaaac40276f77 Mon Sep 17 00:00:00 2001 From: Yegor Bugayenko Date: Tue, 23 Feb 2016 12:01:30 -0800 Subject: [PATCH] #72 more detailed exceptions --- src/main/java/com/jcabi/dynamo/AwsItem.java | 26 ++++++++++++++--- src/main/java/com/jcabi/dynamo/AwsTable.java | 29 +++++++++++++++---- .../java/com/jcabi/dynamo/QueryValve.java | 12 ++++++-- src/main/java/com/jcabi/dynamo/ScanValve.java | 12 ++++++-- 4 files changed, 64 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/jcabi/dynamo/AwsItem.java b/src/main/java/com/jcabi/dynamo/AwsItem.java index e514907..a167bc4 100644 --- a/src/main/java/com/jcabi/dynamo/AwsItem.java +++ b/src/main/java/com/jcabi/dynamo/AwsItem.java @@ -124,12 +124,18 @@ public boolean has(final String attr) throws IOException { final GetItemResult result = aws.getItem(request); has = result.getItem().get(attrib) != null; Logger.info( - this, "#has('%s'): %B from DynamoDB%s, in %[ms]s", + this, "#has('%s'): %B from DynamoDB, %s, in %[ms]s", attr, has, AwsTable.print(result.getConsumedCapacity()), System.currentTimeMillis() - start ); } catch (final AmazonClientException ex) { - throw new IOException(ex); + throw new IOException( + String.format( + "failed to check existence of \"%s\" at \"%s\" by %s", + attr, this.name, this.keys + ), + ex + ); } finally { aws.shutdown(); } @@ -161,7 +167,13 @@ public AttributeValue get(final String attr) throws IOException { System.currentTimeMillis() - start ); } catch (final AmazonClientException ex) { - throw new IOException(ex); + throw new IOException( + String.format( + "failed to get \"%s\" from \"%s\" by %s", + attr, this.name, this.keys + ), + ex + ); } finally { aws.shutdown(); } @@ -202,7 +214,13 @@ public Map put( ); return result.getAttributes(); } catch (final AmazonClientException ex) { - throw new IOException(ex); + throw new IOException( + String.format( + "failed to put %s into \"%s\" with %s", + attrs, this.name, this.keys + ), + ex + ); } finally { aws.shutdown(); } diff --git a/src/main/java/com/jcabi/dynamo/AwsTable.java b/src/main/java/com/jcabi/dynamo/AwsTable.java index 81434f4..673a75d 100644 --- a/src/main/java/com/jcabi/dynamo/AwsTable.java +++ b/src/main/java/com/jcabi/dynamo/AwsTable.java @@ -108,7 +108,7 @@ public Item put(final Map attributes) final PutItemResult result = aws.putItem(request); final long start = System.currentTimeMillis(); Logger.info( - this, "#put('%[text]s'): created item in '%s'%s, in %[ms]s", + this, "#put('%[text]s'): created item in '%s', %s, in %[ms]s", attributes, this.self, AwsTable.print(result.getConsumedCapacity()), System.currentTimeMillis() - start @@ -121,7 +121,13 @@ public Item put(final Map attributes) new Array(this.keys()) ); } catch (final AmazonClientException ex) { - throw new IOException(ex); + throw new IOException( + String.format( + "failed to put into \"%s\" with %s", + this.self, attributes + ), + ex + ); } finally { aws.shutdown(); } @@ -166,7 +172,13 @@ public Collection keys() throws IOException { ); return keys; } catch (final AmazonClientException ex) { - throw new IOException(ex); + throw new IOException( + String.format( + "failed to describe \"%s\"", + this.self + ), + ex + ); } finally { aws.shutdown(); } @@ -201,13 +213,20 @@ public void delete(final Map attributes) final DeleteItemResult result = aws.deleteItem(request); final long start = System.currentTimeMillis(); Logger.info( - this, "#delete('%[text]s'): deleted item in '%s'%s, in %[ms]s", + this, + "#delete('%[text]s'): deleted item in '%s', %s, in %[ms]s", attributes, this.self, AwsTable.print(result.getConsumedCapacity()), System.currentTimeMillis() - start ); } catch (final AmazonClientException ex) { - throw new IOException(ex); + throw new IOException( + String.format( + "failed to delete at \"%s\" by keys %s", + this.self, attributes + ), + ex + ); } finally { aws.shutdown(); } diff --git a/src/main/java/com/jcabi/dynamo/QueryValve.java b/src/main/java/com/jcabi/dynamo/QueryValve.java index 5ab3fc8..0158459 100644 --- a/src/main/java/com/jcabi/dynamo/QueryValve.java +++ b/src/main/java/com/jcabi/dynamo/QueryValve.java @@ -157,14 +157,20 @@ public Dosage fetch(final Credentials credentials, final String table, final QueryResult result = aws.query(request); Logger.info( this, - "#items(): loaded %d item(s) from '%s' using %s%s, in %[ms]s", + "#items(): loaded %d item(s) from '%s' using %s, %s, in %[ms]s", result.getCount(), table, conditions, AwsTable.print(result.getConsumedCapacity()), System.currentTimeMillis() - start ); return new QueryValve.NextDosage(credentials, request, result); } catch (final AmazonClientException ex) { - throw new IOException(ex); + throw new IOException( + String.format( + "failed to fetch from \"%s\" by %s and %s", + table, conditions, keys + ), + ex + ); } finally { aws.shutdown(); } @@ -342,7 +348,7 @@ public Dosage next() { Logger.info( this, // @checkstyle LineLength (1 line) - "#next(): loaded %d item(s) from '%s' using %s%s, in %[ms]s", + "#next(): loaded %d item(s) from '%s' using %s, %s, in %[ms]s", rslt.getCount(), rqst.getTableName(), rqst.getKeyConditions(), AwsTable.print(rslt.getConsumedCapacity()), diff --git a/src/main/java/com/jcabi/dynamo/ScanValve.java b/src/main/java/com/jcabi/dynamo/ScanValve.java index 13f72b1..d09a807 100644 --- a/src/main/java/com/jcabi/dynamo/ScanValve.java +++ b/src/main/java/com/jcabi/dynamo/ScanValve.java @@ -113,14 +113,20 @@ public Dosage fetch(final Credentials credentials, final ScanResult result = aws.scan(request); Logger.info( this, - "#items(): loaded %d item(s) from '%s' using %s%s, in %[ms]s", + "#items(): loaded %d item(s) from '%s' using %s, %s, in %[ms]s", result.getCount(), table, conditions, AwsTable.print(result.getConsumedCapacity()), System.currentTimeMillis() - start ); return new ScanValve.NextDosage(credentials, request, result); } catch (final AmazonClientException ex) { - throw new IOException(ex); + throw new IOException( + String.format( + "failed to fetch from \"%s\" by %s and %s", + table, conditions, keys + ), + ex + ); } finally { aws.shutdown(); } @@ -221,7 +227,7 @@ public Dosage next() { Logger.info( this, // @checkstyle LineLength (1 line) - "#next(): loaded %d item(s) from '%s' using %s%s, in %[ms]s", + "#next(): loaded %d item(s) from '%s' using %s, %s, in %[ms]s", rslt.getCount(), rqst.getTableName(), rqst.getScanFilter(), AwsTable.print(rslt.getConsumedCapacity()), System.currentTimeMillis() - start