public List<String> getArgs() { if (instanceGroup == null) { throw new AmazonServiceException("InstanceGroup must not be null."); } if (instanceCount == null) { throw new AmazonServiceException("InstanceCount must not be null."); } List<String> args = new ArrayList<String>(); args.add("--modify-instance-group"); args.add(instanceGroup); args.add("--instance-count"); args.add(Integer.toString(instanceCount)); return args; } }
public List<String> getArgs() { if (instanceGroup == null) { throw new AmazonServiceException("InstanceGroup must not be null."); } if (instanceCount == null) { throw new AmazonServiceException("InstanceCount must not be null."); } if (instanceType == null) { throw new AmazonServiceException("InstanceType must not be null."); } List<String> args = new ArrayList<String>(); args.add("--add-instance-group"); args.add(instanceGroup); args.add("--instance-count"); args.add(Integer.toString(instanceCount)); args.add("--instance-type"); args.add(instanceType); return args; } }
/** * Create an AmazonServiceException using the chain of unmarshallers. This method will never * return null, it will always return a valid AmazonServiceException * * @param errorCode * Error code to find an appropriate unmarshaller * @param jsonContent * JsonContent of HTTP response * @return AmazonServiceException */ private AmazonServiceException createException(String errorCode, JsonContent jsonContent) { AmazonServiceException ase = unmarshallException(errorCode, jsonContent); if (ase == null) { ase = new AmazonServiceException( "Unable to unmarshall exception response with the unmarshallers provided"); } return ase; }
private void handleErrorResponse(InputStream errorStream, int statusCode, String responseMessage) throws IOException { String errorCode = null; // Parse the error stream returned from the service. if(errorStream != null) { String errorResponse = IOUtils.toString(errorStream); try { JsonNode node = Jackson.jsonNodeOf(errorResponse); JsonNode code = node.get("code"); JsonNode message = node.get("message"); if (code != null && message != null) { errorCode = code.asText(); responseMessage = message.asText(); } } catch (Exception exception) { LOG.debug("Unable to parse error stream"); } } AmazonServiceException ase = new AmazonServiceException(responseMessage); ase.setStatusCode(statusCode); ase.setErrorCode(errorCode); throw ase; } }
/** * Creates the final HadoopJarStepConfig once you are done configuring the step. You can use * this as you would any other HadoopJarStepConfig. * @return HadoopJarStepConfig configured to perform the specified actions. */ public HadoopJarStepConfig toHadoopJarStepConfig() { if (args.size() == 0) { throw new AmazonServiceException("Cannot create a ResizeJobFlowStep with no resize actions."); } if (wait == false) { args.add("--no-wait"); } if (onArrested != null) { args.add("--on-arrested"); args.add(onArrested.toString()); } if (onFailure != null) { args.add("--on-failure"); args.add(onFailure.toString()); } return new HadoopJarStepConfig() .withJar("s3://" + bucket + "/libs/resize-job-flow/0.1/resize-job-flow.jar") .withArgs(args); }
@Mock public DeleteObjectsResult deleteObjects(DeleteObjectsRequest var1) throws SdkClientException, AmazonServiceException { if (emulateError) throw new AmazonServiceException("Unable to reach AWS"); return null; } }
static Exception convert(BatchResultErrorEntry be) { AmazonServiceException toReturn = new AmazonServiceException(be.getMessage()); toReturn.setErrorCode(be.getCode()); toReturn.setErrorType(be.isSenderFault() ? ErrorType.Client : ErrorType.Service); toReturn.setServiceName("AmazonSQS"); return toReturn; }
private AmazonServiceException handleAse(HttpResponse response) throws Exception { final int statusCode = response.getStatusCode(); try { return delegate.handle(response); } catch(InterruptedException e) { throw e; } catch (Exception e) { // If the errorResponseHandler doesn't work, then check for error responses that don't have any content if (statusCode == 413) { AmazonServiceException exception = new AmazonServiceException("Request entity too large"); exception.setServiceName(response.getRequest().getServiceName()); exception.setStatusCode(statusCode); exception.setErrorType(AmazonServiceException.ErrorType.Client); exception.setErrorCode("Request entity too large"); return exception; } else if (statusCode >= 500 && statusCode < 600) { AmazonServiceException exception = new AmazonServiceException(response.getStatusText()); exception.setServiceName(response.getRequest().getServiceName()); exception.setStatusCode(statusCode); exception.setErrorType(AmazonServiceException.ErrorType.Service); exception.setErrorCode(response.getStatusText()); return exception; } else { throw e; } } }
if (objectSummary.getStorageClass() != null && StorageClass.fromValue(StringUtils.toUpperCase(objectSummary.getStorageClass())).equals(StorageClass.Glacier)) { throw new AmazonServiceException( StringUtils.format( "Cannot move file[s3://%s/%s] of storage class glacier, skipping.",
@Override public AmazonServiceException unmarshall(JsonErrorResponse error) throws Exception { return new AmazonServiceException("TestException"); }
@Override public AmazonServiceException unmarshall(JsonErrorResponse error) throws Exception { return new AmazonServiceException("TestException"); }
private AmazonServiceException getServiceException(String errorCode) { AmazonServiceException ase = new AmazonServiceException("some error message"); ase.setErrorCode(errorCode); return ase; } }
private AmazonServiceException getServiceException(String errorCode) { AmazonServiceException ase = new AmazonServiceException("some error message"); ase.setErrorCode(errorCode); return ase; } }
@Override public AmazonServiceException unmarshall(Node in) throws Exception { called.add(true); in = in.getFirstChild(); assertEquals(in.getNodeName(), "error"); assertEquals( in.getTextContent(), "TestError"); AmazonServiceException ase = new AmazonServiceException("TestAse"); return ase; } };
static Exception convert(BatchResultErrorEntry be) { AmazonServiceException toReturn = new AmazonServiceException(be.getMessage()); toReturn.setErrorCode(be.getCode()); toReturn.setErrorType(be.isSenderFault() ? ErrorType.Client : ErrorType.Service); toReturn.setServiceName("AmazonSQS"); return toReturn; }
@Override public AmazonServiceException handle( com.amazonaws.http.HttpResponse response) throws Exception { AmazonServiceException ase = new AmazonServiceException("Fake service exception."); ase.setStatusCode(response.getStatusCode()); ase.setErrorCode(response.getStatusText()); return ase; }
@Override public AmazonServiceException handle(HttpResponse response) throws Exception { assertSame(response, httpResponse); AmazonServiceException ase = new AmazonServiceException("Test"); ase.setErrorCode("TestError"); ase.setErrorType(ErrorType.Service); ase.setServiceName(request.getServiceName()); ase.setStatusCode(response.getStatusCode()); return ase; }
@Test public void testClockskewOffsetWithDateInBodyOfException() { HttpResponse httpResponse = new HttpResponse.Builder().statusText("TestResponse") .statusCode(400).build(); AmazonServiceException ase = new AmazonServiceException("(20041106T084937Z - 15)"); // assert date is > 10 years int offset = client.parseClockSkewOffset(httpResponse, ase); assertTrue(offset > 315400000); }
@Test public void testClockskewOffsetWithBogusDateAsssumesOffsetIsZero() { HttpResponse httpResponse = new HttpResponse.Builder().statusText("TestResponse") .header("Date", "Sat, 064 Jann 20044 08:49:37 GMT") .statusCode(400).build(); AmazonServiceException ase = new AmazonServiceException("ClockSkew"); // assert date is > 10 years int offset = client.parseClockSkewOffset(httpResponse, ase); assertEquals(offset, 0); }
@Test public void testClockskewOffset() { HttpResponse httpResponse = new HttpResponse.Builder().statusText("TestResponse") .header("Date", "Sat, 06 Nov 2004 08:49:37 GMT") .statusCode(400).build(); AmazonServiceException ase = new AmazonServiceException("ClockSkew"); // assert date is > 10 years int offset = client.parseClockSkewOffset(httpResponse, ase); assertTrue(offset > 315400000); }