jeevatkm / digitalocean-api-java Goto Github PK
View Code? Open in Web Editor NEWDigitalOcean API Client in Java
Home Page: https://www.digitalocean.com/community/projects/api-client-in-java
License: MIT License
DigitalOcean API Client in Java
Home Page: https://www.digitalocean.com/community/projects/api-client-in-java
License: MIT License
Calling it like this:
digitalOcean.takeDropletSnapshot(924997,"snap-1");
still creates it with a default snapshot name, so it ignores the provided name.
I debugged the code and found the reason in line 225 of DigitalOceanClient.java:
response = process(Action.TAKE_DROPLET_SNAPSHOT, dropletId, qp);
This line calls the "wrong" overloaded "process" method. It calls
process(Action action, Object... id)
instead of
process(Action action, Object[] id,Map<String, String> queryParams)
This results in ignoring all extra query params in "qp"
I wrote an in-house web application based on Spring Framework, and one of the component is a @Scheduled
job that runs periodically to update the droplet statuses.
It hanged after a retry, so I added some debug logs into the code. Normally it would be like this:
11:38:34,341 INFO [stdout] (myScheduler-3) Got DO client
11:38:35,574 INFO [stdout] (myScheduler-3) Got droplet info.
11:38:35,575 INFO [stdout] (myScheduler-3) Got droplet status.
11:38:35,575 INFO [stdout] (myScheduler-3) Setting droplet status: Active
11:38:35,576 INFO [stdout] (myScheduler-3) Updating droplet info to database.
11:38:35,576 INFO [stdout] (myScheduler-3) Updating info for droplet: 8249784
It's a for loop that loops all droplets I've recorded in the local database.
But before it hangs, it would show logs like this:
11:38:35,579 INFO [stdout] (myScheduler-3) Got DO client
11:42:26,054 INFO [org.apache.http.impl.execchain.RetryExec] (myScheduler-3) I/O exception (java.net.SocketException) caught when processing request to {s}->https://api.digitalocean.com:443: Connection reset
11:42:26,054 INFO [org.apache.http.impl.execchain.RetryExec] (myScheduler-3) Retrying request to {s}->https://api.digitalocean.com:443
And nothing else happens.
Since I set the scheduler to fixedDelay = duration, the scheduler won't be executed again unless the last execution is completed. The problem above prevents the scheduler to work properly.
Is there any workaround for this problem?
More Info click here.
Iteratively improve the API client :)
new DigitalOceanClient("v2", token); return error with "Item may not be null".
I've tried with httpClient but nothing...
Implement REST APIs of Floating IPs More Info.
/v2/volumes/$VOLUME_ID/snapshots
/v2/volumes/$VOLUME_ID/snapshots
I see on the Digital Ocean API that it is possible to specify volumes to be attached at the creation of the droplet. Can that be added? I am trying to add to a Jenkins plugin that uses this wrapper and hit myself on this issue because we cannot fire two events simultaneously, we must wait for the droplet to be created before attaching the volume.
As of May 23, 2014 no update in Digital Ocean APIs, moving this next milestone.
Could you be so kind to update the 1.5-SNAPSHOT on the sonatype mvn repo, so that the latest changes are available?
thanks!
I managed to launch, get status, terminate droplet via Java API v.2. But I couldn't set SSH keys to Droplet for getting access via ssh. I tried all approaches of API: create from open key and fingerprint, get all available keys in account and set to droplet, set id of account ssh keys.
Also I successfully launch droplets with ssh keys via REST API and web interface. And connected to them via Putty. But when I try connect to Droplet started with Java API I got message "private key refused
List keys = new ArrayList()
keys.add(new Key(364008))
keys.add(new Key(368425))
keys.add(new Key(452642))
newDroplet.setKeys(keys)
also i tried
newDroplet.setKeys(apiClient.getAvailableKeys(1).keys)
Via REST API it work right
Adding "per_page" to the list methods so that each page is not limited to just 20 items. Reference.
& actions
attribute into Links class
Serialize and Deserialize of JSON object for API calls
Add Account REST endpoint of DO more info here
Response Body:
{ "account": { "droplet_limit": 25, "email": "[email protected]", "uuid": "b6fc48dbf6d9906cace5f3c78dc9851e757381ef", "email_verified": true } }
java.lang.NullPointerException
at com.myjeeva.digitalocean.impl.DigitalOceanClient.perform(DigitalOceanClient.java:1088)
at com.myjeeva.digitalocean.impl.DigitalOceanClient.deleteDroplet(DigitalOceanClient.java:326)
This doesn't happen in version 2.4, so the bug is in changesets between 2.4 and 2.5. I dropped there with debugger and it looks like 2.5 assumes different REST response than the one actually received.
Are you planning on implementing the newly released block storage?
For both Image and Droplet actions, getCompletedAt should returns a string of 2014-11-14T16:32:24Z as per DigitalOcean API doc.
But I got from Java output is Thu Mar 31 12:53:19 HKT 2016. The date seems to be converted to my local time format with HKT, but the numbers are still in UTC. It needs to add +08:00 for HKT. The actual local time is Thu Mar 31 20:53:19 HKT 2016.
It seems HKT is added incorrectly. It should be UTC regardless of the local time zone.
The workaround is to replaced HKT with UTC in the date string.
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEE MMM dd hh:mm:ss zzz yyyy");
Date myDate = simpleDateFormat.parse(apiClient.getActionInfo(actionID).getCompletedAt().toString().replace("HKT", "UTC"));
System.out.println("Reboot finished at: " + myDate);
System.out.println("Reboot finished at: " + apiClient.getActionInfo(actionID).getCompletedAt());
So the first line of output is correct for HKT.
Reboot finished at: Thu Mar 31 22:39:49 HKT 2016
Reboot finished at: Thu Mar 31 14:39:49 HKT 2016
PS: This affects getCompletedAt
for both DropletAction and ImageAction. And I believe the same problem to getStartedAt
Hi, I'm trying to write an Android app with your api, but I just encounter a bug like this, would you please help me to fix it? Below is the detail of the exception,Thanks so much.
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
Caused by: java.lang.NoSuchMethodError: org.apache.http.entity.StringEntity.<init>
at com.myjeeva.digitalocean.impl.DigitalOceanClient.createRequestData(DigitalOceanClient.java:1021)
at com.myjeeva.digitalocean.impl.DigitalOceanClient.perform(DigitalOceanClient.java:837)
at com.myjeeva.digitalocean.impl.DigitalOceanClient.createDroplet(DigitalOceanClient.java:278)
at space.haiyf.app.grabword.DisplayMessageActivity$createCmd.doInBackground(DisplayMessageActivity.java:137)
at space.haiyf.app.grabword.DisplayMessageActivity$createCmd.doInBackground(DisplayMessageActivity.java:127)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
Exception in thread "main" com.myjeeva.digitalocean.exception.DigitalOceanException:
HTTP Status Code: 403
Error Id: translation missing: en.status_code.forbidden.id
Error Message: You do not have access for the attempted action.
at com.myjeeva.digitalocean.impl.DigitalOceanClient.evaluateResponse(DigitalOceanClient.java:870)
at com.myjeeva.digitalocean.impl.DigitalOceanClient.executeHttpRequest(DigitalOceanClient.java:835)
at com.myjeeva.digitalocean.impl.DigitalOceanClient.doPost(DigitalOceanClient.java:806)
at com.myjeeva.digitalocean.impl.DigitalOceanClient.perform(DigitalOceanClient.java:763)
at com.myjeeva.digitalocean.impl.DigitalOceanClient.shutdownDroplet(DigitalOceanClient.java:311)
DigitalOcean has released a v2 API updates on Oct 27 on Size parameter, more info is here.
Applying these changes into 2.0-SNAPSHOT.
Sync REST APIs in v1.4 release from https://api.digitalocean.com as of today.
updateDomainRecord() takes only records id and name as a parameter and there doesn't seem to be a way to update for example the record data.
On Nov 6, 2014, added support for image filtering. More info click here.
Add this support.
I'm getting the following exception when retrieving/deserializing droplets:
Caused by: java.text.ParseException: Unparseable date: "2014-07-07T03:03:14.000Z"
I believe changing DATE_FORMAT = "yyyy-mm-dd'T'HH:mm:ss'Z'" to "yyyy-mm-dd'T'HH:mm:ss.SSS'Z'" should fix it.
Digital Ocean development team have introduced the Versioning concept into Cloud APIs. Since API v2.0 beta is out for try.
v1 URI will look like below:
https://api.digitalocean.com/v1/droplets/?client_id=[client_id]&api_key=[api_key]¶ms.......
More info click here.
DigitalOcean introduced the Metadata API for Droplets.
Supplying a user_data
while creation, documentation is here
Is it possible that we can access the database using apiv2 and insert and retrieve data using it ?
On Feb 10, 2015 - added new neighbors endpoints (/v2/reports & neighbors) API. More info click here
Add this!
I was trying to use the latest version of the library in my Android app, and ran into
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/impl/client/HttpClients
from Android, I think it's missing a dependency. I got around it by adding HttpComponents to my app's build.gradle file
compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5.1'
This happened to me while using https://github.com/jenkinsci/digitalocean-plugin . Jenkins plugin calls the function getAvailableDroplets, which keeps sending the request to /droplets, until it exhaust the 5000 query per hour.
Here is a similar bug report https://issues.jenkins-ci.org/browse/JENKINS-35022
OAuth 2 is an open standard for authorization that enables third-party applications to obtain limited access to DigitalOcean user accounts, by delegating user authentication to DigitalOcean.
Developers must register their application to use OAuth. A registered application is assigned a client ID and client secret. The client secret should be kept confidential, and only used between the application and the DigitalOcean authorization server (https://cloud.digitalocean.com/v1/oauth/).
More Info, click here
Not a big deal but I suppose that something like {"images": [ { "id" : 3123213, "slug" : null }]} didn't happen in json response not so long ago. This is just for everyone to note as in my case I had to debug the json response to understand why library stopped working for me.
Running 2.6 version of the plugin, I get two Ubuntu 24 x64 images that different only by ids. Both of the images are not mine, i.e. I don't have them in either Snapshots or Backups.
24 = {Image@9528} "com.myjeeva.digitalocean.pojo.Image@158a57d6[id=17824874,name=24 x64,distribution=Ubuntu,slug=<null>,availablePublic=true,regions=[nyc3],createdDate=Fri Jun 10 00:54:21 EDT 2016,minDiskSize=20,size=29.68,type=snapshot,rateLimit=<null>]"
23 = {Image@9527} "com.myjeeva.digitalocean.pojo.Image@11b8b745[id=17824847,name=24 x64,distribution=Ubuntu,slug=<null>,availablePublic=true,regions=[nyc3],createdDate=Fri Jun 10 00:54:21 EDT 2016,minDiskSize=20,size=29.68,type=snapshot,rateLimit=<null>]"
It would make sense for this to be Fedora 24 x64, be there is already Fedora 24 x64.
com.myjeeva.digitalocean.pojo.Image@4ed7e4cf[id=18027532,name=24 x64,distribution=Fedora,slug=fedora-24-x64,availablePublic=true,regions=[nyc1, sfo1, nyc2, ams2, sgp1, lon1, nyc3, ams3, fra1, tor1, sfo2, blr1],createdDate=Tue Jun 21 18:36:10 EDT 2016,minDiskSize=20,size=3.0,type=snapshot,rateLimit=<null>]
It also doesn't seem like there is any Ubuntu 24 x64 when creating a droplet in Digital Ocean's Web UI...
Not sure what to make out of this Ubuntu 24 x64. Perhaps it is upstream, i.e. Digital Ocean's, issue?
Hi @jeevatkm ,
Thanks a lot for this digital ocean API client.
The REST API provides the ability to delete by tag. Unfortunately the client does not provide that feature.
Would you consider supporting it ?
Thank you for your work
Refer snapshots API
There's no IP Address property in the Droplet class while there should be one since the API returns an 'ip_address' field.
Make RateLimit
header values available in all the return object (Not at nested level).
Droplets droplets = getAvailableDroplets(1); RateLimit rateLimit = droplets.getRateLimit();
Actions actions = getAvailableActions(2); RateLimit rateLimit = actions.getRateLimit();
Domain domain = getDomainInfo("myjeeva.com"); RateLimit rateLimit = domain.getRateLimit();
Droplet droplet = getDropletInfo(10000001); RateLimit rateLimit = droplet.getRateLimit();
Update the javadoc for v2 API implementation before release.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.