List of usage examples for com.amazonaws AmazonServiceException getErrorCode
public String getErrorCode()
From source file:org.apache.gora.dynamodb.store.DynamoDBStore.java
License:Apache License
/** * Waits up to 6 minutes to confirm if a table has been deleted or not * @param pTableName/*w w w .j av a2 s .c o m*/ */ private void waitForTableToBeDeleted(String pTableName) { LOG.debug("Waiting for " + pTableName + " to be deleted."); long startTime = System.currentTimeMillis(); long endTime = startTime + waitTime; while (System.currentTimeMillis() < endTime) { try { Thread.sleep(sleepDeleteTime); } catch (Exception e) { } try { DescribeTableRequest request = new DescribeTableRequest().withTableName(pTableName); TableDescription tableDescription = dynamoDBClient.describeTable(request).getTable(); String tableStatus = tableDescription.getTableStatus(); LOG.debug(pTableName + " - current state: " + tableStatus); } catch (AmazonServiceException ase) { if (ase.getErrorCode().equalsIgnoreCase("ResourceNotFoundException") == true) return; ase.printStackTrace(); } } LOG.debug(pTableName + " deleted."); }
From source file:org.apache.gora.dynamodb.store.DynamoDBStore.java
License:Apache License
/** * Waits up to 6 minutes to confirm if a table has been created or not * @param pTableName/* w w w. j av a 2 s . c o m*/ */ private void waitForTableToBecomeAvailable(String tableName) { LOG.debug("Waiting for " + tableName + " to become available"); long startTime = System.currentTimeMillis(); long endTime = startTime + waitTime; while (System.currentTimeMillis() < endTime) { try { Thread.sleep(sleepTime); } catch (Exception e) { } try { DescribeTableRequest request = new DescribeTableRequest().withTableName(tableName); TableDescription tableDescription = dynamoDBClient.describeTable(request).getTable(); String tableStatus = tableDescription.getTableStatus(); LOG.debug(tableName + " - current state: " + tableStatus); if (tableStatus.equals(TableStatus.ACTIVE.toString())) return; } catch (AmazonServiceException ase) { if (ase.getErrorCode().equalsIgnoreCase("ResourceNotFoundException") == false) throw ase; } } throw new RuntimeException("Table " + tableName + " never became active"); }
From source file:org.apache.gora.dynamodb.store.DynamoDBUtils.java
License:Apache License
/** * Waits up to 6 minutes to confirm if a table has been created or not * // ww w . j av a 2s . c o m * @param awsClient * @param tableName */ public static void waitForTableToBecomeAvailable(AmazonDynamoDB awsClient, String tableName) { LOG.debug("Waiting for {} to become available", tableName); long startTime = System.currentTimeMillis(); long endTime = startTime + WAIT_TIME; while (System.currentTimeMillis() < endTime) { try { Thread.sleep(SLEEP_TIME); } catch (Exception e) { } try { DescribeTableRequest request = new DescribeTableRequest().withTableName(tableName); TableDescription tableDescription = awsClient.describeTable(request).getTable(); String tableStatus = tableDescription.getTableStatus(); LOG.debug("{} - current state: {}", tableName, tableStatus); if (tableStatus.equals(TableStatus.ACTIVE.toString())) return; } catch (AmazonServiceException ase) { if (ase.getErrorCode().equalsIgnoreCase("ResourceNotFoundException") == false) throw ase; } } throw new RuntimeException("Table " + tableName + " never became active"); }
From source file:org.apache.hadoop.dynamodb.DynamoDBFibonacciRetryer.java
License:Open Source License
private void handleException(DateTime retryEndTime, Exception exception, Reporter reporter, PrintCounter retryCounter) {//from ww w. ja va2s . c o m DateTime currentTime = new DateTime(DateTimeZone.UTC); long maxDelay = retryEndTime.getMillis() - currentTime.getMillis(); if (verifyRetriableException(exception) && maxDelay > 0) { if (exception instanceof AmazonServiceException) { AmazonServiceException ase = (AmazonServiceException) exception; if (throttleErrorCodes.contains(ase.getErrorCode())) { // Retry exception } else if (internalErrorStatusCodes.contains(ase.getStatusCode())) { // Retry exception } else { throw new RuntimeException(exception); } } incrementRetryCounter(reporter, retryCounter); retryCount++; log.warn("Retry: " + retryCount + " Exception: " + exception); delayOp(maxDelay); } else { if (isShutdown) { log.warn("Retries exceeded and caught, but is shutdown so not throwing", exception); } else { log.error("Retries exceeded or non-retryable exception, throwing: " + exception); throw new RuntimeException(exception); } } }
From source file:org.apache.hadoop.fs.s3a.S3AFileSystem.java
License:Apache License
private void printAmazonServiceException(AmazonServiceException ase) { LOG.info("Caught an AmazonServiceException, which means your request made it " + "to Amazon S3, but was rejected with an error response for some reason."); LOG.info("Error Message: " + ase.getMessage()); LOG.info("HTTP Status Code: " + ase.getStatusCode()); LOG.info("AWS Error Code: " + ase.getErrorCode()); LOG.info("Error Type: " + ase.getErrorType()); LOG.info("Request ID: " + ase.getRequestId()); LOG.info("Class Name: " + ase.getClass().getName()); }
From source file:org.apache.hadoop.fs.s3a.S3AUtils.java
License:Apache License
/** * Get low level details of an amazon exception for logging; multi-line. * @param e exception/*from w w w . j av a2 s .c o m*/ * @return string details */ public static String stringify(AmazonServiceException e) { StringBuilder builder = new StringBuilder(String.format("%s: %s error %d: %s; %s%s%n", e.getErrorType(), e.getServiceName(), e.getStatusCode(), e.getErrorCode(), e.getErrorMessage(), (e.isRetryable() ? " (retryable)" : ""))); String rawResponseContent = e.getRawResponseContent(); if (rawResponseContent != null) { builder.append(rawResponseContent); } return builder.toString(); }
From source file:org.apache.nifi.processors.aws.dynamodb.AbstractDynamoDBProcessor.java
License:Apache License
protected List<FlowFile> processServiceException(final ProcessSession session, List<FlowFile> flowFiles, AmazonServiceException exception) { List<FlowFile> failedFlowFiles = new ArrayList<>(); for (FlowFile flowFile : flowFiles) { Map<String, String> attributes = new HashMap<>(); attributes.put(DYNAMODB_ERROR_EXCEPTION_MESSAGE, exception.getMessage()); attributes.put(DYNAMODB_ERROR_CODE, exception.getErrorCode()); attributes.put(DYNAMODB_ERROR_MESSAGE, exception.getErrorMessage()); attributes.put(DYNAMODB_ERROR_TYPE, exception.getErrorType().name()); attributes.put(DYNAMODB_ERROR_SERVICE, exception.getServiceName()); attributes.put(DYNAMODB_ERROR_RETRYABLE, Boolean.toString(exception.isRetryable())); attributes.put(DYNAMODB_ERROR_REQUEST_ID, exception.getRequestId()); attributes.put(DYNAMODB_ERROR_STATUS_CODE, Integer.toString(exception.getStatusCode())); attributes.put(DYNAMODB_ERROR_EXCEPTION_MESSAGE, exception.getMessage()); attributes.put(DYNAMODB_ERROR_RETRYABLE, Boolean.toString(exception.isRetryable())); flowFile = session.putAllAttributes(flowFile, attributes); failedFlowFiles.add(flowFile);/* w w w . j a v a 2s . co m*/ } return failedFlowFiles; }
From source file:org.apache.nifi.processors.aws.lambda.PutLambda.java
License:Apache License
/** * Populate exception attributes in the flow file * @param session process session//from w ww . j ava2 s .co m * @param flowFile the flow file * @param exception exception thrown during invocation * @return FlowFile the updated flow file */ private FlowFile populateExceptionAttributes(final ProcessSession session, FlowFile flowFile, final AmazonServiceException exception) { Map<String, String> attributes = new HashMap<>(); attributes.put(AWS_LAMBDA_EXCEPTION_MESSAGE, exception.getErrorMessage()); attributes.put(AWS_LAMBDA_EXCEPTION_ERROR_CODE, exception.getErrorCode()); attributes.put(AWS_LAMBDA_EXCEPTION_REQUEST_ID, exception.getRequestId()); attributes.put(AWS_LAMBDA_EXCEPTION_STATUS_CODE, Integer.toString(exception.getStatusCode())); if (exception.getCause() != null) attributes.put(AWS_LAMBDA_EXCEPTION_CAUSE, exception.getCause().getMessage()); attributes.put(AWS_LAMBDA_EXCEPTION_ERROR_TYPE, exception.getErrorType().toString()); attributes.put(AWS_LAMBDA_EXCEPTION_MESSAGE, exception.getErrorMessage()); flowFile = session.putAllAttributes(flowFile, attributes); return flowFile; }
From source file:org.apache.provisionr.amazon.activities.AllInstancesMatchPredicate.java
License:Apache License
@Override public void execute(AmazonEC2 client, Pool pool, DelegateExecution execution) { @SuppressWarnings("unchecked") Optional<List<String>> instanceIds = Optional .fromNullable((List<String>) execution.getVariable(ProcessVariables.INSTANCE_IDS)); if (!instanceIds.isPresent()) { LOG.warn("<< Process variable '{}' not found", ProcessVariables.INSTANCE_IDS); return;// www. j a v a 2s . c o m } else if (instanceIds.get().size() == 0) { LOG.info(">> No instances are currently registered in the process."); return; } try { DescribeInstancesResult result = client .describeInstances(new DescribeInstancesRequest().withInstanceIds(instanceIds.get())); List<Instance> instances = collectInstancesFromReservations(result.getReservations()); if (Iterables.all(instances, predicate)) { LOG.info(">> All {} instances match predicate {} ", instanceIds, predicate); execution.setVariable(resultVariable, true); } else { LOG.info("<< Not all instances {} match predicate {}", instanceIds, predicate); execution.setVariable(resultVariable, false); } } catch (AmazonServiceException exception) { if (exception.getErrorCode().equalsIgnoreCase("InvalidInstanceID.NotFound")) { LOG.warn("<< Got error InvalidInstanceID.NotFound. Assuming predicate {} is false", predicate); execution.setVariable(resultVariable, false); } else { throw Throwables.propagate(exception); } } }
From source file:org.apache.s4.serializer.dynamodb.EventCountAndReportPE.java
License:Apache License
public void onEvent(TopicEvent event) { if (firstEvent) { logger.info("Handling new Event [{}]", getId()); firstEvent = false;// w ww . j a v a 2 s . c o m firstInsert = true; } count += event.getCount(); // countUsedEvents++; // SB // logger.info("Used Data Events counter [{}]", countUsedEvents); // SB if (false) { // BEGINNING OF THE BLOCK!!!!!!!!!!! if (firstInsert) { firstInsert = false; try { // Data fusion config file: try { // File fusionPropsFile = new File(System.getProperty("user.home") + "/DataFusion.properties"); File fusionPropsFile = new File("/home/ec2-user/DataFusion.properties"); if (!fusionPropsFile.exists()) { fusionPropsFile = new File(System.getProperty("user.home") + "/DataFusion.properties"); if (!fusionPropsFile.exists()) { logger.error( "Cannot find Data fusion properties file in this location :[{}]. Make sure it is available at this place and includes AWS credentials (accessKey, secretKey)", fusionPropsFile.getAbsolutePath()); } } fusionProperties.load(new FileInputStream(fusionPropsFile)); accuracy = Double.parseDouble(fusionProperties.getProperty("accuracy")); confidence = Double.parseDouble(fusionProperties.getProperty("confidence")); } catch (Exception e) { logger.error("Cannot find Data fusion config file", e); } // Create and configure DynamoDB client AWSCredentials credentials = new BasicAWSCredentials(awsProperties.getProperty("accessKey"), awsProperties.getProperty("secretKey")); AmazonDynamoDBClient dynamoDBClient = new AmazonDynamoDBClient(credentials); logger.info("Create DynamoDB client"); dynamoDBClient.setEndpoint("dynamodb.eu-west-1.amazonaws.com"); logger.info("DynamoDB client credentials are accepted and endpoint selected"); // try { // Extracted context, e.g query, activity String searchQueryAPI = "Test KnowledgeDiscovery API Query"; String object = "Object detected"; Map<String, AttributeValue> itemRT = new HashMap<String, AttributeValue>(); Map<String, AttributeValue> itemDQ = new HashMap<String, AttributeValue>(); Iterable<String> dataSplit = Splitter.on(' ').omitEmptyStrings().trimResults().split(getId()); // List<String> dataList = Lists.newArrayList(Elements.getElements(dataSplit)); // String receivedMsgs = dataList.get(dataList.size()-1); // countReceivedMsgs = Integer.parseInt(receivedMsgs);; int i = 0; for (String token : dataSplit) { i++; receivedMsgs = token; } int k = 0; for (String token : dataSplit) { k++; if (k == (i - 2)) { receivedAppID = token; } else if (k == (i - 1)) { receivedUserID = token; } } appID = Double.parseDouble(receivedAppID); userID = Double.parseDouble(receivedUserID); // STUPID HARDCODE but fast for prototype, should change to class later :) if (appID == 0 && userID > 0) { // CV app and serialization table rtEventsTableName = "TableEventVector_CV"; tableDataQuality = "EventVectorQuality_CV"; db_orig = db_base_dir + "/cv.db"; countReceivedMsgs_CV = Integer.parseInt(receivedMsgs) - countReceivedMsgsPrev_CV; countReceivedMsgsPrev_CV = Integer.parseInt(receivedMsgs); countUsedMsgs_CV++; countReceivedMsgs = countReceivedMsgs_CV; countUsedMsgs = countUsedMsgs_CV; } else if (appID == 1 && userID > 0) { // NLP rtEventsTableName = "TableEventVector_NLP"; tableDataQuality = "EventVectorSetQuality_NLP"; db_orig = db_base_dir + "/nlp.db"; countReceivedMsgs_NLP = Integer.parseInt(receivedMsgs) - countReceivedMsgsPrev_NLP; countReceivedMsgsPrev_NLP = Integer.parseInt(receivedMsgs); countUsedMsgs_NLP++; countReceivedMsgs = countReceivedMsgs_NLP; countUsedMsgs = countUsedMsgs_NLP; } else if (appID == 2 && userID > 0) { // Audio rtEventsTableName = "TableEventVector_Audio"; tableDataQuality = "EventVectorQuality_Audio"; db_orig = db_base_dir + "/audio.db"; countReceivedMsgs_Audio = Integer.parseInt(receivedMsgs) - countReceivedMsgsPrev_Audio; countReceivedMsgsPrev_Audio = Integer.parseInt(receivedMsgs); countUsedMsgs_Audio++; countReceivedMsgs = countReceivedMsgs_Audio; countUsedMsgs = countUsedMsgs_Audio; } else { // all others Events available in DB rtEventsTableName = "TableEventVector"; tableDataQuality = "EventVectorQuality"; countReceivedMsgs = Integer.parseInt(receivedMsgs) - countReceivedMsgsPrev; countReceivedMsgsPrev = Integer.parseInt(receivedMsgs); countUsedMsgs++; } try { // Users database connection db_conn = DriverManager.getConnection("jdbc:sqlite:" + db_orig); //Actual invocation of Users DB without "rating" field db_stmt = db_conn.prepareStatement( "SELECT id, title, country, name, surname FROM user WHERE appID = ? AND userID = ?"); db_stmt.setDouble(1, userID); db_stmt.setDouble(2, appID); rs = db_stmt.executeQuery(); // Index updates/inserts String ID = rs.getString(1); String location = rs.getString(2); String country = rs.getString(3); String name = rs.getString(4); String surname = rs.getString(5); // resultSet adjustment according to the Accuracy and Confidence levels (1 / number of results and multiplied by 100%) accuracyRT = (1 / rs.getFetchSize()) * 100; confidence = sqrt(accuracyRT * accuracyRT + accuracy * accuracy); // Collect to DynamoDB items (CandidateSet and CandidateSetQuality) itemRT.put("id", new AttributeValue().withS(placesID)); itemRT.put("country", new AttributeValue().withS(country)); itemRT.put("name", new AttributeValue().withS(String.valueOf(lat))); itemRT.put("surname", new AttributeValue().withS(String.valueOf(lon))); itemRT.put("query", new AttributeValue().withS(searchQueryAPI)); itemRT.put("rating", new AttributeValue().withN(String.valueOf(count))); itemRT.put("title", new AttributeValue().withS(location)); itemRT.put("topic", new AttributeValue().withS(getId())); itemRT.put("event", new AttributeValue().withS(activity)); itemRT.put("ts", new AttributeValue().withS(dateFormatter.format(new Date()))); itemDQ.put("TimeStamp", new AttributeValue().withS(dateFormatter.format(new Date()))); itemDQ.put("ReceivedMsgs", new AttributeValue().withN(String.valueOf(countReceivedMsgs))); itemDQ.put("UsedMsgs", new AttributeValue().withN(String.valueOf(countUsedMsgs))); itemDQ.put("Accuracy", new AttributeValue().withN(String.valueOf(count))); itemDQ.put("Timeliness", new AttributeValue().withS(dateFormatter.format(new Date()))); itemDQ.put("Completeness", new AttributeValue().withN(String.valueOf(count))); itemDQ.put("Consistency", new AttributeValue().withN(String.valueOf(count))); itemDQ.put("Confidence", new AttributeValue().withN(String.valueOf(count))); itemDQ.put("Privacy", new AttributeValue().withS("anonymised")); PutItemRequest itemRequestRT = new PutItemRequest().withTableName(rtEventsTableName) .withItem(itemRT); PutItemRequest itemRequestDQ = new PutItemRequest().withTableName(tableDataQuality) .withItem(itemDQ); dynamoDBClient.putItem(itemRequestRT); dynamoDBClient.putItem(itemRequestDQ); itemRT.clear(); itemDQ.clear(); logger.info("TableEvent set size [{}], last known size [{}] ", countReceivedMsgs, countReceivedMsgsPrev); logger.info("Wrote EventVector to DynamoDB [{}] ", rtEventsTableName); logger.info("Wrote EventVector Quality measurements to DynamoDB [{}] ", tableDataQuality); // Closing second "try" } catch (Exception e) { // logger.error("Cannot close DB file", e); } finally { try { rs.close(); } catch (SQLException e) { logger.error("Cannot close ResultSet", e); } try { db_stmt.close(); } catch (SQLException e) { logger.error("Cannot close Statement", e); } try { db_conn.close(); } catch (SQLException e) { logger.error("Cannot close DB file", e); } } // Closing first "try" } catch (AmazonServiceException ase) { logger.error( "Caught an AmazonServiceException, which means your request made it to AWS, but was rejected with an error response for some reason."); logger.error("Error Message: " + ase.getMessage()); logger.error("HTTP Status Code: " + ase.getStatusCode()); logger.error("AWS Error Code: " + ase.getErrorCode()); logger.error("Error Type: " + ase.getErrorType()); logger.error("Request ID: " + ase.getRequestId()); } } // end of if (count == 1) } // END OF THE BLOCK !!!!!!!!!!!!!!! }