org.jclouds.compute.internal
Class BaseComputeService

java.lang.Object
  extended by org.jclouds.compute.internal.BaseComputeService
All Implemented Interfaces:
ComputeService

@Singleton
public class BaseComputeService
extends Object
implements ComputeService


Field Summary
protected  ComputeServiceContext context
           
protected  Map<String,org.jclouds.domain.Credentials> credentialStore
           
protected  org.jclouds.logging.Logger logger
           
 
Constructor Summary
protected BaseComputeService(ComputeServiceContext context, Map<String,org.jclouds.domain.Credentials> credentialStore, com.google.common.base.Supplier<Set<? extends Image>> images, com.google.common.base.Supplier<Set<? extends Hardware>> hardwareProfiles, com.google.common.base.Supplier<Set<? extends org.jclouds.domain.Location>> locations, ListNodesStrategy listNodesStrategy, GetImageStrategy getImageStrategy, GetNodeMetadataStrategy getNodeMetadataStrategy, CreateNodesInGroupThenAddToSet runNodesAndAddToSetStrategy, RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy, ResumeNodeStrategy resumeNodeStrategy, SuspendNodeStrategy suspendNodeStrategy, javax.inject.Provider<TemplateBuilder> templateBuilderProvider, javax.inject.Provider<TemplateOptions> templateOptionsProvider, com.google.common.base.Predicate<AtomicReference<NodeMetadata>> nodeRunning, com.google.common.base.Predicate<AtomicReference<NodeMetadata>> nodeTerminated, com.google.common.base.Predicate<AtomicReference<NodeMetadata>> nodeSuspended, InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory, org.jclouds.scriptbuilder.functions.InitAdminAccess initAdminAccess, RunScriptOnNode.Factory runScriptOnNodeFactory, PersistNodeCredentials persistNodeCredentials, ComputeServiceConstants.Timeouts timeouts, com.google.common.util.concurrent.ListeningExecutorService userExecutor, com.google.common.base.Optional<ImageExtension> imageExtension, com.google.common.base.Optional<SecurityGroupExtension> securityGroupExtension)
           
 
Method Summary
protected  void cleanUpIncidentalResourcesOfDeadNodes(Set<? extends NodeMetadata> deadNodes)
           
 Set<? extends NodeMetadata> createNodesInGroup(String group, int count)
          Like ComputeService.createNodesInGroup(String,int,TemplateOptions), except that the options are default, as specified in ComputeService.templateOptions().
 Set<? extends NodeMetadata> createNodesInGroup(String group, int count, Template template)
          The compute api treats nodes as a group based on the name you specify.
 Set<? extends NodeMetadata> createNodesInGroup(String group, int count, TemplateOptions templateOptions)
          Like ComputeService.createNodesInGroup(String,int,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 NodeMetadata> destroyNodesMatching(com.google.common.base.Predicate<NodeMetadata> filter)
          nodes matching the filter are treated as a logical set.
protected  NodeMetadata doDestroyNode(String id)
           
 ComputeServiceContext getContext()
          
 Image getImage(String id)
          Find an image by its id.
 com.google.common.base.Optional<ImageExtension> getImageExtension()
          Returns the ImageExtension for this provider if it implements it.
 NodeMetadata getNodeMetadata(String id)
          Find a node by its id.
 com.google.common.base.Optional<SecurityGroupExtension> getSecurityGroupExtension()
          Returns the SecurityGroupExtension for this provider if it implements it.
 Set<? extends org.jclouds.domain.Location> listAssignableLocations()
          The list locations command returns all the valid locations for nodes.
 Set<? extends Hardware> listHardwareProfiles()
          The list hardware profiles command shows you the options including virtual cpu count, memory, and disks.
 Set<? extends Image> listImages()
          Images define the operating system and metadata related to a node.
 Set<ComputeMetadata> listNodes()
          
 Set<? extends NodeMetadata> listNodesByIds(Iterable<String> ids)
          
 Set<? extends NodeMetadata> listNodesDetailsMatching(com.google.common.base.Predicate<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.
 Set<? extends NodeMetadata> rebootNodesMatching(com.google.common.base.Predicate<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.
 Set<? extends NodeMetadata> resumeNodesMatching(com.google.common.base.Predicate<NodeMetadata> filter)
          nodes matching the filter are treated as a logical set.
 ExecResponse runScriptOnNode(String id, org.jclouds.scriptbuilder.domain.Statement runScript)
          
 ExecResponse runScriptOnNode(String id, org.jclouds.scriptbuilder.domain.Statement runScript, RunScriptOptions options)
          Run the script on a specific node
 ExecResponse runScriptOnNode(String id, String runScript)
          
 ExecResponse runScriptOnNode(String id, String runScript, RunScriptOptions options)
          
 Map<NodeMetadata,ExecResponse> runScriptOnNodesMatching(com.google.common.base.Predicate<NodeMetadata> filter, org.jclouds.scriptbuilder.domain.Statement runScript)
          
 Map<NodeMetadata,ExecResponse> runScriptOnNodesMatching(com.google.common.base.Predicate<NodeMetadata> filter, org.jclouds.scriptbuilder.domain.Statement runScript, RunScriptOptions options)
          Run the script on all nodes with the specific predicate.
 Map<NodeMetadata,ExecResponse> runScriptOnNodesMatching(com.google.common.base.Predicate<NodeMetadata> filter, String runScript)
          
 Map<? extends NodeMetadata,ExecResponse> runScriptOnNodesMatching(com.google.common.base.Predicate<NodeMetadata> filter, String runScript, RunScriptOptions options)
           
 com.google.common.util.concurrent.ListenableFuture<ExecResponse> submitScriptOnNode(String id, org.jclouds.scriptbuilder.domain.Statement runScript, RunScriptOptions options)
          
 com.google.common.util.concurrent.ListenableFuture<ExecResponse> submitScriptOnNode(String id, String runScript, 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.
 Set<? extends NodeMetadata> suspendNodesMatching(com.google.common.base.Predicate<NodeMetadata> filter)
          nodes matching the filter are treated as a logical set.
 TemplateBuilder templateBuilder()
          Makes a new template builder for this service
 TemplateOptions templateOptions()
          Makes a new set of options for running nodes
protected  NodeMetadata updateNodeWithCredentialsIfPresent(NodeMetadata node, RunScriptOptions options)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

@Named(value="jclouds.compute")
protected org.jclouds.logging.Logger logger

context

protected final ComputeServiceContext context

credentialStore

protected final Map<String,org.jclouds.domain.Credentials> credentialStore
Constructor Detail

BaseComputeService

@Inject
protected BaseComputeService(ComputeServiceContext context,
                                    Map<String,org.jclouds.domain.Credentials> credentialStore,
                                    com.google.common.base.Supplier<Set<? extends Image>> images,
                                    com.google.common.base.Supplier<Set<? extends Hardware>> hardwareProfiles,
                                    com.google.common.base.Supplier<Set<? extends org.jclouds.domain.Location>> locations,
                                    ListNodesStrategy listNodesStrategy,
                                    GetImageStrategy getImageStrategy,
                                    GetNodeMetadataStrategy getNodeMetadataStrategy,
                                    CreateNodesInGroupThenAddToSet runNodesAndAddToSetStrategy,
                                    RebootNodeStrategy rebootNodeStrategy,
                                    DestroyNodeStrategy destroyNodeStrategy,
                                    ResumeNodeStrategy resumeNodeStrategy,
                                    SuspendNodeStrategy suspendNodeStrategy,
                                    javax.inject.Provider<TemplateBuilder> templateBuilderProvider,
                                    @Named(value="DEFAULT")
                                    javax.inject.Provider<TemplateOptions> templateOptionsProvider,
                                    @Named(value="jclouds.compute.timeout.node-running")
                                    com.google.common.base.Predicate<AtomicReference<NodeMetadata>> nodeRunning,
                                    @Named(value="jclouds.compute.timeout.node-terminated")
                                    com.google.common.base.Predicate<AtomicReference<NodeMetadata>> nodeTerminated,
                                    @Named(value="jclouds.compute.timeout.node-suspended")
                                    com.google.common.base.Predicate<AtomicReference<NodeMetadata>> nodeSuspended,
                                    InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory,
                                    org.jclouds.scriptbuilder.functions.InitAdminAccess initAdminAccess,
                                    RunScriptOnNode.Factory runScriptOnNodeFactory,
                                    PersistNodeCredentials persistNodeCredentials,
                                    ComputeServiceConstants.Timeouts timeouts,
                                    @Named(value="jclouds.user-threads")
                                    com.google.common.util.concurrent.ListeningExecutorService userExecutor,
                                    com.google.common.base.Optional<ImageExtension> imageExtension,
                                    com.google.common.base.Optional<SecurityGroupExtension> securityGroupExtension)
Method Detail

getContext

public ComputeServiceContext getContext()

Specified by:
getContext in interface ComputeService
Returns:
a reference to the context that created this ComputeService.

createNodesInGroup

public Set<? extends NodeMetadata> createNodesInGroup(String group,
                                                      int count,
                                                      Template template)
                                               throws RunNodesException
Description copied from interface: ComputeService
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.

Note

While naming constraints on the group name vary per cloud, lower-case alphanumeric with hyphens and least characters practical is most compatible.

Specified by:
createNodesInGroup in interface ComputeService
Parameters:
group - - common identifier to group nodes by
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:
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 NodeMetadata> createNodesInGroup(String group,
                                                      int count,
                                                      TemplateOptions templateOptions)
                                               throws RunNodesException
Description copied from interface: ComputeService
Like ComputeService.createNodesInGroup(String,int,Template), except that the template is default, equivalent to templateBuilder().any().options(templateOptions).

Specified by:
createNodesInGroup in interface ComputeService
Throws:
RunNodesException

createNodesInGroup

public Set<? extends NodeMetadata> createNodesInGroup(String group,
                                                      int count)
                                               throws RunNodesException
Description copied from interface: ComputeService
Like ComputeService.createNodesInGroup(String,int,TemplateOptions), except that the options are default, as specified in ComputeService.templateOptions().

Specified by:
createNodesInGroup in interface ComputeService
Throws:
RunNodesException

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 ComputeService

destroyNodesMatching

public Set<? extends NodeMetadata> destroyNodesMatching(com.google.common.base.Predicate<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 ComputeService
Returns:
list of nodes destroyed

doDestroyNode

@Nullable
protected NodeMetadata doDestroyNode(String id)
Parameters:
id -
Returns:
node that was deleted or null if it wasn't found

cleanUpIncidentalResourcesOfDeadNodes

protected void cleanUpIncidentalResourcesOfDeadNodes(Set<? extends NodeMetadata> deadNodes)

listNodes

public Set<ComputeMetadata> listNodes()

Specified by:
listNodes in interface ComputeService
Returns:
all nodes available to the current user. If possible, the returned set will include NodeMetadata objects.

listNodesByIds

public Set<? extends NodeMetadata> listNodesByIds(Iterable<String> ids)

Specified by:
listNodesByIds in interface ComputeService
Returns:
all nodes with one of the provided ids available to the current user.

listNodesDetailsMatching

public Set<? extends NodeMetadata> listNodesDetailsMatching(com.google.common.base.Predicate<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 ComputeService
Parameters:
filter - how to select the nodes you are interested in details on.

listHardwareProfiles

public Set<? extends 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.

note

This is a cached collection

Specified by:
listHardwareProfiles in interface ComputeService

listImages

public Set<? extends 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.

note

This is a cached collection

Specified by:
listImages in interface 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.

note

This is a cached collection

Specified by:
listAssignableLocations in interface ComputeService

templateBuilder

public TemplateBuilder templateBuilder()
Makes a new template builder for this service

Specified by:
templateBuilder in interface ComputeService

getNodeMetadata

public NodeMetadata getNodeMetadata(String id)
Find a node by its id.

Specified by:
getNodeMetadata in interface ComputeService

getImage

public 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 ComputeService

rebootNode

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

Specified by:
rebootNode in interface ComputeService

rebootNodesMatching

public Set<? extends NodeMetadata> rebootNodesMatching(com.google.common.base.Predicate<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 ComputeService
Returns:
list of nodes rebooted

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 ComputeService

resumeNodesMatching

public Set<? extends NodeMetadata> resumeNodesMatching(com.google.common.base.Predicate<NodeMetadata> filter)
nodes matching the filter are treated as a logical set. Using the resume command, you can save time by resuming the nodes in parallel.

note

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

Specified by:
resumeNodesMatching in interface ComputeService
Returns:
list of nodes resumed

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 ComputeService

suspendNodesMatching

public Set<? extends NodeMetadata> suspendNodesMatching(com.google.common.base.Predicate<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 ComputeService
Returns:
list of nodes suspended

runScriptOnNodesMatching

public Map<NodeMetadata,ExecResponse> runScriptOnNodesMatching(com.google.common.base.Predicate<NodeMetadata> filter,
                                                               String runScript)
                                                        throws RunScriptOnNodesException

Specified by:
runScriptOnNodesMatching in interface ComputeService
Throws:
RunScriptOnNodesException
See Also:
ComputeService.runScriptOnNodesMatching(Predicate, Statement, RunScriptOptions)

runScriptOnNodesMatching

public Map<NodeMetadata,ExecResponse> runScriptOnNodesMatching(com.google.common.base.Predicate<NodeMetadata> filter,
                                                               org.jclouds.scriptbuilder.domain.Statement runScript)
                                                        throws RunScriptOnNodesException

Specified by:
runScriptOnNodesMatching in interface ComputeService
Throws:
RunScriptOnNodesException
See Also:
ComputeService.runScriptOnNodesMatching(Predicate, Statement, RunScriptOptions)

runScriptOnNodesMatching

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

runScriptOnNodesMatching

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

Specified by:
runScriptOnNodesMatching in interface 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:
RunScriptOnNodesException - if anything goes wrong during script execution
See Also:
NodePredicates.runningInGroup(String), Statements

runScriptOnNode

public ExecResponse runScriptOnNode(String id,
                                    String runScript)

Specified by:
runScriptOnNode in interface ComputeService
See Also:
ComputeService.runScriptOnNode(String, String, RunScriptOptions)

runScriptOnNode

public ExecResponse runScriptOnNode(String id,
                                    String runScript,
                                    RunScriptOptions options)

Specified by:
runScriptOnNode in interface ComputeService
See Also:
ComputeService.runScriptOnNode(String, Statement, RunScriptOptions), Statements.exec(java.lang.String)

runScriptOnNode

public ExecResponse runScriptOnNode(String id,
                                    org.jclouds.scriptbuilder.domain.Statement runScript)

Specified by:
runScriptOnNode in interface ComputeService
See Also:
ComputeService.runScriptOnNode(String, Statement, RunScriptOptions)

runScriptOnNode

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

Specified by:
runScriptOnNode in interface 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
See Also:
NodePredicates.runningInGroup(String), Statements

submitScriptOnNode

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

Specified by:
submitScriptOnNode in interface 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
See Also:
NodePredicates.runningInGroup(String), Statements

submitScriptOnNode

public com.google.common.util.concurrent.ListenableFuture<ExecResponse> submitScriptOnNode(String id,
                                                                                           org.jclouds.scriptbuilder.domain.Statement runScript,
                                                                                           RunScriptOptions options)

Specified by:
submitScriptOnNode in interface ComputeService

templateOptions

public TemplateOptions templateOptions()
Description copied from interface: ComputeService
Makes a new set of options for running nodes

Specified by:
templateOptions in interface ComputeService

updateNodeWithCredentialsIfPresent

protected NodeMetadata updateNodeWithCredentialsIfPresent(NodeMetadata node,
                                                          RunScriptOptions options)

getImageExtension

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

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

getSecurityGroupExtension

public com.google.common.base.Optional<SecurityGroupExtension> getSecurityGroupExtension()
Returns the SecurityGroupExtension for this provider if it implements it.

Specified by:
getSecurityGroupExtension in interface ComputeService
Returns:
an optional of the SecurityGroupExtension or Optional.absent() if not implemented


Copyright © 2009-2014 The Apache Software Foundation. All Rights Reserved.