List of usage examples for com.amazonaws AmazonServiceException getErrorCode
public String getErrorCode()
From source file:jp.primecloud.auto.aws.wrapper.ExceptionHandleAwsClientWrapper.java
License:Open Source License
protected AutoException handleException(AmazonServiceException exception, Method method, Object[] args) { Object request = null;//from ww w . ja v a 2 s. c o m if (method.getParameterTypes().length > 0) { request = args[0]; } // UserData?????????? if (request instanceof RunInstancesRequest) { ((RunInstancesRequest) request).setUserData(null); } String str = StringUtils.reflectToString(request); return new AutoException("EAWS-000003", exception, method.getName(), exception.getErrorCode(), exception.getMessage(), str); }
From source file:main.java.ddb.loader.DDBLoaderUtils.java
License:Apache License
static void createTable() throws Exception { try {/*from w w w .ja v a2 s . co m*/ CreateTableRequest create_req = new CreateTableRequest().withTableName(DDBSampleLoader.TBL_NAME) .withKeySchema(new KeySchemaElement().withAttributeName("Id").withKeyType(KeyType.HASH)) .withAttributeDefinitions(new AttributeDefinition().withAttributeName("Id") .withAttributeType(ScalarAttributeType.S)) .withProvisionedThroughput( new ProvisionedThroughput().withReadCapacityUnits(DDBSampleLoader.RCU) .withWriteCapacityUnits(DDBSampleLoader.WCU)); DDBSampleLoader.log.info("Creating a new table ..."); TableUtils.createTableIfNotExists(DDBSampleLoader.ddb_client, create_req); DDBSampleLoader.log.info("Waiting for the table status to be 'ACTIVE' ..."); TableUtils.waitUntilActive(DDBSampleLoader.ddb_client, DDBSampleLoader.TBL_NAME); } catch (AmazonServiceException e) { DDBSampleLoader.log.error("Caught an AmazonServiceException ..."); DDBSampleLoader.log.error("Error Message: " + e.getMessage()); DDBSampleLoader.log.error("HTTP Status Code: " + e.getStatusCode()); DDBSampleLoader.log.error("AWS Error Code: " + e.getErrorCode()); DDBSampleLoader.log.error("Error Type: " + e.getErrorType()); DDBSampleLoader.log.error("Request ID: " + e.getRequestId()); } catch (AmazonClientException e) { DDBSampleLoader.log.error("Caught an AmazonClientException ..."); DDBSampleLoader.log.error("Error Message: " + e.getMessage()); } }
From source file:modules.storage.AmazonS3Storage.java
License:Open Source License
private void logAmazonServiceException(AmazonServiceException ase) { logger.error("Caught an AmazonServiceException, which " + "means your request made it " + "to Amazon S3, but was rejected with an error response " + "for some reason." + " Error Message: " + ase.getMessage() + " HTTP Status Code: " + ase.getStatusCode() + " AWS Error Code: " + ase.getErrorCode() + " Error Type: " + ase.getErrorType() + " Request ID: " + ase.getRequestId(), ase);//from ww w . j a va 2 s .c o m }
From source file:n3phele.factory.ec2.VirtualServerResource.java
License:Open Source License
/** * Updates virtual server object and data store state * //from w w w. j a v a2 s .c om * @param item * object to update * @param reference * reference UUID used for notifications * @param sequence * notification sequence number */ private void updateVirtualServer(VirtualServer item, UUID reference, int sequence) throws IllegalArgumentException { AmazonEC2Client client = null; client = getEC2Client(item.getAccessKey(), item.getEncryptedKey(), item.getLocation()); String instanceId = item.getInstanceId(); boolean madeIntoZombie = item.isZombie(); if (!madeIntoZombie && (instanceId == null || instanceId.length() == 0)) { String spotId = item.getSpotId(); if (spotId == null || spotId.length() == 0) { if ("Initializing".equals(item.getStatus())) { // Update has been called on an item under construction -- // ignore log.warning("Ignoring partially formed item " + item.getUri()); return; } else { log.severe("Improper item " + item); } } DescribeSpotInstanceRequestsResult update = null; try { update = client.describeSpotInstanceRequests( new DescribeSpotInstanceRequestsRequest().withSpotInstanceRequestIds(spotId)); } catch (AmazonServiceException e) { log.log(Level.WARNING, "EC2 error " + e.getErrorCode(), e); throw new WebApplicationException(e, Status.BAD_REQUEST); } instanceId = update.getSpotInstanceRequests().get(0).getInstanceId(); item.setInstanceId(instanceId); // // After cleaning up an object, we leave it around with status == // TERMINATED // for one refresh so that others can see the state chance via // polling. // If we come across an object with state terminated, and the // underlying object // is canceled or closed, then this is the second time the item has // been // refreshed, so now we remove the object. // if ((instanceId == null || instanceId.length() == 0) // pure spot // request && item.getStatus().equals(InstanceStateName.Terminated.toString()) && (update.getSpotInstanceRequests().get(0).getState().equals("cancelled") || update.getSpotInstanceRequests().get(0).getState().equals("closed"))) { delete(item); return; } updateStatus(item, update.getSpotInstanceRequests().get(0).getState(), reference, sequence); update(item); if (item.getStatus().equals("cancelled")) { log.warning("Spot Instance " + item.getUri() + " cancelled .. purging"); try { deleteInstance(item, reference, sequence); // will set // object to // terminated } catch (Exception e) { log.log(Level.SEVERE, "Failed to clean up cancelled spot instance", e); updateStatus(item, InstanceStateName.Terminated.toString(), reference, sequence); delete(item); return; } } if (item.getStatus().equals("closed") && ((item.getInstanceId() == null) || (item.getInstanceId().length() == 0))) { log.warning("Spot Instance " + item.getUri() + " not fulfilled .. purging"); updateStatus(item, InstanceStateName.Terminated.toString(), reference, sequence); delete(item); return; } } if (madeIntoZombie) { if (updateStatus(item, "terminated", reference, sequence)) update(item); if (item.getStatus().equals("terminated")) { log.warning("Instance " + item.getName() + " terminated .. purging"); delete(item); return; } } else if (instanceId != null && instanceId.length() > 0) { DescribeInstancesResult update = client .describeInstances(new DescribeInstancesRequest().withInstanceIds(item.getInstanceId())); if (update.getReservations() != null && update.getReservations().size() > 0) { Instance ec2Instance = update.getReservations().get(0).getInstances().get(0); String newStatus = ec2Instance.getState().getName(); if (!item.getStatus().equals(InstanceStateName.Running.toString()) && InstanceStateName.Running.toString().equals(newStatus)) { item.setOutputParameters(Extractor.extract(ec2Instance)); try { client.createTags(new CreateTagsRequest().withResources(ec2Instance.getInstanceId()) .withTags(new Tag("Name", item.getName()), new Tag("n3phele-factory", Resource.get("factoryName", "ec2Factory")), new Tag("n3phele-uri", item.getUri().toString()))); } catch (Exception ex) { log.log(Level.WARNING, "Cant set tag for " + ec2Instance.getInstanceId() + " associated with " + item.getName(), ex); } } if (updateStatus(item, newStatus, reference, sequence)) update(item); if (item.getStatus().equals("terminated")) { log.warning("Instance " + ec2Instance.getInstanceId() + " terminated .. purging"); delete(item); return; } } else { log.warning("Instance " + item.getInstanceId() + " not found, assumed terminated .. purging"); updateStatus(item, InstanceStateName.Terminated.toString(), reference, sequence); delete(item); return; } } }
From source file:n3phele.factory.ec2.VirtualServerResource.java
License:Open Source License
private int addSpotInstance(List<VirtualServer> items) { RequestSpotInstancesRequest sir = new RequestSpotInstancesRequest(); sir.setInstanceCount(items.size());//from w w w. j av a2 s .co m HashMap<String, String> map = items.get(0).getParametersMap(); Injector.inject(sir, map); LaunchSpecification launchSpec = new LaunchSpecification(); Injector.inject(launchSpec, map); if (map.containsKey("availabilityZone") || map.containsKey("groupName")) { Placement p = new Placement(); if (map.containsKey("availabilityZone")) { String availabilityZone = map.get("availabilityZone"); if (availabilityZone != null && !availabilityZone.equals("")) { p.setAvailabilityZone(map.get("availabilityZone")); launchSpec.setPlacement(p); } } if (map.containsKey("groupName")) { String groupName = map.get("groupName"); if (groupName != null && !groupName.equals("")) { p.setGroupName(map.get("groupName")); launchSpec.setPlacement(p); } } } sir.setLaunchSpecification(launchSpec); AmazonEC2Client client = getEC2Client(items.get(0).getAccessKey(), items.get(0).getEncryptedKey(), items.get(0).getLocation()); RequestSpotInstancesResult result = null; try { result = client.requestSpotInstances(sir); } catch (AmazonServiceException e) { log.log(Level.WARNING, "EC2 error " + e.getErrorCode(), e); throw new WebApplicationException(e, Status.BAD_REQUEST); } int i = 0; for (SpotInstanceRequest spot : result.getSpotInstanceRequests()) { log.warning("Spot Instance[" + i + "] id " + spot.getSpotInstanceRequestId()); items.get(i).setSpotId(spot.getSpotInstanceRequestId()); i++; } return result.getSpotInstanceRequests().size(); }
From source file:n3phele.factory.ec2.VirtualServerResource.java
License:Open Source License
private int addOnDemandInstance(List<VirtualServer> items) { RunInstancesRequest vs = new RunInstancesRequest(); vs.setMinCount(items.size());/*from w w w. j a v a 2 s.c o m*/ vs.setMaxCount(items.size()); String token = items.get(0).getIdempotencyKey(); if (token != null && token.length() > 64) { token = token.substring(token.length() - 64); } vs.setClientToken(token); HashMap<String, String> map = items.get(0).getParametersMap(); Injector.inject(vs, map); if (map.containsKey("availabilityZone") || map.containsKey("groupName")) { Placement p = new Placement(); if (map.containsKey("availabilityZone")) { String availabilityZone = map.get("availabilityZone"); if (availabilityZone != null && !availabilityZone.equals("")) { p.setAvailabilityZone(map.get("availabilityZone")); vs.setPlacement(p); } } if (map.containsKey("groupName")) { String groupName = map.get("groupName"); if (groupName != null && !groupName.equals("")) { p.setGroupName(map.get("groupName")); vs.setPlacement(p); } } } if (items.size() == 1 && createWithZombie(items.get(0))) { return 1; } AmazonEC2Client client = getEC2Client(items.get(0).getAccessKey(), items.get(0).getEncryptedKey(), items.get(0).getLocation()); RunInstancesResult result = null; try { result = client.runInstances(vs); } catch (AmazonServiceException e) { log.log(Level.WARNING, "EC2 error " + e.getErrorCode(), e); throw new WebApplicationException(e, Status.BAD_REQUEST); } catch (AmazonClientException e) { log.log(Level.SEVERE, "EC2 AmazonClientException", e); log.severe("Check for orphaned VMs"); try { result = client.runInstances(vs); } catch (Exception e2) { log.log(Level.SEVERE, "EC2 AmazonClientException", e2); throw new WebApplicationException(e, Status.BAD_REQUEST); } } int i = 0; for (Instance ec2Instance : result.getReservation().getInstances()) { log.info("Create VM[" + i + "] has Instance id " + ec2Instance.getInstanceId()); items.get(i).setInstanceId(ec2Instance.getInstanceId()); i++; } return result.getReservation().getInstances().size(); }
From source file:net.solarnetwork.node.backup.s3.SdkS3Client.java
License:Open Source License
@Override public Set<S3ObjectReference> listObjects(String prefix) throws IOException { AmazonS3 client = getClient();//ww w . j ava 2 s .c o m Set<S3ObjectReference> result = new LinkedHashSet<>(100); try { final ListObjectsV2Request req = new ListObjectsV2Request(); req.setBucketName(bucketName); req.setMaxKeys(maximumKeysPerRequest); req.setPrefix(prefix); ListObjectsV2Result listResult; do { listResult = client.listObjectsV2(req); for (S3ObjectSummary objectSummary : listResult.getObjectSummaries()) { result.add(new S3ObjectReference(objectSummary.getKey(), objectSummary.getSize(), objectSummary.getLastModified())); } req.setContinuationToken(listResult.getNextContinuationToken()); } while (listResult.isTruncated() == true); } catch (AmazonServiceException e) { log.warn("AWS error: {}; HTTP code {}; AWS code {}; type {}; request ID {}", e.getMessage(), e.getStatusCode(), e.getErrorCode(), e.getErrorType(), e.getRequestId()); throw new RemoteServiceException("Error listing S3 objects at " + prefix, e); } catch (AmazonClientException e) { log.debug("Error communicating with AWS: {}", e.getMessage()); throw new IOException("Error communicating with AWS", e); } return result; }
From source file:net.solarnetwork.node.backup.s3.SdkS3Client.java
License:Open Source License
@Override public String getObjectAsString(String key) throws IOException { AmazonS3 client = getClient();/*from w ww . ja va2s . co m*/ try { return client.getObjectAsString(bucketName, key); } catch (AmazonServiceException e) { log.warn("AWS error: {}; HTTP code {}; AWS code {}; type {}; request ID {}", e.getMessage(), e.getStatusCode(), e.getErrorCode(), e.getErrorType(), e.getRequestId()); throw new RemoteServiceException("Error getting S3 object at " + key, e); } catch (AmazonClientException e) { log.debug("Error communicating with AWS: {}", e.getMessage()); throw new IOException("Error communicating with AWS", e); } }
From source file:net.solarnetwork.node.backup.s3.SdkS3Client.java
License:Open Source License
@Override public S3Object getObject(String key) throws IOException { AmazonS3 client = getClient();/*from w w w . j a v a2s . com*/ try { return client.getObject(bucketName, key); } catch (AmazonServiceException e) { log.warn("AWS error: {}; HTTP code {}; AWS code {}; type {}; request ID {}", e.getMessage(), e.getStatusCode(), e.getErrorCode(), e.getErrorType(), e.getRequestId()); throw new RemoteServiceException("Error getting S3 object at " + key, e); } catch (AmazonClientException e) { log.debug("Error communicating with AWS: {}", e.getMessage()); throw new IOException("Error communicating with AWS", e); } }
From source file:net.solarnetwork.node.backup.s3.SdkS3Client.java
License:Open Source License
@Override public S3ObjectReference putObject(String key, InputStream in, ObjectMetadata objectMetadata) throws IOException { AmazonS3 client = getClient();// w w w. j a va 2s . com try { PutObjectRequest req = new PutObjectRequest(bucketName, key, in, objectMetadata); client.putObject(req); return new S3ObjectReference(key, objectMetadata.getContentLength(), objectMetadata.getLastModified()); } catch (AmazonServiceException e) { log.warn("AWS error: {}; HTTP code {}; AWS code {}; type {}; request ID {}", e.getMessage(), e.getStatusCode(), e.getErrorCode(), e.getErrorType(), e.getRequestId()); throw new RemoteServiceException("Error putting S3 object at " + key, e); } catch (AmazonClientException e) { log.debug("Error communicating with AWS: {}", e.getMessage()); throw new IOException("Error communicating with AWS", e); } }