de.jw.cloud42.core.service
Class Cloud42BaseFunctions

java.lang.Object
  extended by de.jw.cloud42.core.service.Cloud42Functions
      extended by de.jw.cloud42.core.service.Cloud42BaseFunctions

public class Cloud42BaseFunctions
extends Cloud42Functions

Basic functions such as listing AMIs and starting an instance.

Author:
fbitzer

Field Summary
 
Fields inherited from class de.jw.cloud42.core.service.Cloud42Functions
ec2
 
Constructor Summary
Cloud42BaseFunctions()
           
 
Method Summary
 boolean addPermission(java.lang.String groupname, java.lang.String protocol, int portFrom, int portTo, java.lang.String cidrIp)
          Add incoming permissions to a group by opening the given ports.
 boolean addPermission(java.lang.String groupname, java.lang.String secGroupName, java.lang.String secGroupOwnerId)
          Adds a permission associated to an group/owner.
 com.xerox.amazonws.ec2.KeyPairInfo createKeypair(java.lang.String name)
          Create a keypair.
 boolean createSecurityGroup(java.lang.String name, java.lang.String description)
          Create a security group that can be assigned to an instance.
 boolean deleteKeypair(java.lang.String name)
          Delete a keypair.
 boolean deleteSecurityGroup(java.lang.String name)
          Delete a security group.
 boolean deregisterImage(java.lang.String imageId)
          Deregister an AMI Image.
 Instance describeInstance(java.lang.String instanceId)
          Get or refresh current information on a running instance identified by its Id.
 com.xerox.amazonws.ec2.KeyPairInfo describeKeypair(java.lang.String name)
          Gets the properties of a specific keypair.
 com.xerox.amazonws.ec2.GroupDescription describeSecurityGroup(java.lang.String name)
          Gets the properties of a specific security group.
 com.xerox.amazonws.ec2.ConsoleOutput getConsoleOutput(java.lang.String instanceId)
          Get console ouput for a particular instance.
 com.xerox.amazonws.ec2.AvailabilityZone[] listAvailabilityZones()
          Lists available Availability zones.
 com.xerox.amazonws.ec2.ImageDescription[] listImages(boolean all)
          Lists available EC2 AMIs that you could start an instance of.
 Instance[] listInstances()
          List all instances.
 com.xerox.amazonws.ec2.KeyPairInfo[] listKeypairs()
          List available keypairs.
 com.xerox.amazonws.ec2.RegionInfo[] listRegions()
          List the AWS Regions.
 com.xerox.amazonws.ec2.GroupDescription[] listSecurityGroups()
          List all available Security groups.
 void rebootInstance(java.lang.String instanceId)
          Reboot a given instance.
 java.lang.String registerImage(java.lang.String location)
          Register a new AMI from a bucket on S3
 boolean removePermission(java.lang.String groupname, java.lang.String protocol, int portFrom, int portTo, java.lang.String cidrIp)
          Revokes permissions that were added using addPermission().
 boolean removePermission(java.lang.String groupname, java.lang.String secGroupName, java.lang.String secGroupOwnerId)
          Revokes a permission associated to an group/owner.
 com.xerox.amazonws.ec2.ReservationDescription runInstance(java.lang.String imageId, java.lang.String[] groups, java.lang.String keyName, byte[] userData, com.xerox.amazonws.ec2.InstanceType instanceType, int count, java.lang.String availabilityZone, java.lang.String kernelId, java.lang.String ramdiskId)
          Starts an instance with the given parameters.
 Instance[] runInstanceBlocking(java.lang.String imageId, java.lang.String[] groups, java.lang.String keyName, byte[] userData, com.xerox.amazonws.ec2.InstanceType instanceType, int count, java.lang.String availabilityZone, java.lang.String kernelId, java.lang.String ramdiskId)
          Blocking start of an instance with the given parameters.
 com.xerox.amazonws.ec2.TerminatingInstanceDescription[] stopAllInstances()
          Stop all existing instances.
 com.xerox.amazonws.ec2.TerminatingInstanceDescription stopInstance(java.lang.String instanceId)
          Stop a specific AMI instance.
 
Methods inherited from class de.jw.cloud42.core.service.Cloud42Functions
getCredentials, getRegionUrl, setCredentials, setRegionUrl
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Cloud42BaseFunctions

public Cloud42BaseFunctions()
Method Detail

listRegions

public com.xerox.amazonws.ec2.RegionInfo[] listRegions()
List the AWS Regions.

Returns:

listImages

public com.xerox.amazonws.ec2.ImageDescription[] listImages(boolean all)
Lists available EC2 AMIs that you could start an instance of. Note that we have to work with arrays here because this class is going to be exposed as a Web service through Axis2 which does not support Lists.

Parameters:
all - set to true to display all public AMIs, set to false to list only your own AMIs.
Returns:
Array of Images or null, if no images were found or credentials were wrong.

runInstance

public com.xerox.amazonws.ec2.ReservationDescription runInstance(java.lang.String imageId,
                                                                 java.lang.String[] groups,
                                                                 java.lang.String keyName,
                                                                 byte[] userData,
                                                                 com.xerox.amazonws.ec2.InstanceType instanceType,
                                                                 int count,
                                                                 java.lang.String availabilityZone,
                                                                 java.lang.String kernelId,
                                                                 java.lang.String ramdiskId)
Starts an instance with the given parameters.

Parameters:
imageId - AMI-Id of the instance to start.
groups - List of groups.
keyName - Name of the keypair to use.
userData - User data for this instance (see http://docs.amazonwebservices.com/AWSEC2/2008-05-05/DeveloperGuide/index.html?AESDG-chapter-instancedata.html).
instanceType - EC2 Type of the instance
count - number of instances to launch
availabilityZone - Availability zone for instance.
kernelId - KernelId to use. May be empty.
ramdiskId - RamdiskId to use. May be empty.
Returns:
Instance or null in case of error.

runInstanceBlocking

public Instance[] runInstanceBlocking(java.lang.String imageId,
                                      java.lang.String[] groups,
                                      java.lang.String keyName,
                                      byte[] userData,
                                      com.xerox.amazonws.ec2.InstanceType instanceType,
                                      int count,
                                      java.lang.String availabilityZone,
                                      java.lang.String kernelId,
                                      java.lang.String ramdiskId)
Blocking start of an instance with the given parameters. Returns only if startup of instance (or instances, of count > 1) is complete (state is "running") or if an error occured.

Parameters:
imageId - AMI-Id of the instance to start.
groups - List of groups.
keyName - Name of the keypair to use.
instanceType - EC2 Type of the instance
count - number of instances to start with in ReservationDescription
Returns:
Instance(s) (if count > 1) or null in case of error.

describeInstance

public Instance describeInstance(java.lang.String instanceId)
Get or refresh current information on a running instance identified by its Id.

Parameters:
instanceId -
Returns:
Instance holding the current properties of the instance or null in case of error.

stopInstance

public com.xerox.amazonws.ec2.TerminatingInstanceDescription stopInstance(java.lang.String instanceId)
Stop a specific AMI instance.

Parameters:
instanceId -
Returns:
TerminatingInstanceDescription or null in case of error.

stopAllInstances

public com.xerox.amazonws.ec2.TerminatingInstanceDescription[] stopAllInstances()
Stop all existing instances.

Returns:
List of TerminatingInstanceDescription or null in case of error or if no instances were running.

rebootInstance

public void rebootInstance(java.lang.String instanceId)
Reboot a given instance.

Parameters:
instanceId -

listInstances

public Instance[] listInstances()
List all instances.

Returns:
List of AMIInstances (may be empty) or null in case of error.

createSecurityGroup

public boolean createSecurityGroup(java.lang.String name,
                                   java.lang.String description)
Create a security group that can be assigned to an instance.

Parameters:
name -
description -
Returns:
true if successfull, false else (e.g. if group with same name already exists).

deleteSecurityGroup

public boolean deleteSecurityGroup(java.lang.String name)
Delete a security group.

Parameters:
name - Name of the group to delete. *
Returns:
true if successfull, false else (e.g. if group is assigned to a running instance).

listSecurityGroups

public com.xerox.amazonws.ec2.GroupDescription[] listSecurityGroups()
List all available Security groups.

Returns:

describeSecurityGroup

public com.xerox.amazonws.ec2.GroupDescription describeSecurityGroup(java.lang.String name)
Gets the properties of a specific security group.

Parameters:
name - The name of the group.
Returns:
GroupDescription or null in case of error or if group does not exist.

addPermission

public boolean addPermission(java.lang.String groupname,
                             java.lang.String protocol,
                             int portFrom,
                             int portTo,
                             java.lang.String cidrIp)
Add incoming permissions to a group by opening the given ports.

Parameters:
instance -
groupname - name of the group.
protocol - e.g. "tcp", "udp", "icmp"
portFrom -
portTo -
cidrIp - CIDR IP range to add (i.e. 0.0.0.0/0)
Returns:
true if successfull, false else

addPermission

public boolean addPermission(java.lang.String groupname,
                             java.lang.String secGroupName,
                             java.lang.String secGroupOwnerId)
Adds a permission associated to an group/owner.

Parameters:
groupname - name of group to modify
secGroupName - name of security group to add access
secGroupOwnerId - owner of security group
Returns:

removePermission

public boolean removePermission(java.lang.String groupname,
                                java.lang.String protocol,
                                int portFrom,
                                int portTo,
                                java.lang.String cidrIp)
Revokes permissions that were added using addPermission().

Parameters:
instance -
groupname -
protocol -
portFrom -
portTo -
cidrIp - CIDR IP range to add (i.e. 0.0.0.0/0)
Returns:
true if successfull, false else

removePermission

public boolean removePermission(java.lang.String groupname,
                                java.lang.String secGroupName,
                                java.lang.String secGroupOwnerId)
Revokes a permission associated to an group/owner.

Parameters:
groupname - name of group to modify
secGroupName - name of security group to revoke access from
secGroupOwnerId - owner of security group to revoke access from
Returns:

registerImage

public java.lang.String registerImage(java.lang.String location)
Register a new AMI from a bucket on S3

Parameters:
location - the location on S3
Returns:
the unique imageId of the newly registered AMI.

deregisterImage

public boolean deregisterImage(java.lang.String imageId)
Deregister an AMI Image.

Parameters:
imageId - the ID of the image to deregister.
Returns:
true if successfull, false else

createKeypair

public com.xerox.amazonws.ec2.KeyPairInfo createKeypair(java.lang.String name)
Create a keypair.

Parameters:
name - Name of the keypair.
Returns:
KeyPairInfo or null in case of error.

deleteKeypair

public boolean deleteKeypair(java.lang.String name)
Delete a keypair.

Parameters:
name - Name of the keypair.
Returns:
true if successfull, false else

listKeypairs

public com.xerox.amazonws.ec2.KeyPairInfo[] listKeypairs()
List available keypairs.

Returns:
List of keypairs (may be empty) or null in case of error.

describeKeypair

public com.xerox.amazonws.ec2.KeyPairInfo describeKeypair(java.lang.String name)
Gets the properties of a specific keypair.

Parameters:
name - The name of the keypair.
Returns:
KeypairInfo or null in case of error or if keypair does not exist.

listAvailabilityZones

public com.xerox.amazonws.ec2.AvailabilityZone[] listAvailabilityZones()
Lists available Availability zones.

Returns:
Array of Availability zones.

getConsoleOutput

public com.xerox.amazonws.ec2.ConsoleOutput getConsoleOutput(java.lang.String instanceId)
Get console ouput for a particular instance.

Parameters:
instanceId - The instanceId of the instance to get the console output from.
Returns:
ConsoleOutput object containing output information or null in case of error.


Copyright © 2010 just works! Software. All Rights Reserved.