Spring for Apache Hadoop

org.springframework.yarn.test.junit
Class AbstractYarnClusterTests

java.lang.Object
  extended by org.springframework.yarn.test.junit.AbstractYarnClusterTests
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware

public abstract class AbstractYarnClusterTests
extends java.lang.Object
implements org.springframework.context.ApplicationContextAware

Abstract base class providing default functionality for running tests using Yarn mini cluster.

Author:
Janne Valkealahti

Field Summary
protected  org.springframework.context.ApplicationContext applicationContext
           
protected  org.apache.hadoop.conf.Configuration configuration
           
protected  YarnClient yarnClient
           
protected  YarnCluster yarnCluster
           
 
Constructor Summary
AbstractYarnClusterTests()
           
 
Method Summary
 org.springframework.context.ApplicationContext getApplicationContext()
          Gets the ApplicationContext for tests.
 org.apache.hadoop.conf.Configuration getConfiguration()
          Gets the running cluster runtime Configuration for tests.
protected  org.apache.hadoop.yarn.api.records.YarnApplicationState getState(org.apache.hadoop.yarn.api.records.ApplicationId applicationId)
          Get the current application state.
 YarnClient getYarnClient()
          Gets the YarnClient.
 YarnCluster getYarnCluster()
          Gets the running YarnCluster for tests.
protected  void killApplication(org.apache.hadoop.yarn.api.records.ApplicationId applicationId)
          Kill the application.
 void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
           
 void setConfiguration(org.apache.hadoop.conf.Configuration configuration)
          Sets the Configuration.
 void setYarnClient(YarnClient yarnClient)
          Sets the YarnClient.
 void setYarnCluster(YarnCluster yarnCluster)
          Sets the YarnCluster
protected  org.apache.hadoop.yarn.api.records.ApplicationId submitApplication()
          Submit an application.
protected  org.apache.hadoop.yarn.api.records.YarnApplicationState submitApplicationAndWait()
          Submits application and wait state.
protected  org.apache.hadoop.yarn.api.records.YarnApplicationState submitApplicationAndWait(long timeout, java.util.concurrent.TimeUnit unit)
          Submits application and wait state.
protected  org.apache.hadoop.yarn.api.records.YarnApplicationState submitApplicationAndWaitState(long timeout, java.util.concurrent.TimeUnit unit, org.apache.hadoop.yarn.api.records.YarnApplicationState... applicationStates)
          Submits application and wait state.
protected  org.apache.hadoop.yarn.api.records.YarnApplicationState waitState(org.apache.hadoop.yarn.api.records.ApplicationId applicationId, long timeout, java.util.concurrent.TimeUnit unit, org.apache.hadoop.yarn.api.records.YarnApplicationState... applicationStates)
          Waits state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

applicationContext

protected org.springframework.context.ApplicationContext applicationContext

configuration

protected org.apache.hadoop.conf.Configuration configuration

yarnCluster

protected YarnCluster yarnCluster

yarnClient

protected YarnClient yarnClient
Constructor Detail

AbstractYarnClusterTests

public AbstractYarnClusterTests()
Method Detail

getApplicationContext

public org.springframework.context.ApplicationContext getApplicationContext()
Gets the ApplicationContext for tests.

Returns:
the Application context

setApplicationContext

public final void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
Specified by:
setApplicationContext in interface org.springframework.context.ApplicationContextAware

getConfiguration

public org.apache.hadoop.conf.Configuration getConfiguration()
Gets the running cluster runtime Configuration for tests.

Returns:
the Yarn cluster config

setConfiguration

@Autowired
public void setConfiguration(org.apache.hadoop.conf.Configuration configuration)
Sets the Configuration.

Parameters:
configuration - the Configuration

getYarnCluster

public YarnCluster getYarnCluster()
Gets the running YarnCluster for tests.

Returns:
the Yarn cluster

setYarnCluster

@Autowired
public void setYarnCluster(YarnCluster yarnCluster)
Sets the YarnCluster

Parameters:
yarnCluster - the Yarn cluster

getYarnClient

public YarnClient getYarnClient()
Gets the YarnClient.

Returns:
the Yarn client

setYarnClient

@Autowired
public void setYarnClient(YarnClient yarnClient)
Sets the YarnClient.

Parameters:
yarnClient - the Yarn client

submitApplicationAndWait

protected org.apache.hadoop.yarn.api.records.YarnApplicationState submitApplicationAndWait()
                                                                                    throws java.lang.Exception
Submits application and wait state. On default waits 60 seconds.

Returns:
Last knows application state
Throws:
java.lang.Exception - if exception occurred
See Also:
submitApplicationAndWaitState(long, TimeUnit, YarnApplicationState...)

submitApplicationAndWait

protected org.apache.hadoop.yarn.api.records.YarnApplicationState submitApplicationAndWait(long timeout,
                                                                                           java.util.concurrent.TimeUnit unit)
                                                                                    throws java.lang.Exception
Submits application and wait state.

Parameters:
timeout - the timeout for wait
unit - the unit for timeout
Returns:
Last knows application state
Throws:
java.lang.Exception - if exception occurred
See Also:
submitApplicationAndWaitState(long, TimeUnit, YarnApplicationState...)

submitApplicationAndWaitState

protected org.apache.hadoop.yarn.api.records.YarnApplicationState submitApplicationAndWaitState(long timeout,
                                                                                                java.util.concurrent.TimeUnit unit,
                                                                                                org.apache.hadoop.yarn.api.records.YarnApplicationState... applicationStates)
                                                                                         throws java.lang.Exception
Submits application and wait state. Returned state is NULL if something failed or final known state after the wait/poll operations. Array of application states can be used to return immediately from wait loop if state is matched.

Parameters:
timeout - the timeout for wait
unit - the unit for timeout
applicationStates - the application states to wait
Returns:
Last knows application state
Throws:
java.lang.Exception - if exception occurred

submitApplication

protected org.apache.hadoop.yarn.api.records.ApplicationId submitApplication()
Submit an application.

Returns:
the submitted application ApplicationId

waitState

protected org.apache.hadoop.yarn.api.records.YarnApplicationState waitState(org.apache.hadoop.yarn.api.records.ApplicationId applicationId,
                                                                            long timeout,
                                                                            java.util.concurrent.TimeUnit unit,
                                                                            org.apache.hadoop.yarn.api.records.YarnApplicationState... applicationStates)
                                                                     throws java.lang.Exception
Waits state. Returned state is NULL if something failed or final known state after the wait/poll operations. Array of application states can be used to return immediately from wait loop if state is matched.

Parameters:
applicationId - the application id
timeout - the timeout for wait
unit - the unit for timeout
applicationStates - the application states to wait
Returns:
Last knows application state
Throws:
java.lang.Exception - if exception occurred

killApplication

protected void killApplication(org.apache.hadoop.yarn.api.records.ApplicationId applicationId)
Kill the application.

Parameters:
applicationId - the application id

getState

protected org.apache.hadoop.yarn.api.records.YarnApplicationState getState(org.apache.hadoop.yarn.api.records.ApplicationId applicationId)
Get the current application state.

Parameters:
applicationId - Yarn app application id
Returns:
Current application state or NULL if not found

Spring for Apache Hadoop