Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elide 5.x dynamic config standalone #1259

Merged
merged 8 commits into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions elide-contrib/elide-dynamic-config-helpers/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@

<properties>
<hjson.version>3.0.0</hjson.version>
<jackson.version>2.10.2</jackson.version>
<handlebars.version>4.2.0</handlebars.version>
<json-schema-validator.version>2.2.12</json-schema-validator.version>
<mdkt.compiler.version>1.3.0</mdkt.compiler.version>
Expand All @@ -55,7 +54,7 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
<version>${version.jackson}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
Expand All @@ -65,11 +64,11 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand Down Expand Up @@ -117,7 +116,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
</dependency>
</dependencies>

<build>
Expand Down
2 changes: 0 additions & 2 deletions elide-datastore/elide-datastore-aggregation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>

Expand All @@ -111,7 +110,6 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>

Expand Down
2 changes: 1 addition & 1 deletion elide-example/elide-blog-example-resteasy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<properties>
<mysql.data.directory>${project.build.directory}/mysql-data</mysql.data.directory>
<resteasy.version>3.11.2.Final</resteasy.version>
<resteasy.version>3.12.0.Final</resteasy.version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,8 @@

package com.yahoo.elide.example;

import com.yahoo.elide.contrib.swagger.SwaggerBuilder;
import com.yahoo.elide.contrib.swagger.resources.DocEndpoint;
import com.yahoo.elide.core.EntityDictionary;
import com.yahoo.elide.example.models.Comment;
import com.yahoo.elide.example.models.Post;
import com.yahoo.elide.example.models.User;
import com.yahoo.elide.standalone.config.ElideStandaloneSettings;
import io.swagger.models.Info;
import io.swagger.models.Swagger;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Optional;

/**
Expand All @@ -35,20 +24,8 @@ public int getPort() {
}

@Override
public List<DocEndpoint.SwaggerRegistration> enableSwagger() {
EntityDictionary dictionary = new EntityDictionary(new HashMap());

dictionary.bindEntity(User.class);
dictionary.bindEntity(Post.class);
dictionary.bindEntity(Comment.class);
Info info = new Info().title("Test Service").version("1.0");

SwaggerBuilder builder = new SwaggerBuilder(dictionary, info);
Swagger swagger = builder.build();

List<DocEndpoint.SwaggerRegistration> docs = new ArrayList<>();
docs.add(new DocEndpoint.SwaggerRegistration("test", swagger));
return docs;
public boolean enableSwagger() {
return true;
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion elide-spring/elide-spring-boot-autoconfigure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

<properties>
<spring.boot.version>2.3.0.RELEASE</spring.boot.version>
<tomcat.version>9.0.34</tomcat.version>
<tomcat.version>9.0.35</tomcat.version>
<project.build.sourceEncoding>utf-8</project.build.sourceEncoding>
<min_jdk_version>1.8</min_jdk_version>
<max_jdk_version>1.8</max_jdk_version>
Expand Down
16 changes: 16 additions & 0 deletions elide-standalone/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@

<dependencies>
<!-- Elide dependency -->
<dependency>
<groupId>com.yahoo.elide</groupId>
<artifactId>elide-datastore-aggregation</artifactId>
<version>5.0.0-pr10-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>com.yahoo.elide</groupId>
<artifactId>elide-datastore-jpa</artifactId>
Expand All @@ -79,6 +85,12 @@
<version>5.0.0-pr10-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>com.yahoo.elide</groupId>
<artifactId>elide-dynamic-config-helpers</artifactId>
<version>5.0.0-pr10-SNAPSHOT</version>
</dependency>

<!-- JPA -->
<dependency>
<groupId>javax.persistence</groupId>
Expand Down Expand Up @@ -240,6 +252,10 @@
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ public Map<String, Class<? extends Check>> getCheckMappings() {
}
/**
* Start the Elide service.
*
* This method blocks until the server exits.
*
* @throws Exception Exception thrown
*/
public void start() throws Exception {
start(true);
Expand All @@ -72,6 +73,7 @@ public void start() throws Exception {
* Start the Elide service.
*
* @param block - Whether or not to wait for the server to shutdown.
* @throws Exception Exception thrown
*/
public void start(boolean block) throws Exception {
ServletContextHandler context = new ServletContextHandler();
Expand Down Expand Up @@ -115,7 +117,7 @@ public void start(boolean block) throws Exception {
context.addServlet(AdminServlet.class, "/stats/*");
}

if (!elideStandaloneSettings.enableSwagger().isEmpty()) {
if (elideStandaloneSettings.enableSwagger()) {
ServletHolder jerseyServlet = context.addServlet(ServletContainer.class,
elideStandaloneSettings.getSwaggerPathSpec());
jerseyServlet.setInitOrder(0);
Expand Down Expand Up @@ -144,6 +146,8 @@ public void start(boolean block) throws Exception {

/**
* Stop the Elide service.
*
* @throws Exception Exception thrown
*/
public void stop() throws Exception {
jettyServer.stop();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@
package com.yahoo.elide.standalone;

import com.yahoo.elide.async.models.AsyncQuery;
import com.yahoo.elide.contrib.dynamicconfighelpers.compile.ElideDynamicEntityCompiler;
import com.yahoo.elide.datastores.jpa.PersistenceUnitInfoImpl;
import com.yahoo.elide.utils.ClassScanner;

import org.hibernate.cfg.AvailableSettings;
import org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl;
import org.hibernate.jpa.boot.internal.PersistenceUnitInfoDescriptor;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Optional;
import java.util.Properties;
import java.util.stream.Collectors;

Expand All @@ -24,8 +31,8 @@
*/
public class Util {

public static EntityManagerFactory getEntityManagerFactory(String modelPackageName, boolean includeAsyncModel,
Properties options) {
public static EntityManagerFactory getEntityManagerFactory(String modelPackageName, boolean includeAsyncModel,
Optional<ElideDynamicEntityCompiler> optionalCompiler, Properties options) {

// Configure default options for example service
if (options.isEmpty()) {
Expand Down Expand Up @@ -53,28 +60,57 @@ public static EntityManagerFactory getEntityManagerFactory(String modelPackageNa
options.put("javax.persistence.jdbc.password", "elide123");
}

ClassLoader classLoader = null;
//Bind entity classes from classpath to Persistence Unit
ArrayList<Class> loadedClasses = new ArrayList<>();

if (optionalCompiler.isPresent()) {
ElideDynamicEntityCompiler compiler = optionalCompiler.get();
classLoader = compiler.getClassLoader();
Collection<ClassLoader> classLoaders = new ArrayList<>();
classLoaders.add(classLoader);
options.put(AvailableSettings.CLASSLOADERS, classLoaders);

try {
loadedClasses.addAll(compiler.findAnnotatedClasses(Entity.class));
} catch (ClassNotFoundException e) {
throw new IllegalStateException(e);
}
}

PersistenceUnitInfo persistenceUnitInfo = new PersistenceUnitInfoImpl("elide-stand-alone",
combineModelEntities(modelPackageName, includeAsyncModel), options);
combineModelEntities(optionalCompiler, modelPackageName, includeAsyncModel),
options, classLoader);

return new EntityManagerFactoryBuilderImpl(
new PersistenceUnitInfoDescriptor(persistenceUnitInfo), new HashMap<>())
new PersistenceUnitInfoDescriptor(persistenceUnitInfo), new HashMap<>(), classLoader)
.build();
}

/**
* Combine the model entities with Async model.
* Combine the model entities with Async and Dynamic models.
*
* @param optionalCompiler optional dynamicCompiler
* @param modelPackageName Package name
* @param includeAsyncModel Include Async model package Name
* @return All entities combined from both package.
*/
public static List<String> combineModelEntities(String modelPackageName, boolean includeAsyncModel) {
public static List<String> combineModelEntities(Optional<ElideDynamicEntityCompiler> optionalCompiler,
String modelPackageName, boolean includeAsyncModel) {

List<String> modelEntities = getAllEntities(modelPackageName);

if (includeAsyncModel) {
modelEntities.addAll(getAllEntities(AsyncQuery.class.getPackage().getName()));
}

if (optionalCompiler.isPresent()) {
try {
modelEntities.addAll(optionalCompiler.get().findAnnotatedClassNames(Entity.class));
} catch (ClassNotFoundException e) {
throw new IllegalStateException(e);
}
}
return modelEntities;
}

Expand Down
Loading