Skip to content

Developer Docs

Dorian Cransac edited this page Sep 3, 2020 · 2 revisions

Exense Server model

Exense server model

AbstractStandardServer usage & features

Starting the server

A single main class for all server implementations (allowing for the same “standard” runconf in every project), only the classpath changes (and the config file if necessary)

Exense server model

Authentication

  • You can switch between on/off as well as between accessor-based (password stored in the User entity in mongodb) and ldap:
authentication=true
ui.authenticator.type=ldap
  • Here are the required settings for LDAP:
# ldaps means SSL
ui.authenticator.ldap.url=ldap://ldap.exense.ch:389
ui.authenticator.ldap.base=dc=exense,dc=ch
ui.authenticator.ldap.techuser=cn=admin,dc=exense,dc=ch
ui.authenticator.ldap.techpwd=<tech pwd>

#leave jks properties empty to use default truststore
ui.authenticator.ldap.ssl.pathToJks=src/test/resources/ldap.jks
ui.authenticator.ldap.ssl.jksPassword=my_jks_pwd

Database

  • MongoDB config:
db.host=localhost
db.port=27017
db.database=myexense

Services

Automatic class registration is done against Jetty for classes implementing the Registrable interface. An even more implicit alternative could be to automatically lookup @Singleton’s and register these in the future.

@Singleton
@Path("/myservice")
public class MyService implements Registrable{
...
}

Accessors

  • All CRUD accessors are currently instantiatied automatically and set into ServerContext with the corresponding AbstractOrganizable entity as a key, and the ServerContext is automatically bound:
(ProductAccessor)context.get(Product.class.getName())
  • Injecting accessors into service (option 1)

MyServer.class

// nothing to do

MyService.class

@Singleton
@Path("/myservice")
public class MyService implements Registrable{

	@Inject
	ServerContext context;
	
	private MyAccessor myAccessor;
	
	@PostConstruct
	public void init() {
		myAccessor= (MyAccessor )context.get(MyEntity.class.getName());
	}
  • Injecting accessors into service (option 2)

MyServer.class

@Override
protected void registerExplicitly_(ResourceConfig resourceConfig) {
resourceConfig.register(new AbstractBinder() {
  @Override
  protected void configure() {
  bind((MyAccessor)context.get(MyEntity.class.getName())).to(MyAccessor.class);
[…]

MyService.class

@Singleton
@Path("/myservice")
public class MyService implements Registrable{

@Inject
MyAccessor MytAccessor;

Testing

EmbeddedMongoTestBench

  • Why?

Because Mocks are useful for designing tests at the module level but by definition they are “dumb”. It’s still nice to run complex queries against the actual engine of MongoDB in order to build tests for accessor implementations or classes interacting directly with the accessor

  • How?

Using flapdoodle’s embeded mongo allows the automatic download, start & stop of mongodb as a managed process, making it super easy to run JUnit based tests transparently both locally and on the build server. The proper version of MongoDB will automatically be downloaded (many operating systems are supported). The management of the embedded instance is provided by the abstract class “EmbeddedMongoTestbench” (from project exense-core-testing) which can be extended for concrete tests.

  • Example
public class BasicHostAccessorTest extends EmbeddedMongoTestbench{

@Test
public void isCalled() {
	HostAccessorImpl hosts = new HostAccessorImpl(session);
	Assert.assertEquals(0, hosts.countAllUsers());
	Host host = new Host();
	host.setOwner("exense");
	host.setNetwork("stepcloud.fr");
	host.setUserCount(3);
	hosts.save(host);
	hosts.printAll();
	Assert.assertEquals(3, hosts.countAllUsers());
  }
}