Class ElasticInstanceManagerImpl
- java.lang.Object
-
- 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
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
Constructors Constructor Description ElasticInstanceManagerImpl(AwsAccountBean awsAccountBean, AdministrationConfigurationAccessor administrationConfigurationAccessor, int startupTimeoutSeconds, ScheduledExecutorService executor, KeyStoreFactory keyStoreFactory, SSLContextFactory sslContextFactory, BootstrapManager bootstrapManager, ErrorHandler errorHandler, SpotInstanceConfigurationAccessor spotInstanceConfigurationAccessor, com.atlassian.event.api.EventPublisher eventPublisher, SecretEncryptionService secretEncryptionService)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddElasticLogEntry(org.apache.log4j.Logger log, String logEntry)voidaddElasticLogEntry(org.apache.logging.log4j.Logger log, String logEntry)booleancancelSpotRequests(@NotNull com.atlassian.aws.AWSAccount awsAccount)Cancel spot instance requests.voidensureLoginKeyPairExists(com.atlassian.aws.AWSAccount awsAccount, String keyPair)Ensures that a key pair, named "elasticbamboo", has been defined in the configured AWS account.intgetAgentSideHttpPort()The TCP port upon which the Elastic Agent listens for HTTP traffic intended for the Bamboo Server.intgetAgentSideJmsPort()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 aSetMultimap, keyed by theElasticImageConfigurationList<RemoteElasticInstance>getAllElasticRemoteAgents()Returns all elastic instances.@NotNull Set<com.atlassian.aws.ec2.EC2InstanceType>getAllowedInstanceTypes()StringgetBambooControlTag()Returns the name of the security group used to indicate that this instance belongs to Bamboo.List<String>getElasticAgentLogs()Retrieve activity logs@Nullable RemoteElasticInstancegetElasticRemoteAgentByInstanceId(String instanceId)Retrieve elastic instance of the given ID.@NotNull List<RemoteElasticInstance>getElasticRemoteAgents()Retrieve a readonly list of any currently existing EC2 instances@NotNull List<RemoteElasticInstance>getElasticRemoteAgentsByConfiguration(long id)@NotNull List<RemoteElasticInstance>getElasticRemoteAgentsByConfiguration(@NotNull ElasticImageConfiguration elasticImageConfiguration)@NotNull StringgetInstanceLogs(@NotNull String instanceId)Fetch console output of a running EC2 instance.@NotNull List<RemoteElasticInstance>getInstancesWithStartingAgents()Returns those elastic instances that have already started but their agents have not yet connected to the bamboo server.@NotNull List<RemoteElasticInstance>getRequestedElasticRemoteAgents()Returns the elastic instances which have been requested but not yet identified.@NotNull List<RemoteElasticInstance>getStartingElasticInstances()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.intgetTotalNumElasticRemoteAgents()Return how many license spots are currently being occupied by elastic instances (pending and running)intgetTunnelPort()The TCP port upon which Elastic Agents listens for incoming tunnel connections from the Bamboo Server.booleanisElasticSupportEnabled()booleanisInstanceKnown(@NotNull String instanceId)Checks if an AWS instance with the given ID exists and is managed by this Bamboo server.RemoteElasticInstancenewElasticAgent(RemoteElasticInstanceListener listener, com.atlassian.aws.AWSAccount awsAccount, @NotNull AgentManager agentManager, @NotNull ElasticImageConfiguration elasticImageConfiguration, @NotNull com.atlassian.aws.ec2.InstanceLaunchConfigurationBuilder instanceLaunchConfigurationBuilder)voidonInstanceIdentified(@NotNull RemoteElasticInstance instance)Tell the manager that the instance is up and runningvoidonInstanceRunning(@NotNull RemoteElasticInstance instance)Invoked when the instance enters the 'running' statevoidregisterElasticAgentStopped(@NotNull RemoteElasticInstance instance)Remove and EC2 instance from the "currently Running mapRemoteElasticInstancerestoreElasticAgent(@NotNull ElasticAgentDefinition elasticAgentDefinition, @Nullable ElasticTunnelDefinition elasticTunnelDefinition, @NotNull com.amazonaws.services.ec2.model.Instance instance, @NotNull RemoteElasticInstanceListener listener, @NotNull com.atlassian.aws.AWSAccount awsAccount, @NotNull AgentManager agentManager, @NotNull com.atlassian.aws.ec2.InstanceLaunchConfigurationBuilder instanceLaunchConfigurationBuilder)After Bamboo server restart, reconnect to elastic agent.voidsetTunnelTimeoutMinutes(int tunnelTimeoutMinutes)booleanvalidateAwsCredentials(com.atlassian.aws.ec2.awssdk.AwsSupportConstants.Region region, com.atlassian.aws.credentials.AWSCredentials awsCredentials, ErrorCollection errorCollection)Validate supplied AWS credentials.booleanvalidateAwsCredentials(com.atlassian.aws.ec2.awssdk.AwsSupportConstants.Region region, String awsAccessID, String awsSecretKey, ErrorCollection errorCollection)Validate a set of supplied AWS credentials.
-
-
-
Constructor Detail
-
ElasticInstanceManagerImpl
public ElasticInstanceManagerImpl(AwsAccountBean awsAccountBean, AdministrationConfigurationAccessor administrationConfigurationAccessor, int startupTimeoutSeconds, ScheduledExecutorService executor, KeyStoreFactory keyStoreFactory, SSLContextFactory sslContextFactory, BootstrapManager bootstrapManager, ErrorHandler errorHandler, SpotInstanceConfigurationAccessor spotInstanceConfigurationAccessor, com.atlassian.event.api.EventPublisher eventPublisher, SecretEncryptionService secretEncryptionService)
-
-
Method Detail
-
newElasticAgent
public RemoteElasticInstance newElasticAgent(RemoteElasticInstanceListener listener, com.atlassian.aws.AWSAccount awsAccount, @NotNull @NotNull AgentManager agentManager, @NotNull @NotNull ElasticImageConfiguration elasticImageConfiguration, @NotNull @NotNull com.atlassian.aws.ec2.InstanceLaunchConfigurationBuilder instanceLaunchConfigurationBuilder) throws NoSuchAlgorithmException, KeyManagementException, IOException, CertificateException, UnrecoverableKeyException, KeyStoreException
- Specified by:
newElasticAgentin interfaceElasticInstanceManager- Throws:
NoSuchAlgorithmExceptionKeyManagementExceptionIOExceptionCertificateExceptionUnrecoverableKeyExceptionKeyStoreException
-
restoreElasticAgent
public RemoteElasticInstance restoreElasticAgent(@NotNull @NotNull ElasticAgentDefinition elasticAgentDefinition, @Nullable @Nullable ElasticTunnelDefinition elasticTunnelDefinition, @NotNull @NotNull com.amazonaws.services.ec2.model.Instance instance, @NotNull @NotNull RemoteElasticInstanceListener listener, @NotNull @NotNull com.atlassian.aws.AWSAccount awsAccount, @NotNull @NotNull AgentManager agentManager, @NotNull @NotNull com.atlassian.aws.ec2.InstanceLaunchConfigurationBuilder instanceLaunchConfigurationBuilder) throws Exception
Description copied from interface:ElasticInstanceManagerAfter Bamboo server restart, reconnect to elastic agent.- Specified by:
restoreElasticAgentin interfaceElasticInstanceManager- Throws:
Exception
-
ensureLoginKeyPairExists
public void ensureLoginKeyPairExists(com.atlassian.aws.AWSAccount awsAccount, String keyPair) throws com.atlassian.aws.AWSExceptionDescription copied from interface:ElasticInstanceManagerEnsures that a key pair, named "elasticbamboo", has been defined in the configured AWS account.
- Specified by:
ensureLoginKeyPairExistsin interfaceElasticInstanceManager- 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:ElasticInstanceManagerValidate a set of supplied AWS credentials.
- Specified by:
validateAwsCredentialsin interfaceElasticInstanceManagerawsAccessID- The Access ID of the Amazon Web Services AccountawsSecretKey- The Secret Key of the Amazon Web Services AccounterrorCollection- AnErrorCollectionto which validation errors should be added, ornullif validation errors are not required.- Returns:
trueif the supplied credentials are successfully validated;falseotherwise.
-
validateAwsCredentials
public boolean validateAwsCredentials(com.atlassian.aws.ec2.awssdk.AwsSupportConstants.Region region, com.atlassian.aws.credentials.AWSCredentials awsCredentials, ErrorCollection errorCollection)Description copied from interface:ElasticInstanceManagerValidate supplied AWS credentials.
- Specified by:
validateAwsCredentialsin interfaceElasticInstanceManagerawsCredentials- Amazon Web Services Account credentialserrorCollection- AnErrorCollectionto which validation errors should be added, ornullif validation errors are not required.- Returns:
trueif the supplied credentials are successfully validated;falseotherwise.
-
getElasticRemoteAgents
@NotNull public @NotNull List<RemoteElasticInstance> getElasticRemoteAgents()
Description copied from interface:ElasticInstanceManagerRetrieve a readonly list of any currently existing EC2 instances- Specified by:
getElasticRemoteAgentsin interfaceElasticInstanceManager- Returns:
- List of
RemoteElasticInstance
-
getElasticRemoteAgentsByConfiguration
@NotNull public @NotNull List<RemoteElasticInstance> getElasticRemoteAgentsByConfiguration(@NotNull @NotNull ElasticImageConfiguration elasticImageConfiguration)
- Specified by:
getElasticRemoteAgentsByConfigurationin interfaceElasticInstanceManager
-
getElasticRemoteAgentsByConfiguration
@NotNull public @NotNull List<RemoteElasticInstance> getElasticRemoteAgentsByConfiguration(long id)
- Specified by:
getElasticRemoteAgentsByConfigurationin interfaceElasticInstanceManager
-
getElasticRemoteAgentByInstanceId
@Nullable public @Nullable RemoteElasticInstance getElasticRemoteAgentByInstanceId(String instanceId)
Description copied from interface:ElasticInstanceManagerRetrieve elastic instance of the given ID.- Specified by:
getElasticRemoteAgentByInstanceIdin interfaceElasticInstanceManager- Parameters:
instanceId- of the instance- Returns:
- the elastic remote agent specific to the provided instance id
-
getRequestedElasticRemoteAgents
@NotNull public @NotNull List<RemoteElasticInstance> getRequestedElasticRemoteAgents()
Description copied from interface:ElasticInstanceManagerReturns the elastic instances which have been requested but not yet identified.- Specified by:
getRequestedElasticRemoteAgentsin interfaceElasticInstanceManager- Returns:
- List of elastic instances which have been requested but not yet started up yet..
-
getStartingElasticInstances
@NotNull public @NotNull List<RemoteElasticInstance> getStartingElasticInstances()
Description copied from interface:ElasticInstanceManagerReturn 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:
getStartingElasticInstancesin interfaceElasticInstanceManager- Returns:
- List of elastic instances which have been requested and identified but not yet started up yet..
-
getInstancesWithStartingAgents
@NotNull public @NotNull List<RemoteElasticInstance> getInstancesWithStartingAgents()
Description copied from interface:ElasticInstanceManagerReturns 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 byElasticInstanceManager.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 byElasticInstanceManager.getElasticRemoteAgents().- Specified by:
getInstancesWithStartingAgentsin interfaceElasticInstanceManager- Returns:
- List of
RemoteElasticInstance
-
getAllElasticRemoteAgents
public List<RemoteElasticInstance> getAllElasticRemoteAgents()
Description copied from interface:ElasticInstanceManagerReturns all elastic instances. It includes requested agents as well as active agents- Specified by:
getAllElasticRemoteAgentsin interfaceElasticInstanceManager- Returns:
-
getAllElasticAgentsAsMap
public com.google.common.collect.SetMultimap<ElasticImageConfiguration,RemoteElasticInstance> getAllElasticAgentsAsMap()
Description copied from interface:ElasticInstanceManagerReturns all elastic instances in aSetMultimap, keyed by theElasticImageConfiguration- Specified by:
getAllElasticAgentsAsMapin interfaceElasticInstanceManager- Returns:
-
getTotalNumElasticRemoteAgents
public int getTotalNumElasticRemoteAgents()
Description copied from interface:ElasticInstanceManagerReturn how many license spots are currently being occupied by elastic instances (pending and running)- Specified by:
getTotalNumElasticRemoteAgentsin interfaceElasticInstanceManager- Returns:
- Number of license slots currently occupied by elastic instances (pending and running).
-
onInstanceIdentified
public void onInstanceIdentified(@NotNull @NotNull RemoteElasticInstance instance)Description copied from interface:ElasticInstanceManagerTell the manager that the instance is up and running- Specified by:
onInstanceIdentifiedin interfaceElasticInstanceManager- Parameters:
instance- the instance identified
-
onInstanceRunning
public void onInstanceRunning(@NotNull @NotNull RemoteElasticInstance instance)Description copied from interface:ElasticInstanceManagerInvoked when the instance enters the 'running' state- Specified by:
onInstanceRunningin interfaceElasticInstanceManager- Parameters:
instance- the instance that entered running state
-
cancelSpotRequests
public boolean cancelSpotRequests(@NotNull @NotNull com.atlassian.aws.AWSAccount awsAccount)Description copied from interface:ElasticInstanceManagerCancel spot instance requests.- Specified by:
cancelSpotRequestsin interfaceElasticInstanceManager- Parameters:
awsAccount- account- Returns:
- true if at least one request was found and cancelled
-
registerElasticAgentStopped
public void registerElasticAgentStopped(@NotNull @NotNull RemoteElasticInstance instance)Description copied from interface:ElasticInstanceManagerRemove and EC2 instance from the "currently Running map- Specified by:
registerElasticAgentStoppedin interfaceElasticInstanceManager- Parameters:
instance- - the one to be deleted from the map
-
addElasticLogEntry
public void addElasticLogEntry(org.apache.log4j.Logger log, String logEntry)- Specified by:
addElasticLogEntryin interfaceElasticInstanceManager
-
addElasticLogEntry
public void addElasticLogEntry(org.apache.logging.log4j.Logger log, String logEntry)- Specified by:
addElasticLogEntryin interfaceElasticInstanceManager
-
getElasticAgentLogs
public List<String> getElasticAgentLogs()
Description copied from interface:ElasticInstanceManagerRetrieve activity logs- Specified by:
getElasticAgentLogsin interfaceElasticInstanceManager- Returns:
- a copy of the current elastic agent logs
-
isElasticSupportEnabled
public boolean isElasticSupportEnabled()
- Specified by:
isElasticSupportEnabledin interfaceElasticInstanceManager- Returns:
- true, if elastic support is turned on
-
getAllowedInstanceTypes
@NotNull public @NotNull Set<com.atlassian.aws.ec2.EC2InstanceType> getAllowedInstanceTypes()
- Specified by:
getAllowedInstanceTypesin interfaceElasticInstanceManager- Returns:
- Set of allowed instance types.
-
getTunnelPort
public int getTunnelPort()
Description copied from interface:ElasticAgentTunnelPortsThe TCP port upon which Elastic Agents listens for incoming tunnel connections from the Bamboo Server.
- Specified by:
getTunnelPortin interfaceElasticAgentTunnelPorts
-
getAgentSideHttpPort
public int getAgentSideHttpPort()
Description copied from interface:ElasticAgentTunnelPortsThe TCP port upon which the Elastic Agent listens for HTTP traffic intended for the Bamboo Server.
- Specified by:
getAgentSideHttpPortin interfaceElasticAgentTunnelPorts
-
getAgentSideJmsPort
public int getAgentSideJmsPort()
Description copied from interface:ElasticAgentTunnelPortsThe TCP port upon which the Elastic Agent listens for JMS traffic intended for the Bamboo Server.
- Specified by:
getAgentSideJmsPortin interfaceElasticAgentTunnelPorts
-
setTunnelTimeoutMinutes
public void setTunnelTimeoutMinutes(int tunnelTimeoutMinutes)
-
getInstanceLogs
@NotNull public @NotNull String getInstanceLogs(@NotNull @NotNull String instanceId) throws com.atlassian.aws.AWSException
Description copied from interface:ElasticInstanceManagerFetch console output of a running EC2 instance.- Specified by:
getInstanceLogsin interfaceElasticInstanceManager- 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 @NotNull String instanceId)Description copied from interface:ElasticInstanceManagerChecks if an AWS instance with the given ID exists and is managed by this Bamboo server.- Specified by:
isInstanceKnownin interfaceElasticInstanceManager- Parameters:
instanceId- id of the instance- Returns:
- true, if the instance exists and is managed by this Bamboo server
-
getBambooControlTag
public String getBambooControlTag()
Description copied from interface:ElasticInstanceManagerReturns the name of the security group used to indicate that this instance belongs to Bamboo.- Specified by:
getBambooControlTagin interfaceElasticInstanceManager
-
-