DigitalOcean API Client in Java

com.myjeeva.digitalocean.impl
Class DigitalOceanClient

java.lang.Object
  extended by com.myjeeva.digitalocean.impl.DigitalOceanClient
All Implemented Interfaces:
Constants, DigitalOcean

public class DigitalOceanClient
extends Object
implements DigitalOcean, Constants

DigitalOcean API client wrapper methods Implementation

Author:
Jeevanandam M. ([email protected])

Field Summary
 
Fields inherited from interface com.myjeeva.digitalocean.Constants
HTTPS_SCHEME, PARAM_API_KEY, PARAM_CLIENT_ID, PARAM_DATA, PARAM_IMAGE_ID, PARAM_IP_ADDRESS, PARAM_NAME, PARAM_PORT, PARAM_PRIORITY, PARAM_RECORD_TYPE, PARAM_REGION_ID, PARAM_SIDE_ID, PARAM_SSH_KEY_IDS, PARAM_WEIGHT, STATUS, UTF_8
 
Constructor Summary
DigitalOceanClient(String clientId, String apiKey)
          Constructor for initializing DigitalOcean Client
 
Method Summary
 SshKey addSshKey(String sshKeyName, String sshPublicKey)
          To be release in v1.2
 Domain createDomain(String domainName, String ipAddress)
          Method creates a new domain name with an A record for the specified [ip_address].
 DomainRecord createDomainRecord(DomainRecord domainRecord)
          Method creates a new domain record name with an given domain record values
 Droplet createDroplet(Droplet droplet)
           Method allows you to create a new droplet.
 Droplet createDroplet(Droplet droplet, String sshKeyIds)
           Method allows you to create a new droplet.
 Response deleteDomain(Integer domainId)
          Method deletes the specified domain from DNS control panel
 Response deleteDomainRecord(Integer domainId, Integer recordId)
          Method deletes the specified domain record from domain.
 Response deleteDroplet(Integer dropletId)
          Method destroys one of your droplets - this is irreversible.
 Response deleteImage(Integer imageId)
          Method allows you to deletes an image.
 Response deleteSshKey(Integer sshKeyId)
          To be release in v1.2
 Response disableDropletBackups(Integer dropletId)
          Method disables automatic backups from running to backup your droplet's data.
 DomainRecord editDomainRecord(DomainRecord domainRecord)
          method edits an existing domain record of the given domain.
 SshKey editSshKey(Integer sshKeyId, String sshPublicKey)
          To be release in v1.2
 Response enableDropletBackups(Integer dropletId)
          Method enables automatic backups which run in the background daily to backup your droplet's data.
 List<Domain> getAvailableDomains()
          Method returns all of your available domains from DNS control panel
 List<Droplet> getAvailableDroplets()
          Method returns all active droplets that are currently running in your account.
 List<DropletImage> getAvailableImages()
          Method returns all the available images that can be accessed by your client ID.
 List<Region> getAvailableRegions()
          Method will return all the available regions within the DigitalOcean cloud.
 List<DropletSize> getAvailableSizes()
          Method returns all the available sizes that can be used to create a droplet.
 List<SshKey> getAvailableSshKeys()
          To be release in v1.2
 Domain getDomainInfo(Integer domainId)
          Method returns the specified domain attributes and zone file info.
 DomainRecord getDomainRecordInfo(Integer domainId, Integer recordId)
          Method returns the specified domain record.
 List<DomainRecord> getDomainRecords(Integer domainId)
          Method returns all of your current domain records from DNS control panel for given domain.
 Droplet getDropletInfo(Integer dropletId)
          Method returns full information for a specific droplet ID that is passed in the URL.
 DropletImage getImageInfo(Integer imageId)
          Method retrieves the attributes of an image.
 SshKey getSshKeyInfo(Integer sshKeyId)
          To be release in v1.2
 Response powerCyleDroplet(Integer dropletId)
          Method allows you to power cycle a droplet.
 Response powerOffDroplet(Integer dropletId)
          Method allows you to poweroff a running droplet.
 Response powerOnDroplet(Integer dropletId)
          Method allows you to poweron a powered off droplet.
 Response rebootDroplet(Integer dropletId)
          Method allows you to reboot a droplet.
 Response rebuildDroplet(Integer dropletId, Integer imageId)
          Method allows you to reinstall a droplet with a default image.
 Response renameDroplet(Integer dropletId, String name)
          Method renames the droplet to the specified name.
 Response resetDropletPassword(Integer dropletId)
          Method will reset the root password for a droplet.
 Response resizeDroplet(Integer dropletId, Integer sizeId)
          Method allows you to resize a specific droplet to a different size.
 Response restoreDroplet(Integer dropletId, Integer imageId)
          Method allows you to restore a droplet with a previous image or snapshot.
 Response shutdownDroplet(Integer dropletId)
          Method allows you to shutdown a running droplet.
 Response takeDropletSnapshot(Integer dropletId)
          Method allows you to take a snapshot of the running droplet, which can later be restored or used to create a new droplet from the same image.
 Response takeDropletSnapshot(Integer dropletId, String snapshotName)
          Method allows you to take a snapshot of the running droplet, which can later be restored or used to create a new droplet from the same image.
 Response transerImage(Integer imageId, Integer regionId)
          Method allows you to transfer an image to a specified region.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DigitalOceanClient

public DigitalOceanClient(String clientId,
                          String apiKey)
Constructor for initializing DigitalOcean Client

Parameters:
clientId - a String object
apiKey - a String object
Throws:
ResourceNotFoundException
Method Detail

getAvailableDroplets

public List<Droplet> getAvailableDroplets()
                                   throws AccessDeniedException,
                                          ResourceNotFoundException,
                                          RequestUnsuccessfulException
Description copied from interface: DigitalOcean
Method returns all active droplets that are currently running in your account. All available API information is presented for each droplet.

Specified by:
getAvailableDroplets in interface DigitalOcean
Returns:
List<Droplet>
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException

createDroplet

public Droplet createDroplet(Droplet droplet)
                      throws AccessDeniedException,
                             ResourceNotFoundException,
                             RequestUnsuccessfulException
Description copied from interface: DigitalOcean

Method allows you to create a new droplet. See the required parameters section below for an explanation of the variables that are needed to create a new droplet.

Create a instance of Droplet object and populate following values

Specified by:
createDroplet in interface DigitalOcean
Parameters:
droplet - - the id of the droplet
Returns:
Droplet
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException

createDroplet

public Droplet createDroplet(Droplet droplet,
                             String sshKeyIds)
                      throws AccessDeniedException,
                             ResourceNotFoundException,
                             RequestUnsuccessfulException
Description copied from interface: DigitalOcean

Method allows you to create a new droplet. See the required parameters section below for an explanation of the variables that are needed to create a new droplet.

Create a instance of Droplet object and populate following values

Specified by:
createDroplet in interface DigitalOcean
Parameters:
droplet - - the id of the droplet
sshKeyIds - - Numeric CSV, comma separated list of ssh_key_ids that you would like to be added to the server
Returns:
Droplet
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException

getDropletInfo

public Droplet getDropletInfo(Integer dropletId)
                       throws AccessDeniedException,
                              ResourceNotFoundException,
                              RequestUnsuccessfulException
Description copied from interface: DigitalOcean
Method returns full information for a specific droplet ID that is passed in the URL.

Specified by:
getDropletInfo in interface DigitalOcean
Parameters:
dropletId - - the id of the droplet
Returns:
Droplet
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException

rebootDroplet

public Response rebootDroplet(Integer dropletId)
                       throws AccessDeniedException,
                              ResourceNotFoundException,
                              RequestUnsuccessfulException
Description copied from interface: DigitalOcean
Method allows you to reboot a droplet. This is the preferred method to use if a server is not responding.

Specified by:
rebootDroplet in interface DigitalOcean
Parameters:
dropletId - - the id of the droplet
Returns:
Response
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException

powerCyleDroplet

public Response powerCyleDroplet(Integer dropletId)
                          throws AccessDeniedException,
                                 ResourceNotFoundException,
                                 RequestUnsuccessfulException
Description copied from interface: DigitalOcean
Method allows you to power cycle a droplet. This will turn off the droplet and then turn it back on.

Specified by:
powerCyleDroplet in interface DigitalOcean
Parameters:
dropletId - - the id of the droplet
Returns:
Response
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException

shutdownDroplet

public Response shutdownDroplet(Integer dropletId)
                         throws AccessDeniedException,
                                ResourceNotFoundException,
                                RequestUnsuccessfulException
Description copied from interface: DigitalOcean
Method allows you to shutdown a running droplet. The droplet will remain in your account.

Specified by:
shutdownDroplet in interface DigitalOcean
Parameters:
dropletId - - the id of the droplet
Returns:
Response
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException

powerOffDroplet

public Response powerOffDroplet(Integer dropletId)
                         throws AccessDeniedException,
                                ResourceNotFoundException,
                                RequestUnsuccessfulException
Description copied from interface: DigitalOcean
Method allows you to poweroff a running droplet. The droplet will remain in your account.

Specified by:
powerOffDroplet in interface DigitalOcean
Parameters:
dropletId - - the id of the droplet
Returns:
Response
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException

powerOnDroplet

public Response powerOnDroplet(Integer dropletId)
                        throws AccessDeniedException,
                               ResourceNotFoundException,
                               RequestUnsuccessfulException
Description copied from interface: DigitalOcean
Method allows you to poweron a powered off droplet.

Specified by:
powerOnDroplet in interface DigitalOcean
Parameters:
dropletId - - the id of the droplet
Returns:
Response
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException

resetDropletPassword

public Response resetDropletPassword(Integer dropletId)
                              throws AccessDeniedException,
                                     ResourceNotFoundException,
                                     RequestUnsuccessfulException
Description copied from interface: DigitalOcean
Method will reset the root password for a droplet. Please be aware that this will reboot the droplet to allow resetting the password.

Specified by:
resetDropletPassword in interface DigitalOcean
Parameters:
dropletId - - the id of the droplet
Returns:
Response
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException

resizeDroplet

public Response resizeDroplet(Integer dropletId,
                              Integer sizeId)
                       throws AccessDeniedException,
                              ResourceNotFoundException,
                              RequestUnsuccessfulException
Description copied from interface: DigitalOcean
Method allows you to resize a specific droplet to a different size. This will affect the number of processors and memory allocated to the droplet.

Specified by:
resizeDroplet in interface DigitalOcean
Parameters:
dropletId - - the id of the droplet
Returns:
Response
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException

takeDropletSnapshot

public Response takeDropletSnapshot(Integer dropletId)
                             throws AccessDeniedException,
                                    ResourceNotFoundException,
                                    RequestUnsuccessfulException
Description copied from interface: DigitalOcean
Method allows you to take a snapshot of the running droplet, which can later be restored or used to create a new droplet from the same image. Please be aware this may cause a reboot.

Specified by:
takeDropletSnapshot in interface DigitalOcean
Parameters:
dropletId - - the id of the droplet
Returns:
Response
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException

takeDropletSnapshot

public Response takeDropletSnapshot(Integer dropletId,
                                    String snapshotName)
                             throws AccessDeniedException,
                                    ResourceNotFoundException,
                                    RequestUnsuccessfulException
Description copied from interface: DigitalOcean
Method allows you to take a snapshot of the running droplet, which can later be restored or used to create a new droplet from the same image. Please be aware this may cause a reboot.

Specified by:
takeDropletSnapshot in interface DigitalOcean
Parameters:
dropletId - - the id of the droplet
snapshotName - - the name the snapshot to be created
Returns:
Response
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException

restoreDroplet

public Response restoreDroplet(Integer dropletId,
                               Integer imageId)
                        throws AccessDeniedException,
                               ResourceNotFoundException,
                               RequestUnsuccessfulException
Description copied from interface: DigitalOcean
Method allows you to restore a droplet with a previous image or snapshot. This will be a mirror copy of the image or snapshot to your droplet. Be sure you have backed up any necessary information prior to restore.

Specified by:
restoreDroplet in interface DigitalOcean
Parameters:
dropletId - - the id of the droplet
Returns:
Response
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException

rebuildDroplet

public Response rebuildDroplet(Integer dropletId,
                               Integer imageId)
                        throws AccessDeniedException,
                               ResourceNotFoundException,
                               RequestUnsuccessfulException
Description copied from interface: DigitalOcean
Method allows you to reinstall a droplet with a default image. This is useful if you want to start again but retain the same IP address for your droplet.

Specified by:
rebuildDroplet in interface DigitalOcean
Parameters:
dropletId - - the id of the droplet
Returns:
Response
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException

enableDropletBackups

public Response enableDropletBackups(Integer dropletId)
                              throws AccessDeniedException,
                                     ResourceNotFoundException,
                                     RequestUnsuccessfulException
Description copied from interface: DigitalOcean
Method enables automatic backups which run in the background daily to backup your droplet's data.

Specified by:
enableDropletBackups in interface DigitalOcean
Parameters:
dropletId - - the id of the droplet
Returns:
Response
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException

disableDropletBackups

public Response disableDropletBackups(Integer dropletId)
                               throws AccessDeniedException,
                                      ResourceNotFoundException,
                                      RequestUnsuccessfulException
Description copied from interface: DigitalOcean
Method disables automatic backups from running to backup your droplet's data.

Specified by:
disableDropletBackups in interface DigitalOcean
Parameters:
dropletId - - the id of the droplet
Returns:
Response
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException

renameDroplet

public Response renameDroplet(Integer dropletId,
                              String name)
                       throws AccessDeniedException,
                              ResourceNotFoundException,
                              RequestUnsuccessfulException
Description copied from interface: DigitalOcean
Method renames the droplet to the specified name.

Specified by:
renameDroplet in interface DigitalOcean
Parameters:
dropletId - - the id of the droplet
Returns:
Response
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException

deleteDroplet

public Response deleteDroplet(Integer dropletId)
                       throws AccessDeniedException,
                              ResourceNotFoundException,
                              RequestUnsuccessfulException
Description copied from interface: DigitalOcean
Method destroys one of your droplets - this is irreversible.

Specified by:
deleteDroplet in interface DigitalOcean
Parameters:
dropletId - - the id of the droplet
Returns:
Response
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException

getAvailableRegions

public List<Region> getAvailableRegions()
                                 throws AccessDeniedException,
                                        ResourceNotFoundException,
                                        RequestUnsuccessfulException
Description copied from interface: DigitalOcean
Method will return all the available regions within the DigitalOcean cloud.

Specified by:
getAvailableRegions in interface DigitalOcean
Returns:
List<Region>
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException

getAvailableImages

public List<DropletImage> getAvailableImages()
                                      throws AccessDeniedException,
                                             ResourceNotFoundException,
                                             RequestUnsuccessfulException
Description copied from interface: DigitalOcean
Method returns all the available images that can be accessed by your client ID. You will have access to all public images by default, and any snapshots or backups that you have created in your own account.

Specified by:
getAvailableImages in interface DigitalOcean
Returns:
List<DropletImage>
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException

getImageInfo

public DropletImage getImageInfo(Integer imageId)
                          throws AccessDeniedException,
                                 ResourceNotFoundException,
                                 RequestUnsuccessfulException
Description copied from interface: DigitalOcean
Method retrieves the attributes of an image.

Specified by:
getImageInfo in interface DigitalOcean
Parameters:
imageId - - the image Id of the droplet/snapshot/backup images
Returns:
DropletImage
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException

deleteImage

public Response deleteImage(Integer imageId)
                     throws AccessDeniedException,
                            ResourceNotFoundException,
                            RequestUnsuccessfulException
Description copied from interface: DigitalOcean
Method allows you to deletes an image. There is no way to restore a deleted image so be careful and ensure your data is properly backed up.

Specified by:
deleteImage in interface DigitalOcean
Parameters:
imageId - - the image Id of the droplet/snapshot/backup images
Returns:
Response
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException

transerImage

public Response transerImage(Integer imageId,
                             Integer regionId)
                      throws AccessDeniedException,
                             ResourceNotFoundException,
                             RequestUnsuccessfulException
Description copied from interface: DigitalOcean
Method allows you to transfer an image to a specified region.

Specified by:
transerImage in interface DigitalOcean
Parameters:
imageId - - the image Id of the droplet/snapshot/backup images
regionId - - the region Id of the digitalocean data centers
Returns:
Response
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException

getAvailableSshKeys

public List<SshKey> getAvailableSshKeys()
Description copied from interface: DigitalOcean
To be release in v1.2

Specified by:
getAvailableSshKeys in interface DigitalOcean

getSshKeyInfo

public SshKey getSshKeyInfo(Integer sshKeyId)
Description copied from interface: DigitalOcean
To be release in v1.2

Specified by:
getSshKeyInfo in interface DigitalOcean

addSshKey

public SshKey addSshKey(String sshKeyName,
                        String sshPublicKey)
Description copied from interface: DigitalOcean
To be release in v1.2

Specified by:
addSshKey in interface DigitalOcean

editSshKey

public SshKey editSshKey(Integer sshKeyId,
                         String sshPublicKey)
Description copied from interface: DigitalOcean
To be release in v1.2

Specified by:
editSshKey in interface DigitalOcean

deleteSshKey

public Response deleteSshKey(Integer sshKeyId)
Description copied from interface: DigitalOcean
To be release in v1.2

Specified by:
deleteSshKey in interface DigitalOcean

getAvailableSizes

public List<DropletSize> getAvailableSizes()
                                    throws AccessDeniedException,
                                           ResourceNotFoundException,
                                           RequestUnsuccessfulException
Description copied from interface: DigitalOcean
Method returns all the available sizes that can be used to create a droplet.

Specified by:
getAvailableSizes in interface DigitalOcean
Returns:
List<DropletSize>
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException

getAvailableDomains

public List<Domain> getAvailableDomains()
                                 throws AccessDeniedException,
                                        ResourceNotFoundException,
                                        RequestUnsuccessfulException
Description copied from interface: DigitalOcean
Method returns all of your available domains from DNS control panel

Specified by:
getAvailableDomains in interface DigitalOcean
Returns:
List<Domain>
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException

getDomainInfo

public Domain getDomainInfo(Integer domainId)
                     throws AccessDeniedException,
                            ResourceNotFoundException,
                            RequestUnsuccessfulException
Description copied from interface: DigitalOcean
Method returns the specified domain attributes and zone file info.

Specified by:
getDomainInfo in interface DigitalOcean
Parameters:
domainId - - the Id of the domain
Returns:
Domain
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException

createDomain

public Domain createDomain(String domainName,
                           String ipAddress)
                    throws AccessDeniedException,
                           ResourceNotFoundException,
                           RequestUnsuccessfulException
Description copied from interface: DigitalOcean
Method creates a new domain name with an A record for the specified [ip_address].

Specified by:
createDomain in interface DigitalOcean
Parameters:
domainName - - the name of the domain
ipAddress - - the IP Address for the domain
Returns:
Domain
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException

deleteDomain

public Response deleteDomain(Integer domainId)
                      throws AccessDeniedException,
                             ResourceNotFoundException,
                             RequestUnsuccessfulException
Description copied from interface: DigitalOcean
Method deletes the specified domain from DNS control panel

Specified by:
deleteDomain in interface DigitalOcean
Parameters:
domainId - - the Id of the domain
Returns:
Response
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException

getDomainRecords

public List<DomainRecord> getDomainRecords(Integer domainId)
                                    throws AccessDeniedException,
                                           ResourceNotFoundException,
                                           RequestUnsuccessfulException
Description copied from interface: DigitalOcean
Method returns all of your current domain records from DNS control panel for given domain.

Specified by:
getDomainRecords in interface DigitalOcean
Parameters:
domainId - - the Id of the domain
Returns:
List<DomainRecord>
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException

getDomainRecordInfo

public DomainRecord getDomainRecordInfo(Integer domainId,
                                        Integer recordId)
                                 throws AccessDeniedException,
                                        ResourceNotFoundException,
                                        RequestUnsuccessfulException
Description copied from interface: DigitalOcean
Method returns the specified domain record.

Specified by:
getDomainRecordInfo in interface DigitalOcean
Parameters:
domainId - - the Id of the domain
recordId - - the record Id of the domain
Returns:
DomainRecord
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException

createDomainRecord

public DomainRecord createDomainRecord(DomainRecord domainRecord)
                                throws AccessDeniedException,
                                       ResourceNotFoundException,
                                       RequestUnsuccessfulException
Description copied from interface: DigitalOcean
Method creates a new domain record name with an given domain record values

Specified by:
createDomainRecord in interface DigitalOcean
Parameters:
domainRecord - - the domain record values domain Id, record type, data, name, priority, port, weight
Returns:
DomainRecord
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException

editDomainRecord

public DomainRecord editDomainRecord(DomainRecord domainRecord)
                              throws AccessDeniedException,
                                     ResourceNotFoundException,
                                     RequestUnsuccessfulException
Description copied from interface: DigitalOcean
method edits an existing domain record of the given domain.

Specified by:
editDomainRecord in interface DigitalOcean
Parameters:
domainRecord - - the domain record values domain Id, record type, data, name, priority, port, weight
Returns:
DomainRecord
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException

deleteDomainRecord

public Response deleteDomainRecord(Integer domainId,
                                   Integer recordId)
                            throws AccessDeniedException,
                                   ResourceNotFoundException,
                                   RequestUnsuccessfulException
Description copied from interface: DigitalOcean
Method deletes the specified domain record from domain.

Specified by:
deleteDomainRecord in interface DigitalOcean
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException

DigitalOcean API Client in Java

Copyright © 2013 myjeeva blog, All rights reserved.

The copyright of the pages and contents on this website is with myjeeva.com and the content is licensed under Creative Commons Attribution-Share Alike 3.0 Unported License. Libraries and code snippets on myjeeva blog has license information.