Skip to content
This repository has been archived by the owner on Oct 14, 2020. It is now read-only.

Commit

Permalink
wildfly runtime prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
awisniew90 committed Mar 20, 2019
1 parent 8a9f981 commit c3288f6
Show file tree
Hide file tree
Showing 50 changed files with 1,654 additions and 276 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.Properties;

import org.w3c.dom.Document;

import io.openliberty.boost.common.BoostException;

Expand All @@ -45,30 +42,12 @@ public static String getCoordindates(Class<?> klass) throws BoostException {
return coordinates.value();
}

protected static final String BOOSTERS_GROUP_ID = "io.openliberty.boosters";
public static final String BOOSTERS_GROUP_ID = "io.openliberty.boosters";
protected String EE_7_VERSION = "0.1-SNAPSHOT";
protected String EE_8_VERSION = "0.2-SNAPSHOT";
protected String MP_20_VERSION = "0.2-SNAPSHOT";

/**
* Return the Liberty feature name
*
* @return
*/
public abstract String getFeature();

/**
* Add the server.xml configuration for this booster
*
* @param doc
*/
public abstract void addServerConfig(Document doc);

/**
* Return the properties required by this booster
*/
public abstract Properties getServerProperties();


/**
* Return the dependency that this booster requires
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*******************************************************************************
* Copyright (c) 2018 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/

package io.openliberty.boost.common.boosters.liberty;

import java.util.Properties;

import org.w3c.dom.Document;

import io.openliberty.boost.common.boosters.AbstractBoosterConfig;

/**
* Interface to describe common function across all technology Booster Pack
* Config Objects
*
*/
public abstract class AbstractBoosterLibertyConfig extends AbstractBoosterConfig {

/**
* Return the Liberty feature name
*
* @return
*/
public abstract String getFeature();

/**
* Add the server.xml configuration for this booster
*
* @param doc
*/
public abstract void addServerConfig(Document doc);

/**
* Return the properties required by this booster
*/
public abstract Properties getServerProperties();

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package io.openliberty.boost.common.boosters;
package io.openliberty.boost.common.boosters.liberty;

import static io.openliberty.boost.common.config.ConfigConstants.CDI_20;
import static io.openliberty.boost.common.config.LibertyConfigConstants.CDI_20;

import java.util.Map;
import java.util.Properties;
Expand All @@ -21,14 +21,14 @@
import io.openliberty.boost.common.BoostLoggerI;
import io.openliberty.boost.common.boosters.AbstractBoosterConfig.BoosterCoordinates;

@BoosterCoordinates(AbstractBoosterConfig.BOOSTERS_GROUP_ID + ":cdi")
public class CDIBoosterConfig extends AbstractBoosterConfig {
@BoosterCoordinates(AbstractBoosterLibertyConfig.BOOSTERS_GROUP_ID + ":cdi")
public class CDIBoosterLibertyConfig extends AbstractBoosterLibertyConfig {

String libertyFeature = null;

public CDIBoosterConfig(Map<String, String> dependencies, BoostLoggerI logger) throws BoostException {
public CDIBoosterLibertyConfig(Map<String, String> dependencies, BoostLoggerI logger) throws BoostException {
String version = dependencies.get(getCoordindates(this.getClass()));

// if it is the 1.0 version = EE7 feature level
if (version.equals(MP_20_VERSION)) {
libertyFeature = CDI_20;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package io.openliberty.boost.common.boosters;
package io.openliberty.boost.common.boosters.liberty;

import org.w3c.dom.Document;

import io.openliberty.boost.common.BoostException;
import io.openliberty.boost.common.BoostLoggerI;
import io.openliberty.boost.common.boosters.AbstractBoosterConfig.BoosterCoordinates;

import static io.openliberty.boost.common.config.ConfigConstants.*;
import static io.openliberty.boost.common.config.LibertyConfigConstants.*;

import java.util.Map;
import java.util.Properties;

@BoosterCoordinates(AbstractBoosterConfig.BOOSTERS_GROUP_ID + ":jaxrs")
public class JAXRSBoosterConfig extends AbstractBoosterConfig {
@BoosterCoordinates(AbstractBoosterLibertyConfig.BOOSTERS_GROUP_ID + ":jaxrs")
public class JAXRSBoosterLibertyConfig extends AbstractBoosterLibertyConfig {

String libertyFeature = null;

public JAXRSBoosterConfig(Map<String, String> dependencies, BoostLoggerI logger) throws BoostException {
public JAXRSBoosterLibertyConfig(Map<String, String> dependencies, BoostLoggerI logger) throws BoostException {
String version = dependencies.get(getCoordindates(this.getClass()));
if (version.equals(EE_7_VERSION)) {
libertyFeature = JAXRS_20;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package io.openliberty.boost.common.boosters;
package io.openliberty.boost.common.boosters.liberty;

import io.openliberty.boost.common.config.BoostProperties;
import io.openliberty.boost.common.BoostException;
import io.openliberty.boost.common.BoostLoggerI;
import io.openliberty.boost.common.boosters.AbstractBoosterConfig.BoosterCoordinates;
import io.openliberty.boost.common.utils.BoostUtil;

import static io.openliberty.boost.common.config.ConfigConstants.*;
import static io.openliberty.boost.common.config.LibertyConfigConstants.*;

import java.util.Map;
import java.util.Properties;
Expand All @@ -25,8 +25,8 @@
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

@BoosterCoordinates(AbstractBoosterConfig.BOOSTERS_GROUP_ID + ":jdbc")
public class JDBCBoosterConfig extends AbstractBoosterConfig {
@BoosterCoordinates(AbstractBoosterLibertyConfig.BOOSTERS_GROUP_ID + ":jdbc")
public class JDBCBoosterLibertyConfig extends AbstractBoosterLibertyConfig {

public static String DERBY_DEPENDENCY = "org.apache.derby:derby";
public static String DB2_DEPENDENCY = "com.ibm.db2.jcc:db2jcc";
Expand All @@ -39,22 +39,22 @@ public class JDBCBoosterConfig extends AbstractBoosterConfig {

private Properties serverProperties;

public JDBCBoosterConfig(Map<String, String> dependencies, BoostLoggerI logger) throws BoostException {
public JDBCBoosterLibertyConfig(Map<String, String> dependencies, BoostLoggerI logger) throws BoostException {

// Check for user defined database dependencies
String configuredDatabaseDep = null;

if (dependencies.containsKey(JDBCBoosterConfig.DERBY_DEPENDENCY)) {
String derbyVersion = dependencies.get(JDBCBoosterConfig.DERBY_DEPENDENCY);
configuredDatabaseDep = JDBCBoosterConfig.DERBY_DEPENDENCY + ":" + derbyVersion;

} else if (dependencies.containsKey(JDBCBoosterConfig.DB2_DEPENDENCY)) {
String db2Version = dependencies.get(JDBCBoosterConfig.DB2_DEPENDENCY);
configuredDatabaseDep = JDBCBoosterConfig.DB2_DEPENDENCY + ":" + db2Version;
} else if (dependencies.containsKey(JDBCBoosterConfig.MYSQL_DEPENDENCY)) {
String mysqlVersion = dependencies.get(JDBCBoosterConfig.MYSQL_DEPENDENCY);
configuredDatabaseDep = JDBCBoosterConfig.MYSQL_DEPENDENCY + ":" + mysqlVersion;
if (dependencies.containsKey(JDBCBoosterLibertyConfig.DERBY_DEPENDENCY)) {
String derbyVersion = dependencies.get(JDBCBoosterLibertyConfig.DERBY_DEPENDENCY);
configuredDatabaseDep = JDBCBoosterLibertyConfig.DERBY_DEPENDENCY + ":" + derbyVersion;

} else if (dependencies.containsKey(JDBCBoosterLibertyConfig.DB2_DEPENDENCY)) {
String db2Version = dependencies.get(JDBCBoosterLibertyConfig.DB2_DEPENDENCY);
configuredDatabaseDep = JDBCBoosterLibertyConfig.DB2_DEPENDENCY + ":" + db2Version;

} else if (dependencies.containsKey(JDBCBoosterLibertyConfig.MYSQL_DEPENDENCY)) {
String mysqlVersion = dependencies.get(JDBCBoosterLibertyConfig.MYSQL_DEPENDENCY);
configuredDatabaseDep = JDBCBoosterLibertyConfig.MYSQL_DEPENDENCY + ":" + mysqlVersion;
}

Properties boostConfigProperties = BoostProperties.getConfiguredBoostProperties(logger);
Expand Down Expand Up @@ -86,41 +86,49 @@ private void init(Properties boostConfigProperties, String configuredDatabaseDep
// Set server properties
this.serverProperties = new Properties();

// Initialize defaults and required properties for each datasource vendor
// Initialize defaults and required properties for each datasource
// vendor
if (this.dependency.startsWith(DERBY_DEPENDENCY)) {
// Embedded Derby requires a database name. Set a default for this and create it.
// Embedded Derby requires a database name. Set a default for this
// and create it.
this.serverProperties.put(BoostProperties.DATASOURCE_DATABASE_NAME, DERBY_DB);
this.serverProperties.put(BoostProperties.DATASOURCE_CREATE_DATABASE, "create");

} else if (this.dependency.startsWith(DB2_DEPENDENCY)) {
// For DB2, since we are expecting the database to exist, there is no
// default value we can set for databaseName that would be of any use.
// Likewise, for user and password, there isn't anything we could set
// here that would make sense. Since these properties are required,
// set empty strings as there values to create place holders. If they
// are not overridden by the user at package time, they can be overridden
// at runtime.
this.serverProperties.put(BoostProperties.DATASOURCE_DATABASE_NAME, "");
this.serverProperties.put(BoostProperties.DATASOURCE_USER, "");
this.serverProperties.put(BoostProperties.DATASOURCE_PASSWORD, "");
// For DB2, since we are expecting the database to exist, there is
// no
// default value we can set for databaseName that would be of any
// use.
// Likewise, for user and password, there isn't anything we could
// set
// here that would make sense. Since these properties are required,
// set empty strings as there values to create place holders. If
// they
// are not overridden by the user at package time, they can be
// overridden
// at runtime.
this.serverProperties.put(BoostProperties.DATASOURCE_DATABASE_NAME, "");
this.serverProperties.put(BoostProperties.DATASOURCE_USER, "");
this.serverProperties.put(BoostProperties.DATASOURCE_PASSWORD, "");
this.serverProperties.put(BoostProperties.DATASOURCE_SERVER_NAME, LOCALHOST);
this.serverProperties.put(BoostProperties.DATASOURCE_PORT_NUMBER, DB2_DEFAULT_PORT_NUMBER);
this.serverProperties.put(BoostProperties.DATASOURCE_PORT_NUMBER, DB2_DEFAULT_PORT_NUMBER);

} else if (this.dependency.startsWith(MYSQL_DEPENDENCY)) {
// Same set of minimum requirements for MySQL
this.serverProperties.put(BoostProperties.DATASOURCE_DATABASE_NAME, "");
this.serverProperties.put(BoostProperties.DATASOURCE_USER, "");
this.serverProperties.put(BoostProperties.DATASOURCE_PASSWORD, "");
// Same set of minimum requirements for MySQL
this.serverProperties.put(BoostProperties.DATASOURCE_DATABASE_NAME, "");
this.serverProperties.put(BoostProperties.DATASOURCE_USER, "");
this.serverProperties.put(BoostProperties.DATASOURCE_PASSWORD, "");
this.serverProperties.put(BoostProperties.DATASOURCE_SERVER_NAME, LOCALHOST);
this.serverProperties.put(BoostProperties.DATASOURCE_PORT_NUMBER, MYSQL_DEFAULT_PORT_NUMBER);
}

// Find and add all "boost.db." properties. This will override any default values
this.serverProperties.put(BoostProperties.DATASOURCE_PORT_NUMBER, MYSQL_DEFAULT_PORT_NUMBER);
}

// Find and add all "boost.db." properties. This will override any
// default values
for (String key : boostConfigProperties.stringPropertyNames()) {
if ( key.startsWith(BoostProperties.DATASOURCE_PREFIX)) {
String value = (String) boostConfigProperties.get(key);
this.serverProperties.put(key, value);
}
if (key.startsWith(BoostProperties.DATASOURCE_PREFIX)) {
String value = (String) boostConfigProperties.get(key);
this.serverProperties.put(key, value);
}
}
}

Expand All @@ -145,14 +153,14 @@ public String getDependency() {
public void addServerConfig(Document doc) {

if (dependency.startsWith(DERBY_DEPENDENCY)) {
addDatasourceConfig(doc, PROPERTIES_DERBY_EMBEDDED, DERBY_JAR);
addDatasourceConfig(doc, PROPERTIES_DERBY_EMBEDDED, DERBY_JAR);

} else if (dependency.startsWith(DB2_DEPENDENCY)) {
addDatasourceConfig(doc, PROPERTIES_DB2_JCC, DB2_JAR);
addDatasourceConfig(doc, PROPERTIES_DB2_JCC, DB2_JAR);

} else if (dependency.startsWith(MYSQL_DEPENDENCY)) {
// Use generic <properties> element for MySQL
addDatasourceConfig(doc, PROPERTIES, MYSQL_JAR);
// Use generic <properties> element for MySQL
addDatasourceConfig(doc, PROPERTIES, MYSQL_JAR);
}
}

Expand Down Expand Up @@ -194,27 +202,30 @@ private void addDatasourceConfig(Document doc, String datasourcePropertiesElemen
jdbcDriver.setAttribute("id", JDBC_DRIVER_1);
jdbcDriver.setAttribute(LIBRARY_REF, JDBC_LIBRARY_1);
serverRoot.appendChild(jdbcDriver);

// Add container authentication
if (this.serverProperties.containsKey(BoostProperties.DATASOURCE_USER) && this.serverProperties.containsKey(BoostProperties.DATASOURCE_PASSWORD)) {
dataSource.setAttribute(CONTAINER_AUTH_DATA_REF, DATASOURCE_AUTH_DATA);

Element containerAuthData = doc.createElement(AUTH_DATA);
containerAuthData.setAttribute("id", DATASOURCE_AUTH_DATA);
containerAuthData.setAttribute(USER, BoostUtil.makeVariable(BoostProperties.DATASOURCE_USER));
containerAuthData.setAttribute(PASSWORD, BoostUtil.makeVariable(BoostProperties.DATASOURCE_PASSWORD));
serverRoot.appendChild(containerAuthData);
if (this.serverProperties.containsKey(BoostProperties.DATASOURCE_USER)
&& this.serverProperties.containsKey(BoostProperties.DATASOURCE_PASSWORD)) {
dataSource.setAttribute(CONTAINER_AUTH_DATA_REF, DATASOURCE_AUTH_DATA);

Element containerAuthData = doc.createElement(AUTH_DATA);
containerAuthData.setAttribute("id", DATASOURCE_AUTH_DATA);
containerAuthData.setAttribute(USER, BoostUtil.makeVariable(BoostProperties.DATASOURCE_USER));
containerAuthData.setAttribute(PASSWORD, BoostUtil.makeVariable(BoostProperties.DATASOURCE_PASSWORD));
serverRoot.appendChild(containerAuthData);
}
}

private void addDatasourceProperties(Element properties) {
for (String property : this.serverProperties.stringPropertyNames()) {
// We are using container authentication. Do not include user or password here
if ( !property.equals(BoostProperties.DATASOURCE_USER) && !property.equals(BoostProperties.DATASOURCE_PASSWORD)) {

String attribute = property.replace(BoostProperties.DATASOURCE_PREFIX, "");
properties.setAttribute(attribute, BoostUtil.makeVariable(property));
}
for (String property : this.serverProperties.stringPropertyNames()) {
// We are using container authentication. Do not include user or
// password here
if (!property.equals(BoostProperties.DATASOURCE_USER)
&& !property.equals(BoostProperties.DATASOURCE_PASSWORD)) {

String attribute = property.replace(BoostProperties.DATASOURCE_PREFIX, "");
properties.setAttribute(attribute, BoostUtil.makeVariable(property));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package io.openliberty.boost.common.boosters;
package io.openliberty.boost.common.boosters.liberty;

import org.w3c.dom.Document;

import io.openliberty.boost.common.BoostException;
import io.openliberty.boost.common.BoostLoggerI;
import io.openliberty.boost.common.boosters.AbstractBoosterConfig.BoosterCoordinates;

import static io.openliberty.boost.common.config.ConfigConstants.*;
import static io.openliberty.boost.common.config.LibertyConfigConstants.*;

import java.util.Map;
import java.util.Properties;

@BoosterCoordinates(AbstractBoosterConfig.BOOSTERS_GROUP_ID + ":jpa")
public class JPABoosterConfig extends AbstractBoosterConfig {
@BoosterCoordinates(AbstractBoosterLibertyConfig.BOOSTERS_GROUP_ID + ":jpa")
public class JPABoosterLibertyConfig extends AbstractBoosterLibertyConfig {

String libertyFeature = null;

public JPABoosterConfig(Map<String, String> dependencies, BoostLoggerI logger) throws BoostException {
public JPABoosterLibertyConfig(Map<String, String> dependencies, BoostLoggerI logger) throws BoostException {
String version = dependencies.get(getCoordindates(this.getClass()));
if (version.equals(EE_7_VERSION)) {
libertyFeature = JPA_21;
Expand Down
Loading

0 comments on commit c3288f6

Please sign in to comment.