org.jclouds.karaf.core
Class ComputeServiceEventProxy

java.lang.Object
  extended by org.jclouds.karaf.core.ComputeServiceEventProxy
All Implemented Interfaces:
org.jclouds.compute.ComputeService

public class ComputeServiceEventProxy
extends Object
implements org.jclouds.compute.ComputeService

A proxy implementations of the ComputeService which delegates calls to the underlying impl and notifies NodeListeners about node creation/destruction events.


Constructor Summary
ComputeServiceEventProxy(org.osgi.framework.BundleContext bundleContext, org.jclouds.compute.ComputeService computeService)
          Constructor
 
Method Summary
 Set<? extends org.jclouds.compute.domain.NodeMetadata> createNodesInGroup(String group, int count)
          Like ComputeService.createNodesInGroup(String, int, org.jclouds.compute.options.TemplateOptions), except that the options are default, as specified in ComputeService.templateOptions().
 Set<? extends org.jclouds.compute.domain.NodeMetadata> createNodesInGroup(String group, int count, org.jclouds.compute.domain.Template template)
          The compute api treats nodes as a group based on the name you specify.
 Set<? extends org.jclouds.compute.domain.NodeMetadata> createNodesInGroup(String group, int count, org.jclouds.compute.options.TemplateOptions templateOptions)
          Like ComputeService.createNodesInGroup(String, int, org.jclouds.compute.domain.Template), except that the template is default, equivalent to templateBuilder().any().options(templateOptions).
 void destroyNode(String id)
          destroy the node, given its id.
 Set<? extends org.jclouds.compute.domain.NodeMetadata> destroyNodesMatching(com.google.common.base.Predicate<org.jclouds.compute.domain.NodeMetadata> filter)
          nodes matching the filter are treated as a logical set.
 org.jclouds.compute.ComputeServiceContext getContext()
           
 org.jclouds.compute.domain.Image getImage(String id)
          Find an image by its id.
 com.google.common.base.Optional<org.jclouds.compute.extensions.ImageExtension> getImageExtension()
          Returns the ImageExtension for this provider if it implements it.
 org.jclouds.compute.domain.NodeMetadata getNodeMetadata(String id)
          Find a node by its id.
 Set<? extends org.jclouds.domain.Location> listAssignableLocations()
          The list locations command returns all the valid locations for nodes.
 Set<? extends org.jclouds.compute.domain.Hardware> listHardwareProfiles()
          The list hardware profiles command shows you the options including virtual cpu count, memory, and disks.
 Set<? extends org.jclouds.compute.domain.Image> listImages()
          Images define the operating system and metadata related to a node.
 Set<? extends org.jclouds.compute.domain.ComputeMetadata> listNodes()
          all nodes available to the current user by id.
 Set<? extends org.jclouds.compute.domain.NodeMetadata> listNodesDetailsMatching(com.google.common.base.Predicate<org.jclouds.compute.domain.ComputeMetadata> filter)
          get all nodes including details such as image and ip addresses even if it incurs extra requests to the service.
 void rebootNode(String id)
          reboot the node, given its id.
 void rebootNodesMatching(com.google.common.base.Predicate<org.jclouds.compute.domain.NodeMetadata> filter)
          nodes matching the filter are treated as a logical set.
 void resumeNode(String id)
          resume the node from suspended state, given its id.
 void resumeNodesMatching(com.google.common.base.Predicate<org.jclouds.compute.domain.NodeMetadata> filter)
          nodes matching the filter are treated as a logical set.
 org.jclouds.compute.domain.ExecResponse runScriptOnNode(String id, org.jclouds.scriptbuilder.domain.Statement runScript)
           
 org.jclouds.compute.domain.ExecResponse runScriptOnNode(String id, org.jclouds.scriptbuilder.domain.Statement runScript, org.jclouds.compute.options.RunScriptOptions options)
          Run the script on a specific node
 org.jclouds.compute.domain.ExecResponse runScriptOnNode(String id, String runScript)
           
 org.jclouds.compute.domain.ExecResponse runScriptOnNode(String id, String runScript, org.jclouds.compute.options.RunScriptOptions options)
           
 Map<? extends org.jclouds.compute.domain.NodeMetadata,org.jclouds.compute.domain.ExecResponse> runScriptOnNodesMatching(com.google.common.base.Predicate<org.jclouds.compute.domain.NodeMetadata> filter, org.jclouds.scriptbuilder.domain.Statement runScript)
           
 Map<? extends org.jclouds.compute.domain.NodeMetadata,org.jclouds.compute.domain.ExecResponse> runScriptOnNodesMatching(com.google.common.base.Predicate<org.jclouds.compute.domain.NodeMetadata> filter, org.jclouds.scriptbuilder.domain.Statement runScript, org.jclouds.compute.options.RunScriptOptions options)
          Run the script on all nodes with the specific predicate.
 Map<? extends org.jclouds.compute.domain.NodeMetadata,org.jclouds.compute.domain.ExecResponse> runScriptOnNodesMatching(com.google.common.base.Predicate<org.jclouds.compute.domain.NodeMetadata> filter, String runScript)
           
 Map<? extends org.jclouds.compute.domain.NodeMetadata,org.jclouds.compute.domain.ExecResponse> runScriptOnNodesMatching(com.google.common.base.Predicate<org.jclouds.compute.domain.NodeMetadata> filter, String runScript, org.jclouds.compute.options.RunScriptOptions options)
           
 com.google.common.util.concurrent.ListenableFuture<org.jclouds.compute.domain.ExecResponse> submitScriptOnNode(String id, org.jclouds.scriptbuilder.domain.Statement runScript, org.jclouds.compute.options.RunScriptOptions options)
          Run the script on a specific node in the background, typically as nohup
 void suspendNode(String id)
          suspend the node, given its id.
 void suspendNodesMatching(com.google.common.base.Predicate<org.jclouds.compute.domain.NodeMetadata> filter)
          nodes matching the filter are treated as a logical set.
 org.jclouds.compute.domain.TemplateBuilder templateBuilder()
          Makes a new template builder for this service
 org.jclouds.compute.options.TemplateOptions templateOptions()
          Makes a new set of options for running nodes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ComputeServiceEventProxy

public ComputeServiceEventProxy(org.osgi.framework.BundleContext bundleContext,
                                org.jclouds.compute.ComputeService computeService)
Constructor

Parameters:
bundleContext -
computeService -
Method Detail

getContext

public org.jclouds.compute.ComputeServiceContext getContext()
Specified by:
getContext in interface org.jclouds.compute.ComputeService
Returns:
a reference to the context that created this ComputeService.

templateBuilder

public org.jclouds.compute.domain.TemplateBuilder templateBuilder()
Makes a new template builder for this service

Specified by:
templateBuilder in interface org.jclouds.compute.ComputeService

templateOptions

public org.jclouds.compute.options.TemplateOptions templateOptions()
Makes a new set of options for running nodes

Specified by:
templateOptions in interface org.jclouds.compute.ComputeService

listHardwareProfiles

public Set<? extends org.jclouds.compute.domain.Hardware> listHardwareProfiles()
The list hardware profiles command shows you the options including virtual cpu count, memory, and disks. cpu count is not a portable quantity across clouds, as they are measured differently. However, it is a good indicator of relative speed within a cloud. memory is measured in megabytes and disks in gigabytes.

Specified by:
listHardwareProfiles in interface org.jclouds.compute.ComputeService
Returns:
a map of hardware profiles by ID, conceding that in some clouds the "id" is not used.

listImages

public Set<? extends org.jclouds.compute.domain.Image> listImages()
Images define the operating system and metadata related to a node. In some clouds, Images are bound to a specific region, and their identifiers are different across these regions. For this reason, you should consider matching image requirements like operating system family with TemplateBuilder as opposed to choosing an image explicitly. The getImages() command returns a map of images by id.

Specified by:
listImages in interface org.jclouds.compute.ComputeService

listNodes

public Set<? extends org.jclouds.compute.domain.ComputeMetadata> listNodes()
all nodes available to the current user by id. If possible, the returned set will include NodeMetadata objects.

Specified by:
listNodes in interface org.jclouds.compute.ComputeService

listAssignableLocations

public Set<? extends org.jclouds.domain.Location> listAssignableLocations()
The list locations command returns all the valid locations for nodes. A location has a scope, which is typically region or zone. A region is a general area, like eu-west, where a zone is similar to a datacenter. If a location has a parent, that implies it is within that location. For example a location can be a rack, whose parent is likely to be a zone.

Specified by:
listAssignableLocations in interface org.jclouds.compute.ComputeService

createNodesInGroup

public Set<? extends org.jclouds.compute.domain.NodeMetadata> createNodesInGroup(String group,
                                                                                 int count,
                                                                                 org.jclouds.compute.domain.Template template)
                                                                          throws org.jclouds.compute.RunNodesException
The compute api treats nodes as a group based on the name you specify. Using this group, you can choose to operate one or many nodes as a logical unit without regard to the implementation details of the cloud.

The set that is returned will include credentials you can use to ssh into the nodes. The "key" part of the credentials is either a password or a private key. You have to inspect the value to determine this.

 if (node.getCredentials().key.startsWith("-----BEGIN RSA PRIVATE KEY-----"))
    // it is a private key, not a password.
 

Note. if all you want to do is execute a script at bootup, you should consider use of the runscript option.

If resources such as security groups are needed, they will be reused or created for you. Inbound port 22 will always be opened up.

Specified by:
createNodesInGroup in interface org.jclouds.compute.ComputeService
Parameters:
group - - common identifier to group nodes by, cannot contain hyphens
count - - how many to fire up.
template - - how to configure the nodes
Returns:
all of the nodes the api was able to launch in a running state.
Throws:
org.jclouds.compute.RunNodesException - when there's a problem applying options to nodes. Note that successful and failed nodes are a part of this exception, so be sure to inspect this carefully.

createNodesInGroup

public Set<? extends org.jclouds.compute.domain.NodeMetadata> createNodesInGroup(String group,
                                                                                 int count,
                                                                                 org.jclouds.compute.options.TemplateOptions templateOptions)
                                                                          throws org.jclouds.compute.RunNodesException
Like ComputeService.createNodesInGroup(String, int, org.jclouds.compute.domain.Template), except that the template is default, equivalent to templateBuilder().any().options(templateOptions).

Specified by:
createNodesInGroup in interface org.jclouds.compute.ComputeService
Throws:
org.jclouds.compute.RunNodesException

createNodesInGroup

public Set<? extends org.jclouds.compute.domain.NodeMetadata> createNodesInGroup(String group,
                                                                                 int count)
                                                                          throws org.jclouds.compute.RunNodesException
Like ComputeService.createNodesInGroup(String, int, org.jclouds.compute.options.TemplateOptions), except that the options are default, as specified in ComputeService.templateOptions().

Specified by:
createNodesInGroup in interface org.jclouds.compute.ComputeService
Throws:
org.jclouds.compute.RunNodesException

resumeNode

public void resumeNode(String id)
resume the node from suspended state, given its id.

note

affected nodes may not resume with the same IP address(es)

Specified by:
resumeNode in interface org.jclouds.compute.ComputeService

resumeNodesMatching

public void resumeNodesMatching(com.google.common.base.Predicate<org.jclouds.compute.domain.NodeMetadata> filter)
nodes matching the filter are treated as a logical set. Using the resume command, you can save time by resumeing the nodes in parallel.

note

affected nodes may not resume with the same IP address(es)

Specified by:
resumeNodesMatching in interface org.jclouds.compute.ComputeService
Throws:
UnsupportedOperationException - if the underlying provider doesn't support suspend/resume
NoSuchElementException - if no nodes matched the predicate specified

suspendNode

public void suspendNode(String id)
suspend the node, given its id. This will result in suspended state.

note

affected nodes may not resume with the same IP address(es)

Specified by:
suspendNode in interface org.jclouds.compute.ComputeService
Throws:
UnsupportedOperationException - if the underlying provider doesn't support suspend/resume

suspendNodesMatching

public void suspendNodesMatching(com.google.common.base.Predicate<org.jclouds.compute.domain.NodeMetadata> filter)
nodes matching the filter are treated as a logical set. Using the suspend command, you can save time by suspending the nodes in parallel.

note

affected nodes may not resume with the same IP address(es)

Specified by:
suspendNodesMatching in interface org.jclouds.compute.ComputeService
Throws:
UnsupportedOperationException - if the underlying provider doesn't support suspend/resume
NoSuchElementException - if no nodes matched the predicate specified

destroyNode

public void destroyNode(String id)
destroy the node, given its id. If it is the only node in a tag set, the dependent resources will also be destroyed.

Specified by:
destroyNode in interface org.jclouds.compute.ComputeService

destroyNodesMatching

public Set<? extends org.jclouds.compute.domain.NodeMetadata> destroyNodesMatching(com.google.common.base.Predicate<org.jclouds.compute.domain.NodeMetadata> filter)
nodes matching the filter are treated as a logical set. Using the delete command, you can save time by removing the nodes in parallel. When the last node in a set is destroyed, any indirect resources it uses, such as keypairs, are also destroyed.

Specified by:
destroyNodesMatching in interface org.jclouds.compute.ComputeService
Returns:
list of nodes destroyed

rebootNode

public void rebootNode(String id)
reboot the node, given its id.

Specified by:
rebootNode in interface org.jclouds.compute.ComputeService

rebootNodesMatching

public void rebootNodesMatching(com.google.common.base.Predicate<org.jclouds.compute.domain.NodeMetadata> filter)
nodes matching the filter are treated as a logical set. Using this command, you can save time by rebooting the nodes in parallel.

Specified by:
rebootNodesMatching in interface org.jclouds.compute.ComputeService
Throws:
NoSuchElementException - if no nodes matched the predicate specified

getNodeMetadata

public org.jclouds.compute.domain.NodeMetadata getNodeMetadata(String id)
Find a node by its id.

Specified by:
getNodeMetadata in interface org.jclouds.compute.ComputeService

listNodesDetailsMatching

public Set<? extends org.jclouds.compute.domain.NodeMetadata> listNodesDetailsMatching(com.google.common.base.Predicate<org.jclouds.compute.domain.ComputeMetadata> filter)
get all nodes including details such as image and ip addresses even if it incurs extra requests to the service.

Specified by:
listNodesDetailsMatching in interface org.jclouds.compute.ComputeService
Parameters:
filter - how to select the nodes you are interested in details on.

runScriptOnNodesMatching

public Map<? extends org.jclouds.compute.domain.NodeMetadata,org.jclouds.compute.domain.ExecResponse> runScriptOnNodesMatching(com.google.common.base.Predicate<org.jclouds.compute.domain.NodeMetadata> filter,
                                                                                                                               String runScript)
                                                                                                                        throws org.jclouds.compute.RunScriptOnNodesException
Specified by:
runScriptOnNodesMatching in interface org.jclouds.compute.ComputeService
Throws:
org.jclouds.compute.RunScriptOnNodesException
See Also:
ComputeService.runScriptOnNodesMatching(com.google.common.base.Predicate, org.jclouds.scriptbuilder.domain.Statement, org.jclouds.compute.options.RunScriptOptions)

runScriptOnNodesMatching

public Map<? extends org.jclouds.compute.domain.NodeMetadata,org.jclouds.compute.domain.ExecResponse> runScriptOnNodesMatching(com.google.common.base.Predicate<org.jclouds.compute.domain.NodeMetadata> filter,
                                                                                                                               org.jclouds.scriptbuilder.domain.Statement runScript)
                                                                                                                        throws org.jclouds.compute.RunScriptOnNodesException
Specified by:
runScriptOnNodesMatching in interface org.jclouds.compute.ComputeService
Throws:
org.jclouds.compute.RunScriptOnNodesException
See Also:
ComputeService.runScriptOnNodesMatching(com.google.common.base.Predicate, org.jclouds.scriptbuilder.domain.Statement, org.jclouds.compute.options.RunScriptOptions)

runScriptOnNodesMatching

public Map<? extends org.jclouds.compute.domain.NodeMetadata,org.jclouds.compute.domain.ExecResponse> runScriptOnNodesMatching(com.google.common.base.Predicate<org.jclouds.compute.domain.NodeMetadata> filter,
                                                                                                                               String runScript,
                                                                                                                               org.jclouds.compute.options.RunScriptOptions options)
                                                                                                                        throws org.jclouds.compute.RunScriptOnNodesException
Specified by:
runScriptOnNodesMatching in interface org.jclouds.compute.ComputeService
Throws:
org.jclouds.compute.RunScriptOnNodesException
See Also:
ComputeService.runScriptOnNodesMatching(com.google.common.base.Predicate, org.jclouds.scriptbuilder.domain.Statement, org.jclouds.compute.options.RunScriptOptions)

runScriptOnNodesMatching

public Map<? extends org.jclouds.compute.domain.NodeMetadata,org.jclouds.compute.domain.ExecResponse> runScriptOnNodesMatching(com.google.common.base.Predicate<org.jclouds.compute.domain.NodeMetadata> filter,
                                                                                                                               org.jclouds.scriptbuilder.domain.Statement runScript,
                                                                                                                               org.jclouds.compute.options.RunScriptOptions options)
                                                                                                                        throws org.jclouds.compute.RunScriptOnNodesException
Run the script on all nodes with the specific predicate.

Specified by:
runScriptOnNodesMatching in interface org.jclouds.compute.ComputeService
Parameters:
filter - Predicate-based filter to define on which nodes the script is to be executed
runScript - statement containing the script to run
options - nullable options to how to run the script, whether to override credentials
Returns:
map with node identifiers and corresponding responses
Throws:
NoSuchElementException - if no nodes matched the predicate specified
org.jclouds.compute.RunScriptOnNodesException - if anything goes wrong during script execution
See Also:
org.jclouds.compute.predicates.NodePredicates#runningInGroup(String), Statements

runScriptOnNode

public org.jclouds.compute.domain.ExecResponse runScriptOnNode(String id,
                                                               org.jclouds.scriptbuilder.domain.Statement runScript,
                                                               org.jclouds.compute.options.RunScriptOptions options)
Run the script on a specific node

Specified by:
runScriptOnNode in interface org.jclouds.compute.ComputeService
Parameters:
id - node the script is to be executed on
runScript - statement containing the script to run
options - nullable options to how to run the script, whether to override credentials
Returns:
map with node identifiers and corresponding responses
Throws:
NoSuchElementException - if the node is not found
IllegalStateException - if the node is not in running state
org.jclouds.compute.callables.ScriptStillRunningException - if the script was still running after org.jclouds.compute.reference.ComputeServiceConstants.Timeouts#scriptComplete
See Also:
org.jclouds.compute.predicates.NodePredicates#runningInGroup(String), Statements

submitScriptOnNode

@Beta
public com.google.common.util.concurrent.ListenableFuture<org.jclouds.compute.domain.ExecResponse> submitScriptOnNode(String id,
                                                                                                                           org.jclouds.scriptbuilder.domain.Statement runScript,
                                                                                                                           org.jclouds.compute.options.RunScriptOptions options)
Run the script on a specific node in the background, typically as nohup

Specified by:
submitScriptOnNode in interface org.jclouds.compute.ComputeService
Parameters:
id - node the script is to be executed on
runScript - statement containing the script to run
options - nullable options to how to run the script, whether to override credentials
Returns:
map with node identifiers and corresponding responses
Throws:
NoSuchElementException - if the node is not found
IllegalStateException - if the node is not in running state
See Also:
org.jclouds.compute.predicates.NodePredicates#runningInGroup(String), Statements

runScriptOnNode

public org.jclouds.compute.domain.ExecResponse runScriptOnNode(String id,
                                                               org.jclouds.scriptbuilder.domain.Statement runScript)
Specified by:
runScriptOnNode in interface org.jclouds.compute.ComputeService
See Also:
runScriptOnNode(String, org.jclouds.scriptbuilder.domain.Statement, org.jclouds.compute.options.RunScriptOptions)

runScriptOnNode

public org.jclouds.compute.domain.ExecResponse runScriptOnNode(String id,
                                                               String runScript,
                                                               org.jclouds.compute.options.RunScriptOptions options)
Specified by:
runScriptOnNode in interface org.jclouds.compute.ComputeService
See Also:
runScriptOnNode(String, org.jclouds.scriptbuilder.domain.Statement, org.jclouds.compute.options.RunScriptOptions), Statements.exec(java.lang.String)

runScriptOnNode

public org.jclouds.compute.domain.ExecResponse runScriptOnNode(String id,
                                                               String runScript)
Specified by:
runScriptOnNode in interface org.jclouds.compute.ComputeService
See Also:
runScriptOnNode(String, String, org.jclouds.compute.options.RunScriptOptions)

getImage

public org.jclouds.compute.domain.Image getImage(String id)
Find an image by its id.

note

This is an uncached call to the backend service

Specified by:
getImage in interface org.jclouds.compute.ComputeService

getImageExtension

public com.google.common.base.Optional<org.jclouds.compute.extensions.ImageExtension> getImageExtension()
Returns the ImageExtension for this provider if it implements it.

Specified by:
getImageExtension in interface org.jclouds.compute.ComputeService
Returns:
an optional of the ImageExtension or Optional.absent() if not implemented


Copyright © 2012. All Rights Reserved.