com.atlassian.bamboo.agent.elastic.server
Class ElasticInstanceManagerImpl

java.lang.Object
  extended by com.atlassian.bamboo.agent.elastic.server.ElasticInstanceManagerImpl
All Implemented Interfaces:
ElasticInstanceManager, ElasticAgentTunnelPorts

public class ElasticInstanceManagerImpl
extends Object
implements ElasticInstanceManager


Field Summary
 
Fields inherited from interface com.atlassian.bamboo.agent.elastic.server.ElasticInstanceManager
BAMBOO_CONTROL_TAG, DEFAULT_INSTANCE_TYPE_32, DEFAULT_INSTANCE_TYPE_64, DEFAULT_PRODUCT_FOR_LINUX_PLATFORM, DEFAULT_PRODUCT_FOR_WINDOWS_PLATFORM, ELASTIC_BAMBOO_KEY_PAIR, ELASTIC_BAMBOO_KEY_PAIR_FILE, ELASTIC_BAMBOO_SECURITY_GROUP
 
Constructor Summary
ElasticInstanceManagerImpl(AwsAccountBean awsAccountBean, AdministrationConfigurationAccessor administrationConfigurationAccessor, int startupTimeoutSeconds, ScheduledExecutorService executor, KeyStoreFactory keyStoreFactory, SSLContextFactory sslContextFactory, BootstrapManager bootstrapManager, ErrorHandler errorHandler, SpotInstanceConfigurationAccessor spotInstanceConfigurationAccessor)
           
 
Method Summary
 void addElasticLogEntry(org.apache.log4j.Logger log, String logEntry)
           
 boolean cancelSpotRequests(com.atlassian.aws.AWSAccount awsAccount)
          Cancel spot instance requests.
 void ensureLoginKeyPairExists(com.atlassian.aws.AWSAccount awsAccount, String keyPair)
          Ensures that a key pair, named "elasticbamboo", has been defined in the configured AWS account.
 int getAgentSideHttpPort()
          The TCP port upon which the Elastic Agent listens for HTTP traffic intended for the Bamboo Server.
 int getAgentSideJmsPort()
          The TCP port upon which the Elastic Agent listens for JMS traffic intended for the Bamboo Server.
 com.google.common.collect.SetMultimap<ElasticImageConfiguration,RemoteElasticInstance> getAllElasticAgentsAsMap()
          Returns all elastic instances in a SetMultimap, keyed by the ElasticImageConfiguration
 List<RemoteElasticInstance> getAllElasticRemoteAgents()
          Returns all elastic instances.
 Set<com.atlassian.aws.ec2.EC2InstanceType> getAllowedInstanceTypes()
           
 List<String> getElasticAgentLogs()
          Retrieve activity logs
 RemoteElasticInstance getElasticRemoteAgentByInstanceId(String instanceId)
          Retrieve elastic instance of the given ID.
 List<RemoteElasticInstance> getElasticRemoteAgents()
          Retrieve a readonly list of any currently existing EC2 instances
 List<RemoteElasticInstance> getElasticRemoteAgentsByConfiguration(ElasticImageConfiguration elasticImageConfiguration)
           
 List<RemoteElasticInstance> getElasticRemoteAgentsByConfiguration(long id)
           
 String getInstanceLogs(String instanceId)
          Fetch console output of a running EC2 instance.
 List<RemoteElasticInstance> getInstancesWithStartingAgents()
          Returns those elastic instances that have already started but their agents have not yet connected to the bamboo server.
 List<RemoteElasticInstance> getRequestedElasticRemoteAgents()
          Returns the elastic instances which have been requested but not yet identified.
 List<RemoteElasticInstance> getStartingElasticInstances()
          Return the elastic instances which have been identified but not started up yet, i.e.
 int getTotalNumElasticRemoteAgents()
          Return how many license spots are currently being occupied by elastic instances (pending and running)
 int getTunnelPort()
          The TCP port upon which Elastic Agents listens for incoming tunnel connections from the Bamboo Server.
 boolean isElasticSupportEnabled()
           
 boolean isInstanceKnown(String instanceId)
          Checks if an AWS instance with the given ID exists and is managed by this Bamboo server.
 RemoteElasticInstance newElasticAgent(RemoteElasticInstanceListener listener, com.atlassian.aws.AWSAccount awsAccount, AgentManager agentManager, ElasticImageConfiguration elasticImageConfiguration, com.atlassian.aws.ec2.InstanceLaunchConfigurationBuilder instanceLaunchConfigurationBuilder)
           
 void onInstanceIdentified(RemoteElasticInstance instance)
          Tell the manager that the instance is up and running
 void onInstanceRunning(RemoteElasticInstance instance)
          Invoked when the instance enters the 'running' state
 void registerElasticAgentStopped(RemoteElasticInstance instance)
          Remove and EC2 instance from the "currently Running map
 void setTunnelTimeoutMinutes(int tunnelTimeoutMinutes)
           
 boolean validateAwsCredentials(com.atlassian.aws.ec2.awssdk.AwsSupportConstants.Region region, String awsAccessID, String awsSecretKey, ErrorCollection errorCollection)
          Validate a set of supplied AWS credentials.
 boolean validateAwsCredentials(String awsAccessID, String awsSecretKey, ErrorCollection errorCollection)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ElasticInstanceManagerImpl

public ElasticInstanceManagerImpl(AwsAccountBean awsAccountBean,
                                  AdministrationConfigurationAccessor administrationConfigurationAccessor,
                                  int startupTimeoutSeconds,
                                  ScheduledExecutorService executor,
                                  KeyStoreFactory keyStoreFactory,
                                  SSLContextFactory sslContextFactory,
                                  BootstrapManager bootstrapManager,
                                  ErrorHandler errorHandler,
                                  SpotInstanceConfigurationAccessor spotInstanceConfigurationAccessor)
Method Detail

newElasticAgent

public RemoteElasticInstance newElasticAgent(RemoteElasticInstanceListener listener,
                                             com.atlassian.aws.AWSAccount awsAccount,
                                             @NotNull
                                             AgentManager agentManager,
                                             @NotNull
                                             ElasticImageConfiguration elasticImageConfiguration,
                                             @NotNull
                                             com.atlassian.aws.ec2.InstanceLaunchConfigurationBuilder instanceLaunchConfigurationBuilder)
                                      throws NoSuchAlgorithmException,
                                             KeyManagementException,
                                             IOException,
                                             CertificateException,
                                             UnrecoverableKeyException,
                                             KeyStoreException
Specified by:
newElasticAgent in interface ElasticInstanceManager
Throws:
NoSuchAlgorithmException
KeyManagementException
IOException
CertificateException
UnrecoverableKeyException
KeyStoreException

ensureLoginKeyPairExists

public void ensureLoginKeyPairExists(com.atlassian.aws.AWSAccount awsAccount,
                                     String keyPair)
                              throws com.atlassian.aws.AWSException
Description copied from interface: ElasticInstanceManager

Ensures that a key pair, named "elasticbamboo", has been defined in the configured AWS account.

Specified by:
ensureLoginKeyPairExists in interface ElasticInstanceManager
Parameters:
awsAccount - that should contain the key pair
Throws:
com.atlassian.aws.AWSException - if there is a problem communicating with EC2.

validateAwsCredentials

public boolean validateAwsCredentials(com.atlassian.aws.ec2.awssdk.AwsSupportConstants.Region region,
                                      String awsAccessID,
                                      String awsSecretKey,
                                      ErrorCollection errorCollection)
Description copied from interface: ElasticInstanceManager

Validate a set of supplied AWS credentials.

Specified by:
validateAwsCredentials in interface ElasticInstanceManager
awsAccessID - The Access ID of the Amazon Web Services Account
awsSecretKey - The Secret Key of the Amazon Web Services Account
errorCollection - An ErrorCollection to which validation errors should be added, or null if validation errors are not required.
Returns:
true if the supplied credentials are successfully validated; false otherwise.

validateAwsCredentials

public boolean validateAwsCredentials(String awsAccessID,
                                      String awsSecretKey,
                                      ErrorCollection errorCollection)
Specified by:
validateAwsCredentials in interface ElasticInstanceManager

getElasticRemoteAgents

@NotNull
public List<RemoteElasticInstance> getElasticRemoteAgents()
Description copied from interface: ElasticInstanceManager
Retrieve a readonly list of any currently existing EC2 instances

Specified by:
getElasticRemoteAgents in interface ElasticInstanceManager
Returns:
List of RemoteElasticInstance

getElasticRemoteAgentsByConfiguration

@NotNull
public List<RemoteElasticInstance> getElasticRemoteAgentsByConfiguration(ElasticImageConfiguration elasticImageConfiguration)
Specified by:
getElasticRemoteAgentsByConfiguration in interface ElasticInstanceManager

getElasticRemoteAgentsByConfiguration

@NotNull
public List<RemoteElasticInstance> getElasticRemoteAgentsByConfiguration(long id)
Specified by:
getElasticRemoteAgentsByConfiguration in interface ElasticInstanceManager

getElasticRemoteAgentByInstanceId

@Nullable
public RemoteElasticInstance getElasticRemoteAgentByInstanceId(String instanceId)
Description copied from interface: ElasticInstanceManager
Retrieve elastic instance of the given ID.

Specified by:
getElasticRemoteAgentByInstanceId in interface ElasticInstanceManager
Parameters:
instanceId - of the instance
Returns:
the elastic remote agent specific to the provided instance id

getRequestedElasticRemoteAgents

@NotNull
public List<RemoteElasticInstance> getRequestedElasticRemoteAgents()
Description copied from interface: ElasticInstanceManager
Returns the elastic instances which have been requested but not yet identified.

Specified by:
getRequestedElasticRemoteAgents in interface ElasticInstanceManager
Returns:
List of elastic instances which have been requested but not yet started up yet..

getStartingElasticInstances

@NotNull
public List<RemoteElasticInstance> getStartingElasticInstances()
Description copied from interface: ElasticInstanceManager
Return the elastic instances which have been identified but not started up yet, i.e. those instances that are IDENTIFIED pending to move to RUNNING state. The list does not include those instances that have been requested but not yet identified.

Specified by:
getStartingElasticInstances in interface ElasticInstanceManager
Returns:
List of elastic instances which have been requested and identified but not yet started up yet..

getInstancesWithStartingAgents

@NotNull
public List<RemoteElasticInstance> getInstancesWithStartingAgents()
Description copied from interface: ElasticInstanceManager
Returns those elastic instances that have already started but their agents have not yet connected to the bamboo server. Once the elastic instance is started it launches a bamboo agents that connects to the bamboo server. There is a period of time when the instance has already started (and therefore it is not returned by ElasticInstanceManager.getRequestedElasticRemoteAgents()) but the agent on the instance has not yet connected to the bamboo server. Elastic instances in such state are returned by this method and the list is a subset of the list returned by ElasticInstanceManager.getElasticRemoteAgents().

Specified by:
getInstancesWithStartingAgents in interface ElasticInstanceManager
Returns:
List of RemoteElasticInstance

getAllElasticRemoteAgents

public List<RemoteElasticInstance> getAllElasticRemoteAgents()
Description copied from interface: ElasticInstanceManager
Returns all elastic instances. It includes requested agents as well as active agents

Specified by:
getAllElasticRemoteAgents in interface ElasticInstanceManager
Returns:

getAllElasticAgentsAsMap

public com.google.common.collect.SetMultimap<ElasticImageConfiguration,RemoteElasticInstance> getAllElasticAgentsAsMap()
Description copied from interface: ElasticInstanceManager
Returns all elastic instances in a SetMultimap, keyed by the ElasticImageConfiguration

Specified by:
getAllElasticAgentsAsMap in interface ElasticInstanceManager
Returns:

getTotalNumElasticRemoteAgents

public int getTotalNumElasticRemoteAgents()
Description copied from interface: ElasticInstanceManager
Return how many license spots are currently being occupied by elastic instances (pending and running)

Specified by:
getTotalNumElasticRemoteAgents in interface ElasticInstanceManager
Returns:
Number of license slots currently occupied by elastic instances (pending and running).

onInstanceIdentified

public void onInstanceIdentified(@NotNull
                                 RemoteElasticInstance instance)
Description copied from interface: ElasticInstanceManager
Tell the manager that the instance is up and running

Specified by:
onInstanceIdentified in interface ElasticInstanceManager
Parameters:
instance - the instance identified

onInstanceRunning

public void onInstanceRunning(@NotNull
                              RemoteElasticInstance instance)
Description copied from interface: ElasticInstanceManager
Invoked when the instance enters the 'running' state

Specified by:
onInstanceRunning in interface ElasticInstanceManager
Parameters:
instance - the instance that entered running state

cancelSpotRequests

public boolean cancelSpotRequests(@NotNull
                                  com.atlassian.aws.AWSAccount awsAccount)
Description copied from interface: ElasticInstanceManager
Cancel spot instance requests.

Specified by:
cancelSpotRequests in interface ElasticInstanceManager
Parameters:
awsAccount - account
Returns:
true if at least one request was found and cancelled

registerElasticAgentStopped

public void registerElasticAgentStopped(@NotNull
                                        RemoteElasticInstance instance)
Description copied from interface: ElasticInstanceManager
Remove and EC2 instance from the "currently Running map

Specified by:
registerElasticAgentStopped in interface ElasticInstanceManager
Parameters:
instance - - the one to be deleted from the map

addElasticLogEntry

public void addElasticLogEntry(org.apache.log4j.Logger log,
                               String logEntry)
Specified by:
addElasticLogEntry in interface ElasticInstanceManager

getElasticAgentLogs

public List<String> getElasticAgentLogs()
Description copied from interface: ElasticInstanceManager
Retrieve activity logs

Specified by:
getElasticAgentLogs in interface ElasticInstanceManager
Returns:
a copy of the current elastic agent logs

isElasticSupportEnabled

public boolean isElasticSupportEnabled()
Specified by:
isElasticSupportEnabled in interface ElasticInstanceManager
Returns:
true, if elastic support is turned on

getAllowedInstanceTypes

@NotNull
public Set<com.atlassian.aws.ec2.EC2InstanceType> getAllowedInstanceTypes()
Specified by:
getAllowedInstanceTypes in interface ElasticInstanceManager
Returns:
Set of allowed instance types.

getTunnelPort

public int getTunnelPort()
Description copied from interface: ElasticAgentTunnelPorts

The TCP port upon which Elastic Agents listens for incoming tunnel connections from the Bamboo Server.

Specified by:
getTunnelPort in interface ElasticAgentTunnelPorts

getAgentSideHttpPort

public int getAgentSideHttpPort()
Description copied from interface: ElasticAgentTunnelPorts

The TCP port upon which the Elastic Agent listens for HTTP traffic intended for the Bamboo Server.

Specified by:
getAgentSideHttpPort in interface ElasticAgentTunnelPorts

getAgentSideJmsPort

public int getAgentSideJmsPort()
Description copied from interface: ElasticAgentTunnelPorts

The TCP port upon which the Elastic Agent listens for JMS traffic intended for the Bamboo Server.

Specified by:
getAgentSideJmsPort in interface ElasticAgentTunnelPorts

setTunnelTimeoutMinutes

public void setTunnelTimeoutMinutes(int tunnelTimeoutMinutes)

getInstanceLogs

@NotNull
public String getInstanceLogs(@NotNull
                                      String instanceId)
                       throws com.atlassian.aws.AWSException
Description copied from interface: ElasticInstanceManager
Fetch console output of a running EC2 instance.

Specified by:
getInstanceLogs in interface ElasticInstanceManager
Parameters:
instanceId - id of the instance
Returns:
Logs from the instance, empty string if no logs were available.
Throws:
com.atlassian.aws.AWSException - if an error occurs while fetching the console output

isInstanceKnown

public boolean isInstanceKnown(@NotNull
                               String instanceId)
Description copied from interface: ElasticInstanceManager
Checks if an AWS instance with the given ID exists and is managed by this Bamboo server.

Specified by:
isInstanceKnown in interface ElasticInstanceManager
Parameters:
instanceId - id of the instance
Returns:
true, if the instance exists and is managed by this Bamboo server


Copyright © 2015 Atlassian Software Systems Pty Ltd. All rights reserved.