From ca487d4dee2bf2f74f77adbf896f60e1df81e7a9 Mon Sep 17 00:00:00 2001 From: Andrew Mauer Date: Tue, 4 Dec 2018 15:37:04 -0500 Subject: [PATCH 1/6] introduce microprofile support - new repo structure remove 18002 level tests from travis env comment out 18004 level tests from travis env until 18004 is available --- .travis.yml | 21 +-- .../config/BoosterPackConfigurator.java | 1 + .../config/CDIBoosterPackConfigurator.java | 44 +++++ .../boost/common/config/ConfigConstants.java | 5 + .../config/JSONPBoosterPackConfigurator.java | 44 +++++ .../config/LibertyServerConfigGenerator.java | 2 - .../MPConfigBoosterPackConfigurator.java | 44 +++++ .../MPHealthBoosterPackConfigurator.java | 44 +++++ .../MPOpenTracingBoosterPackConfigurator.java | 44 +++++ .../MPRestClientBoosterPackConfigurator.java | 44 +++++ .../common/utils/LibertyBoosterUtil.java | 46 ++++- .../boost-boms/boost-mp20-apis-bom/pom.xml | 119 +++++++++++++ .../boost-boms/booster-mp20-bom/pom.xml | 67 ++++++++ boost-maven/boost-boms/pom.xml | 7 +- .../booster-cdi-ee8/invoker.properties | 1 + .../boost-boosters/booster-cdi-ee8/pom.xml | 30 ++++ .../booster-jsonp-ee8/invoker.properties | 1 + .../boost-boosters/booster-jsonp-ee8/pom.xml | 30 ++++ .../booster-mpConfig-20/invoker.properties | 1 + .../booster-mpConfig-20/pom.xml | 30 ++++ .../booster-mpHealth-20/invoker.properties | 1 + .../booster-mpHealth-20/pom.xml | 30 ++++ .../invoker.properties | 1 + .../booster-mpOpenTracing-20/pom.xml | 30 ++++ .../invoker.properties | 1 + .../booster-mpRestClient-20/pom.xml | 30 ++++ .../src/it/test-mpHealth-1.0/pom.xml | 162 ++++++++++++++++++ .../guides/config/CustomConfigSource.java | 103 +++++++++++ .../inventory/InventoryApplication.java | 21 +++ .../guides/inventory/InventoryConfig.java | 49 ++++++ .../guides/inventory/InventoryHealth.java | 68 ++++++++ .../guides/inventory/InventoryManager.java | 48 ++++++ .../guides/inventory/InventoryResource.java | 81 +++++++++ .../guides/inventory/InventoryUtils.java | 87 ++++++++++ .../guides/inventory/client/SystemClient.java | 37 ++++ .../inventory/client/UnknownUrlException.java | 28 +++ .../client/UnknownUrlExceptionMapper.java | 38 ++++ .../guides/inventory/model/InventoryList.java | 32 ++++ .../guides/inventory/model/SystemData.java | 44 +++++ .../guides/system/SystemApplication.java | 21 +++ .../guides/system/SystemHealth.java | 35 ++++ .../guides/system/SystemResource.java | 31 ++++ .../main/resources/CustomConfigSource.json | 4 + .../META-INF/microprofile-config.properties | 11 ++ ...lipse.microprofile.config.spi.ConfigSource | 3 + .../src/main/webapp/WEB-INF/web.xml | 10 ++ .../src/main/webapp/index.html | 78 +++++++++ .../guides/health/HealthTestIT.java | 69 ++++++++ .../guides/health/HealthTestUtil.java | 97 +++++++++++ 49 files changed, 1848 insertions(+), 27 deletions(-) create mode 100644 boost-common/src/main/java/io/openliberty/boost/common/config/CDIBoosterPackConfigurator.java create mode 100644 boost-common/src/main/java/io/openliberty/boost/common/config/JSONPBoosterPackConfigurator.java create mode 100644 boost-common/src/main/java/io/openliberty/boost/common/config/MPConfigBoosterPackConfigurator.java create mode 100644 boost-common/src/main/java/io/openliberty/boost/common/config/MPHealthBoosterPackConfigurator.java create mode 100644 boost-common/src/main/java/io/openliberty/boost/common/config/MPOpenTracingBoosterPackConfigurator.java create mode 100644 boost-common/src/main/java/io/openliberty/boost/common/config/MPRestClientBoosterPackConfigurator.java create mode 100644 boost-maven/boost-boms/boost-mp20-apis-bom/pom.xml create mode 100644 boost-maven/boost-boms/booster-mp20-bom/pom.xml create mode 100644 boost-maven/boost-boosters/booster-cdi-ee8/invoker.properties create mode 100644 boost-maven/boost-boosters/booster-cdi-ee8/pom.xml create mode 100644 boost-maven/boost-boosters/booster-jsonp-ee8/invoker.properties create mode 100644 boost-maven/boost-boosters/booster-jsonp-ee8/pom.xml create mode 100644 boost-maven/boost-boosters/booster-mpConfig-20/invoker.properties create mode 100644 boost-maven/boost-boosters/booster-mpConfig-20/pom.xml create mode 100644 boost-maven/boost-boosters/booster-mpHealth-20/invoker.properties create mode 100644 boost-maven/boost-boosters/booster-mpHealth-20/pom.xml create mode 100644 boost-maven/boost-boosters/booster-mpOpenTracing-20/invoker.properties create mode 100644 boost-maven/boost-boosters/booster-mpOpenTracing-20/pom.xml create mode 100644 boost-maven/boost-boosters/booster-mpRestClient-20/invoker.properties create mode 100644 boost-maven/boost-boosters/booster-mpRestClient-20/pom.xml create mode 100644 boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/pom.xml create mode 100644 boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/config/CustomConfigSource.java create mode 100644 boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryApplication.java create mode 100644 boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryConfig.java create mode 100644 boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryHealth.java create mode 100644 boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryManager.java create mode 100644 boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryResource.java create mode 100644 boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryUtils.java create mode 100644 boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/client/SystemClient.java create mode 100644 boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/client/UnknownUrlException.java create mode 100644 boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/client/UnknownUrlExceptionMapper.java create mode 100644 boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/model/InventoryList.java create mode 100644 boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/model/SystemData.java create mode 100644 boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/system/SystemApplication.java create mode 100644 boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/system/SystemHealth.java create mode 100644 boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/system/SystemResource.java create mode 100644 boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/resources/CustomConfigSource.json create mode 100644 boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/resources/META-INF/microprofile-config.properties create mode 100644 boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource create mode 100644 boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/webapp/WEB-INF/web.xml create mode 100644 boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/webapp/index.html create mode 100644 boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/test/java/it/io/openliberty/guides/health/HealthTestIT.java create mode 100644 boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/test/java/it/io/openliberty/guides/health/HealthTestUtil.java diff --git a/.travis.yml b/.travis.yml index c9898cce..b3aae722 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,28 +16,15 @@ matrix: env: RUNTIME=wlp RUNTIME_VERSION=18.0.0.3 BUILD_TOOL=maven - jdk: oraclejdk9 env: RUNTIME=wlp RUNTIME_VERSION=18.0.0.3 BUILD_TOOL=gradle - # Exclude 18.0.0.2 WLP - - jdk: openjdk8 - env: RUNTIME=wlp RUNTIME_VERSION=18.0.0.2 BUILD_TOOL=maven - - jdk: openjdk8 - env: RUNTIME=wlp RUNTIME_VERSION=18.0.0.2 BUILD_TOOL=gradle - - jdk: oraclejdk8 - env: RUNTIME=wlp RUNTIME_VERSION=18.0.0.2 BUILD_TOOL=maven - - jdk: oraclejdk8 - env: RUNTIME=wlp RUNTIME_VERSION=18.0.0.2 BUILD_TOOL=gradle - - jdk: oraclejdk9 - env: RUNTIME=wlp RUNTIME_VERSION=18.0.0.2 BUILD_TOOL=maven - - jdk: oraclejdk9 - env: RUNTIME=wlp RUNTIME_VERSION=18.0.0.2 BUILD_TOOL=gradle env: - - RUNTIME=ol RUNTIME_VERSION=18.0.0.2 BUILD_TOOL=maven - RUNTIME=ol RUNTIME_VERSION=18.0.0.3 BUILD_TOOL=maven - - RUNTIME=wlp RUNTIME_VERSION=18.0.0.2 BUILD_TOOL=maven +# - RUNTIME=ol RUNTIME_VERSION=18.0.0.4 BUILD_TOOL=maven - RUNTIME=wlp RUNTIME_VERSION=18.0.0.3 BUILD_TOOL=maven - - RUNTIME=ol RUNTIME_VERSION=18.0.0.2 BUILD_TOOL=gradle +# - RUNTIME=wlp RUNTIME_VERSION=18.0.0.4 BUILD_TOOL=maven - RUNTIME=ol RUNTIME_VERSION=18.0.0.3 BUILD_TOOL=gradle - - RUNTIME=wlp RUNTIME_VERSION=18.0.0.2 BUILD_TOOL=gradle +# - RUNTIME=ol RUNTIME_VERSION=18.0.0.4 BUILD_TOOL=gradle - RUNTIME=wlp RUNTIME_VERSION=18.0.0.3 BUILD_TOOL=gradle +# - RUNTIME=wlp RUNTIME_VERSION=18.0.0.4 BUILD_TOOL=gradle cache: directories: - $HOME/.m2 diff --git a/boost-common/src/main/java/io/openliberty/boost/common/config/BoosterPackConfigurator.java b/boost-common/src/main/java/io/openliberty/boost/common/config/BoosterPackConfigurator.java index 2c4d2703..9a6138b6 100644 --- a/boost-common/src/main/java/io/openliberty/boost/common/config/BoosterPackConfigurator.java +++ b/boost-common/src/main/java/io/openliberty/boost/common/config/BoosterPackConfigurator.java @@ -25,6 +25,7 @@ public abstract class BoosterPackConfigurator { 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 diff --git a/boost-common/src/main/java/io/openliberty/boost/common/config/CDIBoosterPackConfigurator.java b/boost-common/src/main/java/io/openliberty/boost/common/config/CDIBoosterPackConfigurator.java new file mode 100644 index 00000000..6093a906 --- /dev/null +++ b/boost-common/src/main/java/io/openliberty/boost/common/config/CDIBoosterPackConfigurator.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * 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.config; + +import static io.openliberty.boost.common.config.ConfigConstants.CDI_20; + +import org.w3c.dom.Document; + +public class CDIBoosterPackConfigurator extends BoosterPackConfigurator { + + String libertyFeature = null; + + @Override + public void setFeature(String version) { + // if it is the 1.0 version = EE7 feature level + if (version.equals(MP_20_VERSION)) { + libertyFeature = CDI_20; + } + } + + @Override + public String getFeature() { + return libertyFeature; + } + + @Override + public void addServerConfig(Document doc) { + // No config to write + + } + + @Override + public String getDependencyToCopy() { + return null; + } +} diff --git a/boost-common/src/main/java/io/openliberty/boost/common/config/ConfigConstants.java b/boost-common/src/main/java/io/openliberty/boost/common/config/ConfigConstants.java index 67ceb24d..6a710f6b 100644 --- a/boost-common/src/main/java/io/openliberty/boost/common/config/ConfigConstants.java +++ b/boost-common/src/main/java/io/openliberty/boost/common/config/ConfigConstants.java @@ -64,6 +64,11 @@ public interface ConfigConstants { public String JAXRS_21 = "jaxrs-2.1"; public String JDBC_41 = "jdbc-4.1"; public String JDBC_42 = "jdbc-4.2"; + public String CDI_20 = "cdi-2.0"; + public String MPHEALTH_10 = "mpHealth-1.0"; + public String MPRESTCLIENT_11 = "mpRestClient-1.1"; + public String JSONP_11 = "jsonp-1.1"; + public String MPCONFIG_13 = "mpConfig-1.3"; public String SHARED_RESOURCES_DIR = "${shared.resource.dir}"; public String SERVER_OUTPUT_DIR = "${server.output.dir}"; diff --git a/boost-common/src/main/java/io/openliberty/boost/common/config/JSONPBoosterPackConfigurator.java b/boost-common/src/main/java/io/openliberty/boost/common/config/JSONPBoosterPackConfigurator.java new file mode 100644 index 00000000..69e0c60e --- /dev/null +++ b/boost-common/src/main/java/io/openliberty/boost/common/config/JSONPBoosterPackConfigurator.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * 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.config; + +import static io.openliberty.boost.common.config.ConfigConstants.JSONP_11; + +import org.w3c.dom.Document; + +public class JSONPBoosterPackConfigurator extends BoosterPackConfigurator { + + String libertyFeature = null; + + @Override + public void setFeature(String version) { + // if it is the 1.0 version = EE7 feature level + if (version.equals(MP_20_VERSION)) { + libertyFeature = JSONP_11; + } + } + + @Override + public String getFeature() { + return libertyFeature; + } + + @Override + public void addServerConfig(Document doc) { + // No config to write + + } + + @Override + public String getDependencyToCopy() { + return null; + } +} \ No newline at end of file diff --git a/boost-common/src/main/java/io/openliberty/boost/common/config/LibertyServerConfigGenerator.java b/boost-common/src/main/java/io/openliberty/boost/common/config/LibertyServerConfigGenerator.java index 1874d434..2cce773d 100644 --- a/boost-common/src/main/java/io/openliberty/boost/common/config/LibertyServerConfigGenerator.java +++ b/boost-common/src/main/java/io/openliberty/boost/common/config/LibertyServerConfigGenerator.java @@ -144,7 +144,6 @@ public void addKeystore(Map keystoreProps, Map k * The full name of the Liberty feature to add. */ public void addFeature(String featureName) { - if (!featuresAdded.contains(featureName)) { Element feature = doc.createElement(FEATURE); feature.appendChild(doc.createTextNode(featureName)); @@ -175,7 +174,6 @@ public void addFeatures(List features) { * @throws IOException */ public void writeToServer() throws TransformerException, IOException { - // Replace auto-generated server.xml TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); diff --git a/boost-common/src/main/java/io/openliberty/boost/common/config/MPConfigBoosterPackConfigurator.java b/boost-common/src/main/java/io/openliberty/boost/common/config/MPConfigBoosterPackConfigurator.java new file mode 100644 index 00000000..e1253db6 --- /dev/null +++ b/boost-common/src/main/java/io/openliberty/boost/common/config/MPConfigBoosterPackConfigurator.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * 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.config; + +import static io.openliberty.boost.common.config.ConfigConstants.MPCONFIG_13; + +import org.w3c.dom.Document; + +public class MPConfigBoosterPackConfigurator extends BoosterPackConfigurator { + + String libertyFeature = null; + + @Override + public void setFeature(String version) { + // if it is the 1.0 version = EE7 feature level + if (version.equals(MP_20_VERSION)) { + libertyFeature = MPCONFIG_13; + } + } + + @Override + public String getFeature() { + return libertyFeature; + } + + @Override + public void addServerConfig(Document doc) { + // No config to write + + } + + @Override + public String getDependencyToCopy() { + return null; + } +} diff --git a/boost-common/src/main/java/io/openliberty/boost/common/config/MPHealthBoosterPackConfigurator.java b/boost-common/src/main/java/io/openliberty/boost/common/config/MPHealthBoosterPackConfigurator.java new file mode 100644 index 00000000..ea29d83c --- /dev/null +++ b/boost-common/src/main/java/io/openliberty/boost/common/config/MPHealthBoosterPackConfigurator.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * 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.config; + +import static io.openliberty.boost.common.config.ConfigConstants.MPHEALTH_10; + +import org.w3c.dom.Document; + +public class MPHealthBoosterPackConfigurator extends BoosterPackConfigurator { + + String libertyFeature = null; + + @Override + public void setFeature(String version) { + // if it is the 2.0 version = MP2.0 feature level + if (version.equals(MP_20_VERSION)) { + libertyFeature = MPHEALTH_10; + } + } + + @Override + public String getFeature() { + return libertyFeature; + } + + @Override + public void addServerConfig(Document doc) { + // No config to write + + } + + @Override + public String getDependencyToCopy() { + return null; + } +} diff --git a/boost-common/src/main/java/io/openliberty/boost/common/config/MPOpenTracingBoosterPackConfigurator.java b/boost-common/src/main/java/io/openliberty/boost/common/config/MPOpenTracingBoosterPackConfigurator.java new file mode 100644 index 00000000..a5ce134c --- /dev/null +++ b/boost-common/src/main/java/io/openliberty/boost/common/config/MPOpenTracingBoosterPackConfigurator.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * 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.config; + +import static io.openliberty.boost.common.config.ConfigConstants.MPHEALTH_10; + +import org.w3c.dom.Document; + +public class MPOpenTracingBoosterPackConfigurator extends BoosterPackConfigurator { + + String libertyFeature = null; + + @Override + public void setFeature(String version) { + // if it is the 1.0 version = EE7 feature level + if (version.equals(MP_20_VERSION)) { + libertyFeature = MPHEALTH_10; + } + } + + @Override + public String getFeature() { + return libertyFeature; + } + + @Override + public void addServerConfig(Document doc) { + // No config to write + + } + + @Override + public String getDependencyToCopy() { + return null; + } +} diff --git a/boost-common/src/main/java/io/openliberty/boost/common/config/MPRestClientBoosterPackConfigurator.java b/boost-common/src/main/java/io/openliberty/boost/common/config/MPRestClientBoosterPackConfigurator.java new file mode 100644 index 00000000..69d7726a --- /dev/null +++ b/boost-common/src/main/java/io/openliberty/boost/common/config/MPRestClientBoosterPackConfigurator.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * 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.config; + +import static io.openliberty.boost.common.config.ConfigConstants.MPRESTCLIENT_11; + +import org.w3c.dom.Document; + +public class MPRestClientBoosterPackConfigurator extends BoosterPackConfigurator { + + String libertyFeature = null; + + @Override + public void setFeature(String version) { + // if it is the 1.0 version = EE7 feature level + if (version.equals(MP_20_VERSION)) { + libertyFeature = MPRESTCLIENT_11; + } + } + + @Override + public String getFeature() { + return libertyFeature; + } + + @Override + public void addServerConfig(Document doc) { + // No config to write + + } + + @Override + public String getDependencyToCopy() { + return null; + } +} diff --git a/boost-common/src/main/java/io/openliberty/boost/common/utils/LibertyBoosterUtil.java b/boost-common/src/main/java/io/openliberty/boost/common/utils/LibertyBoosterUtil.java index edafd7b3..c436a9ca 100644 --- a/boost-common/src/main/java/io/openliberty/boost/common/utils/LibertyBoosterUtil.java +++ b/boost-common/src/main/java/io/openliberty/boost/common/utils/LibertyBoosterUtil.java @@ -16,9 +16,15 @@ import io.openliberty.boost.common.BoostLoggerI; import io.openliberty.boost.common.config.BoosterPackConfigurator; +import io.openliberty.boost.common.config.CDIBoosterPackConfigurator; import io.openliberty.boost.common.config.JAXRSBoosterPackConfigurator; import io.openliberty.boost.common.config.JDBCBoosterPackConfigurator; +import io.openliberty.boost.common.config.JSONPBoosterPackConfigurator; import io.openliberty.boost.common.config.LibertyServerConfigGenerator; +import io.openliberty.boost.common.config.MPConfigBoosterPackConfigurator; +import io.openliberty.boost.common.config.MPHealthBoosterPackConfigurator; +import io.openliberty.boost.common.config.MPOpenTracingBoosterPackConfigurator; +import io.openliberty.boost.common.config.MPRestClientBoosterPackConfigurator; public class LibertyBoosterUtil { @@ -26,7 +32,13 @@ public class LibertyBoosterUtil { public static String BOOSTER_JAXRS = "jaxrs"; public static String BOOSTER_JDBC = "jdbc"; - + public static String BOOSTER_MPHEALTH = "mpHealth"; + public static String BOOSTER_JSONP = "jsonp"; + public static String BOOSTER_CDI = "cdi"; + public static String BOOSTER_MPCONFIG = "mpConfig"; + public static String BOOSTER_MPRESTCLIENT = "mpRestClient"; + public static String BOOSTER_OPENTRACING = "mpOpenTracing"; + protected String libertyServerPath; protected List boosterPackConfigurators; protected BoostLoggerI logger; @@ -50,18 +62,41 @@ private List getBoosterPackConfigurators(Map boosterPackConfigList = new ArrayList(); + for (String dep : dependencies.keySet()) { if (dep.equals(BOOSTER_JDBC)) { JDBCBoosterPackConfigurator jdbcConfig = new JDBCBoosterPackConfigurator(); jdbcConfig.setFeature(dependencies.get(dep)); boosterPackConfigList.add(jdbcConfig); - } else if (dep.equals(BOOSTER_JAXRS)) { JAXRSBoosterPackConfigurator jaxrsConfig = new JAXRSBoosterPackConfigurator(); jaxrsConfig.setFeature(dependencies.get(dep)); boosterPackConfigList.add(jaxrsConfig); - } - + } else if (dep.equals(BOOSTER_MPHEALTH)) { + MPHealthBoosterPackConfigurator mpHealthConfig = new MPHealthBoosterPackConfigurator(); + mpHealthConfig.setFeature(dependencies.get(dep)); + boosterPackConfigList.add(mpHealthConfig); + } else if (dep.equals(BOOSTER_MPCONFIG)) { + MPConfigBoosterPackConfigurator mpConfigConfig = new MPConfigBoosterPackConfigurator(); + mpConfigConfig.setFeature(dependencies.get(dep)); + boosterPackConfigList.add(mpConfigConfig); + } else if (dep.equals(BOOSTER_CDI)) { + CDIBoosterPackConfigurator CDIConfig = new CDIBoosterPackConfigurator(); + CDIConfig.setFeature(dependencies.get(dep)); + boosterPackConfigList.add(CDIConfig); + } else if (dep.equals(BOOSTER_MPRESTCLIENT)) { + MPRestClientBoosterPackConfigurator mpRestClientConfig = new MPRestClientBoosterPackConfigurator(); + mpRestClientConfig.setFeature(dependencies.get(dep)); + boosterPackConfigList.add(mpRestClientConfig); + } else if (dep.equals(BOOSTER_JSONP)) { + JSONPBoosterPackConfigurator jsonpConfig = new JSONPBoosterPackConfigurator(); + jsonpConfig.setFeature(dependencies.get(dep)); + boosterPackConfigList.add(jsonpConfig); + } else if (dep.equals(BOOSTER_OPENTRACING)) { + MPOpenTracingBoosterPackConfigurator mpOpenTracingConfig = new MPOpenTracingBoosterPackConfigurator(); + mpOpenTracingConfig.setFeature(dependencies.get(dep)); + boosterPackConfigList.add(mpOpenTracingConfig); + } } return boosterPackConfigList; @@ -90,12 +125,11 @@ public void generateLibertyServerConfig(String warName) throws Exception { } public List getDependenciesToCopy() { - + List dependenciesToCopy = new ArrayList(); for (BoosterPackConfigurator configurator : boosterPackConfigurators) { String dependencyToCopy = configurator.getDependencyToCopy(); - if (dependencyToCopy != null) { dependenciesToCopy.add(dependencyToCopy); diff --git a/boost-maven/boost-boms/boost-mp20-apis-bom/pom.xml b/boost-maven/boost-boms/boost-mp20-apis-bom/pom.xml new file mode 100644 index 00000000..bbaaf069 --- /dev/null +++ b/boost-maven/boost-boms/boost-mp20-apis-bom/pom.xml @@ -0,0 +1,119 @@ + + + 4.0.0 + + io.openliberty.boost + boost-mp20-apis-bom + + 0.1-SNAPSHOT + pom + + Booster MP20 APIs Bom + + + + 2.0 + 2.1 + 1.1 + 1.0 + 1.2 + + + 1.3 + 1.1 + 1.0 + 1.1 + 1.1 + 1.0 + 1.1 + 1.1 + + + + + + + javax.enterprise + cdi-api + ${cdi-version} + + + javax.ws.rs + javax.ws.rs-api + ${jaxrs-version} + + + javax.json + javax.json-api + ${jsonp-version} + + + javax.annotation + javax.annotation-api + ${annotation-version} + + + org.eclipse.microprofile.config + microprofile-config-api + ${config-version} + + + org.eclipse.microprofile.fault-tolerance + microprofile-fault-tolerance-api + ${ft-version} + + + org.eclipse.microprofile.health + microprofile-health-api + ${health-version} + + + org.eclipse.microprofile.metrics + microprofile-metrics-api + ${metrics-version} + + + org.eclipse.microprofile.jwt + microprofile-jwt-auth-api + ${jwt-version} + + + org.eclipse.microprofile.openapi + microprofile-openapi-api + ${openapi-version} + + + org.eclipse.microprofile.rest.client + microprofile-rest-client-api + ${rest-client-version} + + + org.eclipse.microprofile.opentracing + microprofile-opentracing-api + ${opentracing-version} + + + io.openliberty.boosters + jaxrs + ${jaxrs-version} + + + io.openliberty.boosters + cdi + ${cdi-version} + + + io.openliberty.boosters + jsonp + ${jsonp-version} + + + + + diff --git a/boost-maven/boost-boms/booster-mp20-bom/pom.xml b/boost-maven/boost-boms/booster-mp20-bom/pom.xml new file mode 100644 index 00000000..182e30a0 --- /dev/null +++ b/boost-maven/boost-boms/booster-mp20-bom/pom.xml @@ -0,0 +1,67 @@ + + + 4.0.0 + + + + io.openliberty.boost + boost-maven-parent + 0.1.3-SNAPSHOT + ../.. + + + io.openliberty.boosters + mp20-bom + pom + + Booster MP20 Feature Bom + + + + + io.openliberty.boost + boost-mp20-apis-bom + 0.1-SNAPSHOT + import + pom + + + io.openliberty.boosters + mpHealth + 0.2-SNAPSHOT + + + io.openliberty.boosters + mpConfig + 0.2-SNAPSHOT + + + io.openliberty.boosters + mpRestClient + 0.2-SNAPSHOT + + + io.openliberty.boosters + jaxrs + 0.2-SNAPSHOT + + + io.openliberty.boosters + jsonp + 0.2-SNAPSHOT + + + io.openliberty.boosters + cdi + 0.2-SNAPSHOT + + + + + diff --git a/boost-maven/boost-boms/pom.xml b/boost-maven/boost-boms/pom.xml index 36a709d0..8f3b0827 100644 --- a/boost-maven/boost-boms/pom.xml +++ b/boost-maven/boost-boms/pom.xml @@ -1,4 +1,3 @@ - + 9080 + 9443 + + ${project.build.directory}/${app.name}.zip + usr + + + + + + sonatype-nexus-snapshots + Sonatype Nexus Snapshots + https://oss.sonatype.org/content/repositories/snapshots/ + + true + + + false + + + + + + + + io.openliberty.boosters + mp20-bom + @pom.version@ + pom + import + + + + + + + + junit + junit + 4.12 + test + + + org.apache.cxf + cxf-rt-rs-client + 3.1.11 + test + + + org.apache.cxf + cxf-rt-rs-extension-providers + 3.1.11 + test + + + org.glassfish + javax.json + 1.0.4 + test + + + + io.openliberty.boosters + jaxrs + + + io.openliberty.boosters + jsonp + + + io.openliberty.boosters + cdi + + + io.openliberty.boosters + mpConfig + + + io.openliberty.boosters + mpRestClient + + + io.openliberty.boosters + mpHealth + + + + org.apache.commons + commons-lang3 + 3.0 + + + + + + + io.openliberty.boost + boost-maven-plugin + @pom.version@ + + + ${runtimeGroupId} + ${runtimeArtifactId} + ${runtimeVersion} + zip + + + + + + package + + + + test-start-server + pre-integration-test + + start + + + + test-stop-server + post-integration-test + + stop + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + 2.19.1 + + + + integration-test + verify + + + + + + + \ No newline at end of file diff --git a/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/config/CustomConfigSource.java b/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/config/CustomConfigSource.java new file mode 100644 index 00000000..32b8d541 --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/config/CustomConfigSource.java @@ -0,0 +1,103 @@ +// tag::copyright[] +/******************************************************************************* + * Copyright (c) 2017 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 implementation + *******************************************************************************/ +// end::copyright[] + +// tag::customConfig[] +package io.openliberty.guides.config; + +import javax.json.stream.JsonParser; +import javax.json.stream.JsonParser.Event; +import javax.json.Json; +import java.math.BigDecimal; +import java.util.*; +import java.io.StringReader; +import java.io.BufferedReader; +import java.io.FileReader; +import org.eclipse.microprofile.config.spi.ConfigSource; + +public class CustomConfigSource implements ConfigSource { + + String fileLocation = System.getProperty("user.dir").split("target")[0] + + "target/it/test-mpHealth-1.0/src/main/resources/CustomConfigSource.json"; + + @Override + public int getOrdinal() { + return Integer.parseInt(getProperties().get("config_ordinal")); + } + + @Override + public Set getPropertyNames() { + return getProperties().keySet(); + } + + @Override + public String getValue(String key) { + return getProperties().get(key); + } + + @Override + public String getName() { + return "Custom Config Source: file:" + this.fileLocation; + } + + public Map getProperties() { + Map m = new HashMap(); + String jsonData = this.readFile(this.fileLocation); + JsonParser parser = Json.createParser(new StringReader(jsonData)); + String key = null; + while (parser.hasNext()) { + final Event event = parser.next(); + switch (event) { + case KEY_NAME: + key = parser.getString(); + break; + case VALUE_STRING: + String string = parser.getString(); + m.put(key, string); + break; + case VALUE_NUMBER: + BigDecimal number = parser.getBigDecimal(); + m.put(key, number.toString()); + break; + case VALUE_TRUE: + m.put(key, "true"); + break; + case VALUE_FALSE: + m.put(key, "false"); + break; + default: + break; + } + } + parser.close(); + return m; + } + + public String readFile(String fileName) { + String result = ""; + try { + BufferedReader br = new BufferedReader(new FileReader(fileName)); + StringBuilder sb = new StringBuilder(); + String line = br.readLine(); + while (line != null) { + sb.append(line); + line = br.readLine(); + } + result = sb.toString(); + br.close(); + } catch (Exception e) { + e.printStackTrace(); + } + return result; + } +} +// end::customConfig[] diff --git a/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryApplication.java b/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryApplication.java new file mode 100644 index 00000000..612e61cc --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryApplication.java @@ -0,0 +1,21 @@ +// tag::copyright[] +/******************************************************************************* + * Copyright (c) 2017 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 implementation + *******************************************************************************/ +// end::copyright[] +package io.openliberty.guides.inventory; + +import javax.ws.rs.ApplicationPath; +import javax.ws.rs.core.Application; + +@ApplicationPath("inventory") +public class InventoryApplication extends Application { + +} diff --git a/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryConfig.java b/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryConfig.java new file mode 100644 index 00000000..0ab6821c --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryConfig.java @@ -0,0 +1,49 @@ +// tag::copyright[] +/******************************************************************************* + * Copyright (c) 2017 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 implementation + *******************************************************************************/ +// end::copyright[] + +// tag::config-class[] +package io.openliberty.guides.inventory; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; +import javax.inject.Provider; +import org.eclipse.microprofile.config.inject.ConfigProperty; + +@ApplicationScoped +public class InventoryConfig { + + // tag::port-number[] + @Inject + @ConfigProperty(name = "io_openliberty_guides_port_number") + private int portNumber; + // end::port-number[] + + // tag::build-in-converter[] + @Inject + @ConfigProperty(name = "io_openliberty_guides_inventory_inMaintenance") + private Provider inMaintenance; + // end::build-in-converter[] + + // tag::isInMaintenance[] + public boolean isInMaintenance() { + return inMaintenance.get(); + } + // end::isInMaintenance[] + + // tag::getPortNumber[] + public int getPortNumber() { + return portNumber; + } + // end::getPortNumber[] +} +// end::config-class[] diff --git a/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryHealth.java b/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryHealth.java new file mode 100644 index 00000000..26d22462 --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryHealth.java @@ -0,0 +1,68 @@ +// tag::comment[] +/******************************************************************************* + * 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 implementation + *******************************************************************************/ +// end::comment[] +// tag::InventoryHealth[] +package io.openliberty.guides.inventory; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import io.openliberty.guides.inventory.client.SystemClient; +import org.eclipse.microprofile.health.Health; +import org.eclipse.microprofile.health.HealthCheck; +import org.eclipse.microprofile.health.HealthCheckResponse; + +@Health +@ApplicationScoped +public class InventoryHealth implements HealthCheck { + @Inject + InventoryConfig config; + + private InventoryUtils invUtils = new InventoryUtils(); + + public boolean isHealthy() { + if (config.isInMaintenance()) { + return false; + } + try { + String url = invUtils.buildUrl("http", "localhost", + //Integer.parseInt(System.getProperty("default.http.port")), + 9080, + "/system/properties"); + Client client = ClientBuilder.newClient(); + Response response = client.target(url).request(MediaType.APPLICATION_JSON) + .get(); + if (response.getStatus() != 200) { + return false; + } + return true; + } catch (Exception e) { + return false; + } + } + + @Override + public HealthCheckResponse call() { + if (!isHealthy()) { + return HealthCheckResponse.named(InventoryResource.class.getSimpleName()) + .withData("services", "not available").down() + .build(); + } + return HealthCheckResponse.named(InventoryResource.class.getSimpleName()) + .withData("services", "available").up().build(); + } + +} +// end::InventoryHealth[] diff --git a/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryManager.java b/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryManager.java new file mode 100644 index 00000000..d6e0ae9b --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryManager.java @@ -0,0 +1,48 @@ +// tag::copyright[] +/******************************************************************************* + * Copyright (c) 2017, 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 implementation + *******************************************************************************/ +// end::copyright[] +// tag::manager[] +package io.openliberty.guides.inventory; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Properties; +import javax.enterprise.context.ApplicationScoped; +import io.openliberty.guides.inventory.model.*; + +@ApplicationScoped +public class InventoryManager { + + private List systems = Collections.synchronizedList(new ArrayList<>()); + private InventoryUtils invUtils = new InventoryUtils(); + + public Properties get(String hostname, int portNumber) { + return invUtils.getProperties(hostname, portNumber); + } + + public void add(String hostname, Properties systemProps) { + Properties props = new Properties(); + props.setProperty("os.name", systemProps.getProperty("os.name")); + props.setProperty("user.name", systemProps.getProperty("user.name")); + + SystemData host = new SystemData(hostname, props); + if (!systems.contains(host)) + systems.add(host); + } + + public InventoryList list() { + return new InventoryList(systems); + } + +} +// end::manager[] diff --git a/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryResource.java b/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryResource.java new file mode 100644 index 00000000..8eabe508 --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryResource.java @@ -0,0 +1,81 @@ +// tag::copyright[] +/******************************************************************************* + * Copyright (c) 2017 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 implementation + *******************************************************************************/ +// end::copyright[] + +// tag::InventoryResource[] +package io.openliberty.guides.inventory; + +import java.util.Properties; +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import io.openliberty.guides.inventory.InventoryConfig; + +@RequestScoped +@Path("systems") +public class InventoryResource { + + @Inject + InventoryManager manager; + + // tag::config-injection[] + @Inject + InventoryConfig inventoryConfig; + // end::config-injection[] + + @GET + @Path("{hostname}") + @Produces(MediaType.APPLICATION_JSON) + public Response getPropertiesForHost(@PathParam("hostname") String hostname) { + + if (!inventoryConfig.isInMaintenance()) { + // Get properties + // tag::config-port[] + Properties props = manager.get(hostname, inventoryConfig.getPortNumber()); + // end::config-port[] + if (props == null) { + return Response.status(Response.Status.NOT_FOUND) + .entity( + "ERROR: Unknown hostname or the resource may not be running on the host machine") + .build(); + } + + // Add to inventory + manager.add(hostname, props); + return Response.ok(props).build(); + } else { + // tag::email[] + return Response.status(Response.Status.SERVICE_UNAVAILABLE) + .entity("ERROR: Service is currently in maintenance.").build(); + // end::email[] + } + } + + @GET + @Produces(MediaType.APPLICATION_JSON) + public Response listContents() { + if (!inventoryConfig.isInMaintenance()) { + return Response.ok(manager.list()).build(); + } else { + return Response.status(Response.Status.SERVICE_UNAVAILABLE) + .entity("ERROR: Service is currently in maintenance.").build(); + } + } + +} + +// end::InventoryResource[] diff --git a/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryUtils.java b/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryUtils.java new file mode 100644 index 00000000..fb1bdb93 --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryUtils.java @@ -0,0 +1,87 @@ +// tag::copyright[] +/******************************************************************************* + * Copyright (c) 2017, 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 implementation + *******************************************************************************/ +// end::copyright[] +package io.openliberty.guides.inventory; + +import java.net.URL; +import java.net.URI; +import java.net.UnknownHostException; +import java.net.MalformedURLException; +import javax.ws.rs.ProcessingException; +import java.util.Properties; +import org.apache.commons.lang3.exception.ExceptionUtils; +import org.eclipse.microprofile.rest.client.RestClientBuilder; +import io.openliberty.guides.inventory.client.SystemClient; +import io.openliberty.guides.inventory.client.UnknownUrlException; +import io.openliberty.guides.inventory.client.UnknownUrlExceptionMapper; + +public class InventoryUtils { + + // tag::builder[] + public Properties getProperties(String hostname, int portNumber) { + String customURLString = "http://" + hostname + ":" + portNumber + "/system"; + URL customURL = null; + try { + customURL = new URL(customURLString); + SystemClient customRestClient = RestClientBuilder.newBuilder() + .baseUrl(customURL) + .register( + UnknownUrlExceptionMapper.class) + .build(SystemClient.class); + return customRestClient.getProperties(); + } catch (ProcessingException ex) { + handleProcessingException(ex); + } catch (UnknownUrlException e) { + System.err.println("The given URL is unreachable."); + } catch (MalformedURLException e) { + System.err.println("The given URL is not formatted correctly."); + } + return null; + } + // end::builder[] + + public void handleProcessingException(ProcessingException ex) { + Throwable rootEx = ExceptionUtils.getRootCause(ex); + if (rootEx != null && rootEx instanceof UnknownHostException) { + System.err.println("The specified host is unknown."); + } else { + throw ex; + } + } + + // tag::doc[] + /** + * Builds the URI string to the system service for a particular host. + * + * @param protocol + * - http or https. + * @param host + * - name of host. + * @param port + * - port number. + * @param path + * - Note that the path needs to start with a slash!!! + * @return String representation of the URI to the system properties service. + */ + // end::doc[] + public static String buildUrl(String protocol, String host, int port, + String path) { + try { + URI uri = new URI(protocol, null, host, port, path, null, null); + return uri.toString(); + } catch (Exception e) { + System.out.println("URISyntaxException"); + return null; + } + } + +} \ No newline at end of file diff --git a/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/client/SystemClient.java b/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/client/SystemClient.java new file mode 100644 index 00000000..173ff3ad --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/client/SystemClient.java @@ -0,0 +1,37 @@ +// tag::copyright[] +/******************************************************************************* + * Copyright (c) 2017, 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 implementation + *******************************************************************************/ +// end::copyright[] +// tag::client[] +package io.openliberty.guides.inventory.client; + +import java.util.Properties; +import javax.enterprise.context.Dependent; +import javax.ws.rs.ProcessingException; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import org.eclipse.microprofile.rest.client.annotation.RegisterProvider; +import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; + +// tag::annotations[] +@Dependent +@RegisterRestClient +@RegisterProvider(UnknownUrlExceptionMapper.class) +@Path("/properties") +public interface SystemClient { + // end::annotations[] + @GET + @Produces(MediaType.APPLICATION_JSON) + public Properties getProperties() throws UnknownUrlException, ProcessingException; +} +// end::client[] diff --git a/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/client/UnknownUrlException.java b/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/client/UnknownUrlException.java new file mode 100644 index 00000000..45e740b6 --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/client/UnknownUrlException.java @@ -0,0 +1,28 @@ +// tag::copyright[] +/******************************************************************************* + * Copyright (c) 2017, 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 implementation + *******************************************************************************/ +// end::copyright[] +// tag::exception[] +package io.openliberty.guides.inventory.client; + +public class UnknownUrlException extends Exception { + + private static final long serialVersionUID = 1L; + + public UnknownUrlException() { + super(); + } + + public UnknownUrlException(String message) { + super(message); + } +} +// end::exception[] diff --git a/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/client/UnknownUrlExceptionMapper.java b/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/client/UnknownUrlExceptionMapper.java new file mode 100644 index 00000000..a7eb66ae --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/client/UnknownUrlExceptionMapper.java @@ -0,0 +1,38 @@ +// tag::copyright[] +/******************************************************************************* + * Copyright (c) 2017, 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 implementation + *******************************************************************************/ +// end::copyright[] +// tag::mapper[] +package io.openliberty.guides.inventory.client; + +import java.util.logging.Logger; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.Response; +import javax.ws.rs.ext.Provider; +import org.eclipse.microprofile.rest.client.ext.ResponseExceptionMapper; + +@Provider +public class UnknownUrlExceptionMapper + implements ResponseExceptionMapper { + Logger LOG = Logger.getLogger(UnknownUrlExceptionMapper.class.getName()); + + @Override + public boolean handles(int status, MultivaluedMap headers) { + LOG.info("status = " + status); + return status == 404; + } + + @Override + public UnknownUrlException toThrowable(Response response) { + return new UnknownUrlException(); + } +} +// end::mapper[] diff --git a/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/model/InventoryList.java b/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/model/InventoryList.java new file mode 100644 index 00000000..2a562109 --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/model/InventoryList.java @@ -0,0 +1,32 @@ +// tag::copyright[] +/******************************************************************************* + * Copyright (c) 2017, 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 implementation + *******************************************************************************/ +// end::copyright[] +package io.openliberty.guides.inventory.model; + +import java.util.List; + +public class InventoryList { + + private List systems; + + public InventoryList(List systems) { + this.systems = systems; + } + + public List getSystems() { + return systems; + } + + public int getTotal() { + return systems.size(); + } +} diff --git a/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/model/SystemData.java b/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/model/SystemData.java new file mode 100644 index 00000000..84b37f30 --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/model/SystemData.java @@ -0,0 +1,44 @@ +// tag::copyright[] +/******************************************************************************* + * Copyright (c) 2017, 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 implementation + *******************************************************************************/ +// end::copyright[] +package io.openliberty.guides.inventory.model; + +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +public class SystemData { + + private final String hostname; + private final Properties properties; + + public SystemData(String hostname, Properties properties) { + this.hostname = hostname; + this.properties = properties; + } + + public String getHostname() { + return hostname; + } + + public Properties getProperties() { + return properties; + } + + @Override + public boolean equals(Object host) { + if (host instanceof SystemData) { + return hostname.equals(((SystemData) host).getHostname()); + } + return false; + } +} diff --git a/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/system/SystemApplication.java b/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/system/SystemApplication.java new file mode 100644 index 00000000..e36ae744 --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/system/SystemApplication.java @@ -0,0 +1,21 @@ +// tag::copyright[] +/******************************************************************************* + * Copyright (c) 2017 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 implementation + *******************************************************************************/ +// end::copyright[] +package io.openliberty.guides.system; + +import javax.ws.rs.core.Application; +import javax.ws.rs.ApplicationPath; + +@ApplicationPath("system") +public class SystemApplication extends Application { + +} diff --git a/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/system/SystemHealth.java b/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/system/SystemHealth.java new file mode 100644 index 00000000..cc5b0c23 --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/system/SystemHealth.java @@ -0,0 +1,35 @@ +// tag::comment[] +/******************************************************************************* + * 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 implementation + *******************************************************************************/ +// end::comment[] +// tag::SystemHealth[] +package io.openliberty.guides.system; + +import javax.enterprise.context.ApplicationScoped; +import org.eclipse.microprofile.health.Health; +import org.eclipse.microprofile.health.HealthCheck; +import org.eclipse.microprofile.health.HealthCheckResponse; + +@Health +@ApplicationScoped +public class SystemHealth implements HealthCheck { + @Override + public HealthCheckResponse call() { + if (!System.getProperty("wlp.server.name").equals("BoostServer")) { + return HealthCheckResponse.named(SystemResource.class.getSimpleName()) + .withData("default server", "not available").down() + .build(); + } + return HealthCheckResponse.named(SystemResource.class.getSimpleName()) + .withData("default server", "available").up().build(); + } +} +// end::SystemHealth[] diff --git a/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/system/SystemResource.java b/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/system/SystemResource.java new file mode 100644 index 00000000..59d74eb8 --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/java/io/openliberty/guides/system/SystemResource.java @@ -0,0 +1,31 @@ +// tag::copyright[] +/******************************************************************************* + * Copyright (c) 2017, 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 implementation + *******************************************************************************/ +// end::copyright[] +package io.openliberty.guides.system; + +import javax.enterprise.context.RequestScoped; +import javax.ws.rs.GET; +import javax.ws.rs.core.Response; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +@RequestScoped +@Path("properties") +public class SystemResource { + + @GET + @Produces(MediaType.APPLICATION_JSON) + public Response getProperties() { + return Response.ok(System.getProperties()).build(); + } +} diff --git a/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/resources/CustomConfigSource.json b/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/resources/CustomConfigSource.json new file mode 100644 index 00000000..0c2ee17c --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/resources/CustomConfigSource.json @@ -0,0 +1,4 @@ +{ + "config_ordinal":700, + "io_openliberty_guides_inventory_inMaintenance":false +} diff --git a/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/resources/META-INF/microprofile-config.properties b/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/resources/META-INF/microprofile-config.properties new file mode 100644 index 00000000..b1b24d26 --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/resources/META-INF/microprofile-config.properties @@ -0,0 +1,11 @@ +# tag::all-props[] +# tag::ordinal[] +config_ordinal=100 +# end::ordinal[] +# tag::inventory-port-number[] +io_openliberty_guides_port_number=9080 +# end::inventory-port-number[] +# tag::inventory-in-maintenance[] +io_openliberty_guides_inventory_inMaintenance=false +# end::inventory-in-maintenance[] +# end::all-props[] diff --git a/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource b/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource new file mode 100644 index 00000000..2b7d054c --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource @@ -0,0 +1,3 @@ +# tag::register[] +io.openliberty.guides.config.CustomConfigSource +# end::register[] diff --git a/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/webapp/WEB-INF/web.xml b/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 00000000..a3823f10 --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,10 @@ + + + Liberty Project + + + index.html + + \ No newline at end of file diff --git a/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/webapp/index.html b/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/webapp/index.html new file mode 100644 index 00000000..74ec6c74 --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/main/webapp/index.html @@ -0,0 +1,78 @@ + + + +

Welcome to your Liberty Application

+

Thanks for generating this project using the app accelerator. Please see below for some extra information on each of the technologies you chose

+ +
+

REST

+

+ For the complete feature documentation, see the jaxrs-2.0 + feature description in IBM Knowledge Center. +

+
+ +
+

MicroProfile

+

+ The MicroProfile project is an open + community with the aim of optimizing Enterprise Java for a microservices + architecture. MicroProfile will be evolving with guidance from the community. +

+

+ For the complete feature documentation, see the + microProfile-1.0 + feature description in IBM Knowledge Center. +

+

+ If you want to share your thoughts you can post straight to the + MicroProfile Google group. +

+
+
+
+ + diff --git a/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/test/java/it/io/openliberty/guides/health/HealthTestIT.java b/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/test/java/it/io/openliberty/guides/health/HealthTestIT.java new file mode 100644 index 00000000..1656bc0c --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/test/java/it/io/openliberty/guides/health/HealthTestIT.java @@ -0,0 +1,69 @@ +// tag::comment[] +/******************************************************************************* + * 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 implementation + *******************************************************************************/ +// end::comment[] +// tag::HealthTest[] +package it.io.openliberty.guides.health; + +import static org.junit.Assert.assertEquals; +import java.util.HashMap; +import javax.json.JsonArray; +import org.junit.After; +import org.junit.Test; + +public class HealthTestIT { + + private JsonArray servicesStates; + private static HashMap dataWhenServicesUP; + private static HashMap dataWhenInventoryDown; + + static { + dataWhenServicesUP = new HashMap(); + dataWhenInventoryDown = new HashMap(); + + dataWhenServicesUP.put("SystemResource", "UP"); + dataWhenServicesUP.put("InventoryResource", "UP"); + + dataWhenInventoryDown.put("SystemResource", "UP"); + dataWhenInventoryDown.put("InventoryResource", "DOWN"); + } + + @Test + public void testIfServicesAreUp() { + servicesStates = HealthTestUtil.connectToHealthEnpoint(200); + checkStates(dataWhenServicesUP, servicesStates); + } + + @Test + public void testIfInventoryServiceIsDown() { + servicesStates = HealthTestUtil.connectToHealthEnpoint(200); + checkStates(dataWhenServicesUP, servicesStates); + HealthTestUtil.changeInventoryProperty(HealthTestUtil.INV_MAINTENANCE_FALSE, + HealthTestUtil.INV_MAINTENANCE_TRUE); + servicesStates = HealthTestUtil.connectToHealthEnpoint(503); + checkStates(dataWhenInventoryDown, servicesStates); + } + + private void checkStates(HashMap testData, JsonArray servStates) { + testData.forEach((service, expectedState) -> { + assertEquals("The state of " + service + " service is not matching.", + expectedState, + HealthTestUtil.getActualState(service, servStates)); + }); + } + + @After + public void teardown() { + HealthTestUtil.cleanUp(); + } + +} +// end::HealthTest[] diff --git a/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/test/java/it/io/openliberty/guides/health/HealthTestUtil.java b/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/test/java/it/io/openliberty/guides/health/HealthTestUtil.java new file mode 100644 index 00000000..ab566809 --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/it/test-mpHealth-1.0/src/test/java/it/io/openliberty/guides/health/HealthTestUtil.java @@ -0,0 +1,97 @@ +// tag::comment[] +/******************************************************************************* + * 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 implementation + *******************************************************************************/ +// end::comment[] +// tag::HealthTestUtil[] +package it.io.openliberty.guides.health; + +import static org.junit.Assert.assertEquals; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; + +import javax.json.JsonArray; +import javax.json.JsonObject; +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.core.Response; + +import org.apache.cxf.jaxrs.provider.jsrjsonp.JsrJsonpProvider; + +public class HealthTestUtil { + + private static String port; + private static String baseUrl; + private final static String HEALTH_ENDPOINT = "health"; + public static final String INV_MAINTENANCE_FALSE = "io_openliberty_guides_inventory_inMaintenance\":false"; + public static final String INV_MAINTENANCE_TRUE = "io_openliberty_guides_inventory_inMaintenance\":true"; + + static { + //port = System.getProperty("liberty.test.port"); + port = "9080"; + baseUrl = "http://localhost:" + port + "/"; + } + + public static JsonArray connectToHealthEnpoint(int expectedResponseCode) { + String healthURL = baseUrl + HEALTH_ENDPOINT; + Client client = ClientBuilder.newClient().register(JsrJsonpProvider.class); + Response response = client.target(healthURL).request().get(); + assertEquals("Response code is not matching " + healthURL, + expectedResponseCode, response.getStatus()); + JsonArray servicesStates = response.readEntity(JsonObject.class) + .getJsonArray("checks"); + response.close(); + client.close(); + return servicesStates; + } + + public static String getActualState(String service, + JsonArray servicesStates) { + String state = ""; + for (Object obj : servicesStates) { + if (obj instanceof JsonObject) { + if (service.equals(((JsonObject) obj).getString("name"))) { + state = ((JsonObject) obj).getString("state"); + } + } + } + return state; + } + + public static void changeInventoryProperty(String oldValue, String newValue) { + try { + String fileName = System.getProperty("user.dir").split("target")[0] + + "target/it/test-mpHealth-1.0/src/main/resources/CustomConfigSource.json"; + BufferedReader reader = new BufferedReader(new FileReader(new File(fileName))); + String line = ""; + String oldContent = "", newContent = ""; + while ((line = reader.readLine()) != null) { + oldContent += line + "\r\n"; + } + reader.close(); + newContent = oldContent.replaceAll(oldValue, newValue); + FileWriter writer = new FileWriter(fileName); + writer.write(newContent); + writer.close(); + Thread.sleep(600); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static void cleanUp() { + changeInventoryProperty(INV_MAINTENANCE_TRUE, INV_MAINTENANCE_FALSE); + } + +} +// end::HealthTestUtil[] From 9a1754512370dd8ad1b8298d8c038eb62971f4a9 Mon Sep 17 00:00:00 2001 From: Andrew Mauer Date: Thu, 3 Jan 2019 16:03:36 -0500 Subject: [PATCH 2/6] re-factor of the booster config based on comments --- .../common/config/BoosterDependencyInfo.java | 27 ++++++++ .../config/BoosterPackConfigurator.java | 33 +++++----- .../config/CDIBoosterPackConfigurator.java | 35 ++++------- .../boost/common/config/ConfigConstants.java | 1 + .../config/JAXRSBoosterPackConfigurator.java | 41 +++++------- .../config/JDBCBoosterPackConfigurator.java | 39 +++++------- .../config/JSONPBoosterPackConfigurator.java | 38 ++++------- .../config/LibertyServerConfigGenerator.java | 5 +- .../MPConfigBoosterPackConfigurator.java | 36 ++++------- .../MPHealthBoosterPackConfigurator.java | 36 ++++------- .../MPOpenTracingBoosterPackConfigurator.java | 38 ++++------- .../MPRestClientBoosterPackConfigurator.java | 36 ++++------- .../common/utils/LibertyBoosterUtil.java | 63 ++++++++++--------- .../maven/liberty/LibertyPackageMojo.java | 5 +- .../boost/maven/utils/MavenProjectUtil.java | 10 ++- 15 files changed, 189 insertions(+), 254 deletions(-) create mode 100644 boost-common/src/main/java/io/openliberty/boost/common/config/BoosterDependencyInfo.java diff --git a/boost-common/src/main/java/io/openliberty/boost/common/config/BoosterDependencyInfo.java b/boost-common/src/main/java/io/openliberty/boost/common/config/BoosterDependencyInfo.java new file mode 100644 index 00000000..5b5f1f26 --- /dev/null +++ b/boost-common/src/main/java/io/openliberty/boost/common/config/BoosterDependencyInfo.java @@ -0,0 +1,27 @@ +package io.openliberty.boost.common.config; + +public class BoosterDependencyInfo { + + protected String group; + protected String artifact; + protected String version; + + public BoosterDependencyInfo(String grp, String artf, String ver ) { + + this.group = grp; + this.artifact = artf; + this.version = ver; + } + + public String getGroup(){ + return group; + } + + public String getArtifact(){ + return artifact; + } + + public String getVersion(){ + return version; + } +} diff --git a/boost-common/src/main/java/io/openliberty/boost/common/config/BoosterPackConfigurator.java b/boost-common/src/main/java/io/openliberty/boost/common/config/BoosterPackConfigurator.java index 9a6138b6..f48b0af6 100644 --- a/boost-common/src/main/java/io/openliberty/boost/common/config/BoosterPackConfigurator.java +++ b/boost-common/src/main/java/io/openliberty/boost/common/config/BoosterPackConfigurator.java @@ -22,18 +22,19 @@ * */ public abstract class BoosterPackConfigurator { - - protected String EE_7_VERSION = "0.1-SNAPSHOT"; + + protected BoosterDependencyInfo dependencyInfo; + protected LibertyServerConfigGenerator serverXML; + + 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(); - + + public BoosterPackConfigurator(BoosterDependencyInfo depInfo, LibertyServerConfigGenerator srvrXML){ + dependencyInfo = depInfo; + serverXML = srvrXML; + } + /** * method to write out the default config for a particular feature into * server.xml @@ -42,18 +43,12 @@ public abstract class BoosterPackConfigurator { */ public abstract void addServerConfig(Document doc); - /** - * Set the Liberty feature based on the booster dependency version - * - * @param version - */ - public abstract void setFeature(String version); - /** * Return the artifactId of the dependency jar to copy to the server * * @return */ - public abstract String getDependencyToCopy(); - + public String getDependencyToCopy(){ + return null; + } } diff --git a/boost-common/src/main/java/io/openliberty/boost/common/config/CDIBoosterPackConfigurator.java b/boost-common/src/main/java/io/openliberty/boost/common/config/CDIBoosterPackConfigurator.java index 6093a906..e3a218a6 100644 --- a/boost-common/src/main/java/io/openliberty/boost/common/config/CDIBoosterPackConfigurator.java +++ b/boost-common/src/main/java/io/openliberty/boost/common/config/CDIBoosterPackConfigurator.java @@ -16,29 +16,16 @@ public class CDIBoosterPackConfigurator extends BoosterPackConfigurator { - String libertyFeature = null; + public CDIBoosterPackConfigurator(BoosterDependencyInfo depInfo, LibertyServerConfigGenerator srvrXML) { + super(depInfo, srvrXML); + // TODO Auto-generated constructor stub + } + + public void addServerConfig(Document doc) { + // write out the feature Manager stanza + if (dependencyInfo.getVersion().equals(MP_20_VERSION)) { + serverXML.addFeature(CDI_20); + } + } - @Override - public void setFeature(String version) { - // if it is the 1.0 version = EE7 feature level - if (version.equals(MP_20_VERSION)) { - libertyFeature = CDI_20; - } - } - - @Override - public String getFeature() { - return libertyFeature; - } - - @Override - public void addServerConfig(Document doc) { - // No config to write - - } - - @Override - public String getDependencyToCopy() { - return null; - } } diff --git a/boost-common/src/main/java/io/openliberty/boost/common/config/ConfigConstants.java b/boost-common/src/main/java/io/openliberty/boost/common/config/ConfigConstants.java index 6a710f6b..e39cd253 100644 --- a/boost-common/src/main/java/io/openliberty/boost/common/config/ConfigConstants.java +++ b/boost-common/src/main/java/io/openliberty/boost/common/config/ConfigConstants.java @@ -69,6 +69,7 @@ public interface ConfigConstants { public String MPRESTCLIENT_11 = "mpRestClient-1.1"; public String JSONP_11 = "jsonp-1.1"; public String MPCONFIG_13 = "mpConfig-1.3"; + public String MPOPENTRACING_10 = "mpOpenTracing-1.0"; public String SHARED_RESOURCES_DIR = "${shared.resource.dir}"; public String SERVER_OUTPUT_DIR = "${server.output.dir}"; diff --git a/boost-common/src/main/java/io/openliberty/boost/common/config/JAXRSBoosterPackConfigurator.java b/boost-common/src/main/java/io/openliberty/boost/common/config/JAXRSBoosterPackConfigurator.java index d82382a3..529ed7ca 100644 --- a/boost-common/src/main/java/io/openliberty/boost/common/config/JAXRSBoosterPackConfigurator.java +++ b/boost-common/src/main/java/io/openliberty/boost/common/config/JAXRSBoosterPackConfigurator.java @@ -10,39 +10,28 @@ *******************************************************************************/ package io.openliberty.boost.common.config; -import org.w3c.dom.Document; import io.openliberty.boost.common.config.BoosterPackConfigurator; import static io.openliberty.boost.common.config.ConfigConstants.*; -import java.util.Map; +import org.w3c.dom.Document; public class JAXRSBoosterPackConfigurator extends BoosterPackConfigurator { + + public JAXRSBoosterPackConfigurator(BoosterDependencyInfo depInfo, LibertyServerConfigGenerator srvrXML) { + super(depInfo, srvrXML); + // TODO Auto-generated constructor stub + } - String libertyFeature = null; - - @Override - public void setFeature(String version) { - // if it is the 1.0 version = EE7 feature level - if (version.equals(EE_7_VERSION)) { - libertyFeature = JAXRS_20; - } else if (version.equals(EE_8_VERSION)) { - libertyFeature = JAXRS_21; - } - } - - @Override - public String getFeature() { - return libertyFeature; - } - - @Override + @Override public void addServerConfig(Document doc) { - // No config to write - + // write out the feature Manager stanza + if (dependencyInfo.getVersion().equals(EE_7_VERSION)) { + serverXML.addFeature(JAXRS_20); + } else if (dependencyInfo.getVersion().equals(EE_8_VERSION)) { + serverXML.addFeature(JAXRS_20); + } + + // no further config needed for jaxrs } - @Override - public String getDependencyToCopy() { - return null; - } } diff --git a/boost-common/src/main/java/io/openliberty/boost/common/config/JDBCBoosterPackConfigurator.java b/boost-common/src/main/java/io/openliberty/boost/common/config/JDBCBoosterPackConfigurator.java index 5890d9c9..f76dd169 100644 --- a/boost-common/src/main/java/io/openliberty/boost/common/config/JDBCBoosterPackConfigurator.java +++ b/boost-common/src/main/java/io/openliberty/boost/common/config/JDBCBoosterPackConfigurator.java @@ -14,8 +14,6 @@ import static io.openliberty.boost.common.config.ConfigConstants.*; -import java.util.HashMap; -import java.util.Map; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -23,27 +21,33 @@ public class JDBCBoosterPackConfigurator extends BoosterPackConfigurator { - /** + public JDBCBoosterPackConfigurator(BoosterDependencyInfo depInfo, LibertyServerConfigGenerator srvrXML) { + super(depInfo, srvrXML); + // TODO Auto-generated constructor stub + } + + /** * The artifactId of the dependency for this booster that needs to be copied * to the server */ private final String DEPENDENCY_ARTIFACT = "org.apache.derby:derby:10.14.2.0"; - String libertyFeature = null; - - /** - * retrieves the default boost feature string for the jdbc dependency - */ - public String getFeature() { - return libertyFeature; - } - /** * writes out jdbc default config data when selected by the presence of a * jdbc boost dependency */ + @Override public void addServerConfig(Document doc) { + + // write out the feature Manager stanza + if (dependencyInfo.getVersion().equals(EE_7_VERSION)) { + serverXML.addFeature(JDBC_41); + } else if (dependencyInfo.getVersion().equals(EE_8_VERSION)) { + serverXML.addFeature(JDBC_42); + } + //write out config stanzas + Element serverRoot = doc.getDocumentElement(); // Find the root server element @@ -81,17 +85,6 @@ public void addServerConfig(Document doc) { serverRoot.appendChild(jdbcDriver); } - @Override - public void setFeature(String version) { - - if (version.equals(EE_7_VERSION)) { - libertyFeature = JDBC_41; - } else if (version.equals(EE_8_VERSION)) { - libertyFeature = JDBC_42; - } - - } - @Override public String getDependencyToCopy() { diff --git a/boost-common/src/main/java/io/openliberty/boost/common/config/JSONPBoosterPackConfigurator.java b/boost-common/src/main/java/io/openliberty/boost/common/config/JSONPBoosterPackConfigurator.java index 69e0c60e..2161d95f 100644 --- a/boost-common/src/main/java/io/openliberty/boost/common/config/JSONPBoosterPackConfigurator.java +++ b/boost-common/src/main/java/io/openliberty/boost/common/config/JSONPBoosterPackConfigurator.java @@ -15,30 +15,16 @@ import org.w3c.dom.Document; public class JSONPBoosterPackConfigurator extends BoosterPackConfigurator { - - String libertyFeature = null; - - @Override - public void setFeature(String version) { - // if it is the 1.0 version = EE7 feature level - if (version.equals(MP_20_VERSION)) { - libertyFeature = JSONP_11; - } - } - - @Override - public String getFeature() { - return libertyFeature; - } - - @Override - public void addServerConfig(Document doc) { - // No config to write - - } - - @Override - public String getDependencyToCopy() { - return null; - } + + public JSONPBoosterPackConfigurator(BoosterDependencyInfo depInfo, LibertyServerConfigGenerator srvrXML) { + super(depInfo, srvrXML); + // TODO Auto-generated constructor stub + } + + public void addServerConfig(Document doc) { + // write out the feature Manager stanza + if (dependencyInfo.getVersion().equals(MP_20_VERSION)) { + serverXML.addFeature(JSONP_11); + } + } } \ No newline at end of file diff --git a/boost-common/src/main/java/io/openliberty/boost/common/config/LibertyServerConfigGenerator.java b/boost-common/src/main/java/io/openliberty/boost/common/config/LibertyServerConfigGenerator.java index 2cce773d..d041b991 100644 --- a/boost-common/src/main/java/io/openliberty/boost/common/config/LibertyServerConfigGenerator.java +++ b/boost-common/src/main/java/io/openliberty/boost/common/config/LibertyServerConfigGenerator.java @@ -144,6 +144,9 @@ public void addKeystore(Map keystoreProps, Map k * The full name of the Liberty feature to add. */ public void addFeature(String featureName) { + + System.out.println("AJM: in LSCUtil - feature to be added: " + featureName); + if (!featuresAdded.contains(featureName)) { Element feature = doc.createElement(FEATURE); feature.appendChild(doc.createTextNode(featureName)); @@ -209,7 +212,7 @@ public void addBootstrapProperties(Properties properties) throws IOException { } public void addBoosterConfig(BoosterPackConfigurator configurator) { - configurator.addServerConfig(getServerDoc()); + configurator.addServerConfig(getServerDoc()); } public void addApplication(String appName) { diff --git a/boost-common/src/main/java/io/openliberty/boost/common/config/MPConfigBoosterPackConfigurator.java b/boost-common/src/main/java/io/openliberty/boost/common/config/MPConfigBoosterPackConfigurator.java index e1253db6..24488755 100644 --- a/boost-common/src/main/java/io/openliberty/boost/common/config/MPConfigBoosterPackConfigurator.java +++ b/boost-common/src/main/java/io/openliberty/boost/common/config/MPConfigBoosterPackConfigurator.java @@ -16,29 +16,15 @@ public class MPConfigBoosterPackConfigurator extends BoosterPackConfigurator { - String libertyFeature = null; - - @Override - public void setFeature(String version) { - // if it is the 1.0 version = EE7 feature level - if (version.equals(MP_20_VERSION)) { - libertyFeature = MPCONFIG_13; - } - } - - @Override - public String getFeature() { - return libertyFeature; - } - - @Override - public void addServerConfig(Document doc) { - // No config to write - - } - - @Override - public String getDependencyToCopy() { - return null; - } + public MPConfigBoosterPackConfigurator(BoosterDependencyInfo depInfo, LibertyServerConfigGenerator srvrXML) { + super(depInfo, srvrXML); + // TODO Auto-generated constructor stub + } + + public void addServerConfig(Document doc) { + // write out the feature Manager stanza + if (dependencyInfo.getVersion().equals(MP_20_VERSION)) { + serverXML.addFeature(MPCONFIG_13); + } + } } diff --git a/boost-common/src/main/java/io/openliberty/boost/common/config/MPHealthBoosterPackConfigurator.java b/boost-common/src/main/java/io/openliberty/boost/common/config/MPHealthBoosterPackConfigurator.java index ea29d83c..a5214d73 100644 --- a/boost-common/src/main/java/io/openliberty/boost/common/config/MPHealthBoosterPackConfigurator.java +++ b/boost-common/src/main/java/io/openliberty/boost/common/config/MPHealthBoosterPackConfigurator.java @@ -16,29 +16,15 @@ public class MPHealthBoosterPackConfigurator extends BoosterPackConfigurator { - String libertyFeature = null; - - @Override - public void setFeature(String version) { - // if it is the 2.0 version = MP2.0 feature level - if (version.equals(MP_20_VERSION)) { - libertyFeature = MPHEALTH_10; - } - } - - @Override - public String getFeature() { - return libertyFeature; - } - - @Override - public void addServerConfig(Document doc) { - // No config to write - - } - - @Override - public String getDependencyToCopy() { - return null; - } + public MPHealthBoosterPackConfigurator(BoosterDependencyInfo depInfo, LibertyServerConfigGenerator srvrXML) { + super(depInfo, srvrXML); + // TODO Auto-generated constructor stub + } + + public void addServerConfig(Document doc) { + // write out the feature Manager stanza + if (dependencyInfo.getVersion().equals(MP_20_VERSION)) { + serverXML.addFeature(MPHEALTH_10); + } + } } diff --git a/boost-common/src/main/java/io/openliberty/boost/common/config/MPOpenTracingBoosterPackConfigurator.java b/boost-common/src/main/java/io/openliberty/boost/common/config/MPOpenTracingBoosterPackConfigurator.java index a5ce134c..de0c2577 100644 --- a/boost-common/src/main/java/io/openliberty/boost/common/config/MPOpenTracingBoosterPackConfigurator.java +++ b/boost-common/src/main/java/io/openliberty/boost/common/config/MPOpenTracingBoosterPackConfigurator.java @@ -10,35 +10,21 @@ *******************************************************************************/ package io.openliberty.boost.common.config; -import static io.openliberty.boost.common.config.ConfigConstants.MPHEALTH_10; +import static io.openliberty.boost.common.config.ConfigConstants.MPOPENTRACING_10; import org.w3c.dom.Document; public class MPOpenTracingBoosterPackConfigurator extends BoosterPackConfigurator { - String libertyFeature = null; - - @Override - public void setFeature(String version) { - // if it is the 1.0 version = EE7 feature level - if (version.equals(MP_20_VERSION)) { - libertyFeature = MPHEALTH_10; - } - } - - @Override - public String getFeature() { - return libertyFeature; - } - - @Override - public void addServerConfig(Document doc) { - // No config to write - - } - - @Override - public String getDependencyToCopy() { - return null; - } + public MPOpenTracingBoosterPackConfigurator(BoosterDependencyInfo depInfo, LibertyServerConfigGenerator srvrXML) { + super(depInfo, srvrXML); + // TODO Auto-generated constructor stub + } + + public void addServerConfig(Document doc) { + // write out the feature Manager stanza + if (dependencyInfo.getVersion().equals(MP_20_VERSION)) { + serverXML.addFeature(MPOPENTRACING_10); + } + } } diff --git a/boost-common/src/main/java/io/openliberty/boost/common/config/MPRestClientBoosterPackConfigurator.java b/boost-common/src/main/java/io/openliberty/boost/common/config/MPRestClientBoosterPackConfigurator.java index 69d7726a..cbda9e55 100644 --- a/boost-common/src/main/java/io/openliberty/boost/common/config/MPRestClientBoosterPackConfigurator.java +++ b/boost-common/src/main/java/io/openliberty/boost/common/config/MPRestClientBoosterPackConfigurator.java @@ -16,29 +16,15 @@ public class MPRestClientBoosterPackConfigurator extends BoosterPackConfigurator { - String libertyFeature = null; - - @Override - public void setFeature(String version) { - // if it is the 1.0 version = EE7 feature level - if (version.equals(MP_20_VERSION)) { - libertyFeature = MPRESTCLIENT_11; - } - } - - @Override - public String getFeature() { - return libertyFeature; - } - - @Override - public void addServerConfig(Document doc) { - // No config to write - - } - - @Override - public String getDependencyToCopy() { - return null; - } + public MPRestClientBoosterPackConfigurator(BoosterDependencyInfo depInfo, LibertyServerConfigGenerator srvrXML) { + super(depInfo, srvrXML); + // TODO Auto-generated constructor stub + } + + public void addServerConfig(Document doc) { + // write out the feature Manager stanza + if (dependencyInfo.getVersion().equals(MP_20_VERSION)) { + serverXML.addFeature(MPRESTCLIENT_11); + } + } } diff --git a/boost-common/src/main/java/io/openliberty/boost/common/utils/LibertyBoosterUtil.java b/boost-common/src/main/java/io/openliberty/boost/common/utils/LibertyBoosterUtil.java index c436a9ca..47844df7 100644 --- a/boost-common/src/main/java/io/openliberty/boost/common/utils/LibertyBoosterUtil.java +++ b/boost-common/src/main/java/io/openliberty/boost/common/utils/LibertyBoosterUtil.java @@ -14,7 +14,10 @@ import java.util.List; import java.util.Map; +import javax.xml.parsers.ParserConfigurationException; + import io.openliberty.boost.common.BoostLoggerI; +import io.openliberty.boost.common.config.BoosterDependencyInfo; import io.openliberty.boost.common.config.BoosterPackConfigurator; import io.openliberty.boost.common.config.CDIBoosterPackConfigurator; import io.openliberty.boost.common.config.JAXRSBoosterPackConfigurator; @@ -42,12 +45,21 @@ public class LibertyBoosterUtil { protected String libertyServerPath; protected List boosterPackConfigurators; protected BoostLoggerI logger; + protected LibertyServerConfigGenerator serverConfig; - public LibertyBoosterUtil(String libertyServerPath, Map dependencies, BoostLoggerI logger) { + public LibertyBoosterUtil(String libertyServerPath, List dependencies, BoostLoggerI logger) { this.libertyServerPath = libertyServerPath; this.logger = logger; + try { + this.serverConfig = new LibertyServerConfigGenerator(libertyServerPath); + } catch (ParserConfigurationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + this.boosterPackConfigurators = getBoosterPackConfigurators(dependencies); + } /** @@ -58,43 +70,35 @@ public LibertyBoosterUtil(String libertyServerPath, Map dependen * @param dependencies * @return */ - private List getBoosterPackConfigurators(Map dependencies) { + private List getBoosterPackConfigurators(List dependencies) { List boosterPackConfigList = new ArrayList(); - for (String dep : dependencies.keySet()) { - if (dep.equals(BOOSTER_JDBC)) { - JDBCBoosterPackConfigurator jdbcConfig = new JDBCBoosterPackConfigurator(); - jdbcConfig.setFeature(dependencies.get(dep)); + for (BoosterDependencyInfo dep : dependencies) { + if (dep.getArtifact().equals(BOOSTER_JDBC)) { + JDBCBoosterPackConfigurator jdbcConfig = new JDBCBoosterPackConfigurator(dep, serverConfig); boosterPackConfigList.add(jdbcConfig); - } else if (dep.equals(BOOSTER_JAXRS)) { - JAXRSBoosterPackConfigurator jaxrsConfig = new JAXRSBoosterPackConfigurator(); - jaxrsConfig.setFeature(dependencies.get(dep)); + } else if (dep.getArtifact().equals(BOOSTER_JAXRS)) { + JAXRSBoosterPackConfigurator jaxrsConfig = new JAXRSBoosterPackConfigurator(dep, serverConfig); boosterPackConfigList.add(jaxrsConfig); - } else if (dep.equals(BOOSTER_MPHEALTH)) { - MPHealthBoosterPackConfigurator mpHealthConfig = new MPHealthBoosterPackConfigurator(); - mpHealthConfig.setFeature(dependencies.get(dep)); + } else if (dep.getArtifact().equals(BOOSTER_MPHEALTH)) { + MPHealthBoosterPackConfigurator mpHealthConfig = new MPHealthBoosterPackConfigurator(dep, serverConfig); boosterPackConfigList.add(mpHealthConfig); - } else if (dep.equals(BOOSTER_MPCONFIG)) { - MPConfigBoosterPackConfigurator mpConfigConfig = new MPConfigBoosterPackConfigurator(); - mpConfigConfig.setFeature(dependencies.get(dep)); + } else if (dep.getArtifact().equals(BOOSTER_MPCONFIG)) { + MPConfigBoosterPackConfigurator mpConfigConfig = new MPConfigBoosterPackConfigurator(dep, serverConfig); boosterPackConfigList.add(mpConfigConfig); - } else if (dep.equals(BOOSTER_CDI)) { - CDIBoosterPackConfigurator CDIConfig = new CDIBoosterPackConfigurator(); - CDIConfig.setFeature(dependencies.get(dep)); + } else if (dep.getArtifact().equals(BOOSTER_CDI)) { + CDIBoosterPackConfigurator CDIConfig = new CDIBoosterPackConfigurator(dep, serverConfig); boosterPackConfigList.add(CDIConfig); - } else if (dep.equals(BOOSTER_MPRESTCLIENT)) { - MPRestClientBoosterPackConfigurator mpRestClientConfig = new MPRestClientBoosterPackConfigurator(); - mpRestClientConfig.setFeature(dependencies.get(dep)); + } else if (dep.getArtifact().equals(BOOSTER_MPRESTCLIENT)) { + MPRestClientBoosterPackConfigurator mpRestClientConfig = new MPRestClientBoosterPackConfigurator(dep, serverConfig); boosterPackConfigList.add(mpRestClientConfig); - } else if (dep.equals(BOOSTER_JSONP)) { - JSONPBoosterPackConfigurator jsonpConfig = new JSONPBoosterPackConfigurator(); - jsonpConfig.setFeature(dependencies.get(dep)); + } else if (dep.getArtifact().equals(BOOSTER_JSONP)) { + JSONPBoosterPackConfigurator jsonpConfig = new JSONPBoosterPackConfigurator(dep, serverConfig); boosterPackConfigList.add(jsonpConfig); - } else if (dep.equals(BOOSTER_OPENTRACING)) { - MPOpenTracingBoosterPackConfigurator mpOpenTracingConfig = new MPOpenTracingBoosterPackConfigurator(); - mpOpenTracingConfig.setFeature(dependencies.get(dep)); + } else if (dep.getArtifact().equals(BOOSTER_OPENTRACING)) { + MPOpenTracingBoosterPackConfigurator mpOpenTracingConfig = new MPOpenTracingBoosterPackConfigurator(dep, serverConfig); boosterPackConfigList.add(mpOpenTracingConfig); } } @@ -104,12 +108,11 @@ private List getBoosterPackConfigurators(Map boosterDependencies = MavenProjectUtil.getBoosterDependencies(project, + List boosterDependencies = MavenProjectUtil.getBoosterDependencies(project, BoostLogger.getInstance()); boosterUtil = new LibertyBoosterUtil(libertyServerPath, boosterDependencies, BoostLogger.getInstance()); @@ -127,6 +128,7 @@ public void execute() throws MojoExecutionException { copyBoosterDependencies(); + System.out.println("AJM: going to process the features"); generateServerConfigEE(); installMissingFeatures(); @@ -182,6 +184,7 @@ private void generateServerConfigEE() throws MojoExecutionException { try { // Generate server config + System.out.println("AJM: gernerating the srv cfg"); boosterUtil.generateLibertyServerConfig(warName); } catch (Exception e) { diff --git a/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/utils/MavenProjectUtil.java b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/utils/MavenProjectUtil.java index 2e9037cc..0198f5ad 100644 --- a/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/utils/MavenProjectUtil.java +++ b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/utils/MavenProjectUtil.java @@ -19,6 +19,8 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.project.MavenProject; +import io.openliberty.boost.common.config.BoosterDependencyInfo; + public class MavenProjectUtil { /** @@ -59,9 +61,9 @@ public static List getSpringFrameworkDependencies(MavenProject project) return springFrameworkDependencies; } - public static Map getBoosterDependencies(MavenProject project, BoostLogger logger) { + public static List getBoosterDependencies(MavenProject project, BoostLogger logger) { - Map boosterDependencies = new HashMap(); + List boosterDependencies = new ArrayList(); logger.debug("Processing project for dependencies."); for (Artifact artifact : project.getArtifacts()) { @@ -69,7 +71,9 @@ public static Map getBoosterDependencies(MavenProject project, B + artifact.getArtifactId() + ":" + artifact.getVersion()); if (artifact.getGroupId().equals("io.openliberty.boosters")) { - boosterDependencies.put(artifact.getArtifactId(), artifact.getVersion()); + BoosterDependencyInfo currBooster = new BoosterDependencyInfo(artifact.getGroupId(), + artifact.getArtifactId(), artifact.getVersion()); + boosterDependencies.add(currBooster); } } From 3f0cf6ffc1fcdbdd747c72e8a9420ee92876fe92 Mon Sep 17 00:00:00 2001 From: Andrew Mauer Date: Thu, 3 Jan 2019 17:06:16 -0500 Subject: [PATCH 3/6] fix jars config levels --- .../config/JAXRSBoosterPackConfigurator.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/boost-common/src/main/java/io/openliberty/boost/common/config/JAXRSBoosterPackConfigurator.java b/boost-common/src/main/java/io/openliberty/boost/common/config/JAXRSBoosterPackConfigurator.java index 529ed7ca..d4f28add 100644 --- a/boost-common/src/main/java/io/openliberty/boost/common/config/JAXRSBoosterPackConfigurator.java +++ b/boost-common/src/main/java/io/openliberty/boost/common/config/JAXRSBoosterPackConfigurator.java @@ -16,22 +16,22 @@ import org.w3c.dom.Document; public class JAXRSBoosterPackConfigurator extends BoosterPackConfigurator { - + public JAXRSBoosterPackConfigurator(BoosterDependencyInfo depInfo, LibertyServerConfigGenerator srvrXML) { - super(depInfo, srvrXML); - // TODO Auto-generated constructor stub - } + super(depInfo, srvrXML); + // TODO Auto-generated constructor stub + } - @Override + @Override public void addServerConfig(Document doc) { // write out the feature Manager stanza - if (dependencyInfo.getVersion().equals(EE_7_VERSION)) { - serverXML.addFeature(JAXRS_20); + if (dependencyInfo.getVersion().equals(EE_7_VERSION)) { + serverXML.addFeature(JAXRS_20); } else if (dependencyInfo.getVersion().equals(EE_8_VERSION)) { - serverXML.addFeature(JAXRS_20); + serverXML.addFeature(JAXRS_21); } - - // no further config needed for jaxrs + + // no further config needed for jaxrs } } From 8fdfab1463f65d0e40e27a06532ac1328f323761 Mon Sep 17 00:00:00 2001 From: Andrew Mauer Date: Mon, 7 Jan 2019 14:57:35 -0500 Subject: [PATCH 4/6] introduce groovy updates for microprofile re-structure plus mphealth testcase --- boost-gradle/build.gradle | 4 + .../gradle/tasks/BoostPackageTask.groovy | 7 +- .../gradle/utils/GradleProjectUtil.groovy | 12 +- .../groovy/BoostPackageMPHealth10Test.groovy | 176 ++++++++++++++++++ .../resources/test-mpHealth-1.0/build.gradle | 51 +++++ .../guides/config/CustomConfigSource.java | 103 ++++++++++ .../inventory/InventoryApplication.java | 21 +++ .../guides/inventory/InventoryConfig.java | 49 +++++ .../guides/inventory/InventoryHealth.java | 68 +++++++ .../guides/inventory/InventoryManager.java | 48 +++++ .../guides/inventory/InventoryResource.java | 81 ++++++++ .../guides/inventory/InventoryUtils.java | 87 +++++++++ .../guides/inventory/client/SystemClient.java | 37 ++++ .../inventory/client/UnknownUrlException.java | 28 +++ .../client/UnknownUrlExceptionMapper.java | 38 ++++ .../guides/inventory/model/InventoryList.java | 32 ++++ .../guides/inventory/model/SystemData.java | 44 +++++ .../guides/system/SystemApplication.java | 21 +++ .../guides/system/SystemHealth.java | 35 ++++ .../guides/system/SystemResource.java | 31 +++ .../main/resources/CustomConfigSource.json | 4 + .../META-INF/microprofile-config.properties | 11 ++ ...lipse.microprofile.config.spi.ConfigSource | 3 + .../src/main/webapp/WEB-INF/web.xml | 10 + .../src/main/webapp/index.html | 78 ++++++++ .../guides/health/HealthTestIT.java | 69 +++++++ .../guides/health/HealthTestUtil.java | 97 ++++++++++ 27 files changed, 1240 insertions(+), 5 deletions(-) create mode 100644 boost-gradle/src/test/groovy/BoostPackageMPHealth10Test.groovy create mode 100644 boost-gradle/src/test/resources/test-mpHealth-1.0/build.gradle create mode 100644 boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/config/CustomConfigSource.java create mode 100644 boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryApplication.java create mode 100644 boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryConfig.java create mode 100644 boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryHealth.java create mode 100644 boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryManager.java create mode 100644 boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryResource.java create mode 100644 boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryUtils.java create mode 100644 boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/client/SystemClient.java create mode 100644 boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/client/UnknownUrlException.java create mode 100644 boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/client/UnknownUrlExceptionMapper.java create mode 100644 boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/model/InventoryList.java create mode 100644 boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/model/SystemData.java create mode 100644 boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/system/SystemApplication.java create mode 100644 boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/system/SystemHealth.java create mode 100644 boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/system/SystemResource.java create mode 100644 boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/resources/CustomConfigSource.json create mode 100644 boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/resources/META-INF/microprofile-config.properties create mode 100644 boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource create mode 100644 boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/webapp/WEB-INF/web.xml create mode 100644 boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/webapp/index.html create mode 100644 boost-gradle/src/test/resources/test-mpHealth-1.0/src/test/java/it/io/openliberty/guides/health/HealthTestIT.java create mode 100644 boost-gradle/src/test/resources/test-mpHealth-1.0/src/test/java/it/io/openliberty/guides/health/HealthTestUtil.java diff --git a/boost-gradle/build.gradle b/boost-gradle/build.gradle index 79243f1a..e0946618 100644 --- a/boost-gradle/build.gradle +++ b/boost-gradle/build.gradle @@ -33,6 +33,10 @@ dependencies { testCompile("javax.ws.rs:javax.ws.rs-api:2.1") testCompile("com.github.docker-java:docker-java:3.1.0-rc-4") testCompile "commons-httpclient:commons-httpclient:3.1" + testCompile group: 'org.glassfish', name: 'javax.json', version: '1.0.4' + testCompile group: 'org.apache.cxf', name: 'cxf-rt-rs-client', version: '3.1.11' + testCompile group: 'org.apache.cxf', name: 'cxf-rt-rs-extension-providers', version: '3.1.11' + testCompile group: 'junit', name: 'junit', version: '4.+' } test { diff --git a/boost-gradle/src/main/groovy/io/openliberty/boost/gradle/tasks/BoostPackageTask.groovy b/boost-gradle/src/main/groovy/io/openliberty/boost/gradle/tasks/BoostPackageTask.groovy index 965a5fe7..3fec9545 100644 --- a/boost-gradle/src/main/groovy/io/openliberty/boost/gradle/tasks/BoostPackageTask.groovy +++ b/boost-gradle/src/main/groovy/io/openliberty/boost/gradle/tasks/BoostPackageTask.groovy @@ -36,6 +36,7 @@ import io.openliberty.boost.gradle.utils.GradleProjectUtil import io.openliberty.boost.common.utils.BoostUtil import io.openliberty.boost.common.utils.SpringBootUtil import io.openliberty.boost.common.utils.LibertyBoosterUtil +import io.openliberty.boost.common.config.BoosterDependencyInfo import net.wasdev.wlp.gradle.plugins.extensions.PackageAndDumpExtension @@ -146,7 +147,11 @@ public class BoostPackageTask extends AbstractBoostTask { } else if (project.plugins.hasPlugin('war')) { // Get booster dependencies from project - Map boosterDependencies = GradleProjectUtil.getBoosterDependencies(project) + // Get booster dependencies from project + List boosterDependencies = GradleProjectUtil.getBoosterDependencies(project, + BoostLogger.getInstance()); + + //Map boosterDependencies = GradleProjectUtil.getBoosterDependencies(project) boosterUtil = new LibertyBoosterUtil(libertyServerPath, boosterDependencies, BoostLogger.getInstance()) copyBoosterDependencies() diff --git a/boost-gradle/src/main/groovy/io/openliberty/boost/gradle/utils/GradleProjectUtil.groovy b/boost-gradle/src/main/groovy/io/openliberty/boost/gradle/utils/GradleProjectUtil.groovy index 49653316..fd008bd3 100644 --- a/boost-gradle/src/main/groovy/io/openliberty/boost/gradle/utils/GradleProjectUtil.groovy +++ b/boost-gradle/src/main/groovy/io/openliberty/boost/gradle/utils/GradleProjectUtil.groovy @@ -18,6 +18,8 @@ import org.gradle.api.artifacts.ModuleVersionIdentifier import groovy.lang.MissingPropertyException +import io.openliberty.boost.common.config.BoosterDependencyInfo + public class GradleProjectUtil { /** @@ -56,14 +58,16 @@ public class GradleProjectUtil { return springBootDependencies } - public static Map getBoosterDependencies(Project project) { - Map boosterDependencies = new HashMap() + public static List getBoosterDependencies(Project project) { + List boosterDependencies = new ArrayList() + //Map boosterDependencies = new HashMap() project.configurations.compile.resolvedConfiguration.resolvedArtifacts.collect { it.moduleVersion.id }.each { ModuleVersionIdentifier id -> if ( id.group.equals("io.openliberty.boosters") ) { - - boosterDependencies.put(id.name.toString(), id.version.toString()) + BoosterDependencyInfo currBooster = new BoosterDependencyInfo(id.group.toString, id.name.toString, id.version.toString); + boosterDependencies.add(currBooster); + //boosterDependencies.put(id.name.toString(), id.version.toString()) } } diff --git a/boost-gradle/src/test/groovy/BoostPackageMPHealth10Test.groovy b/boost-gradle/src/test/groovy/BoostPackageMPHealth10Test.groovy new file mode 100644 index 00000000..718f1bb4 --- /dev/null +++ b/boost-gradle/src/test/groovy/BoostPackageMPHealth10Test.groovy @@ -0,0 +1,176 @@ +/******************************************************************************* + * 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 + *******************************************************************************/ +import org.gradle.testkit.runner.BuildResult +import org.gradle.testkit.runner.GradleRunner +import static org.gradle.testkit.runner.TaskOutcome.* + +import static org.junit.Assert.assertEquals +import org.junit.After +import org.junit.Before +import org.junit.Test +import org.junit.BeforeClass +import org.junit.AfterClass + +import java.io.BufferedReader +import java.io.File +import java.io.FileReader +import java.io.FileWriter + +import javax.ws.rs.client.Client +import javax.ws.rs.client.ClientBuilder +import javax.ws.rs.core.Response +import javax.json.JsonArray +import javax.json.JsonObject + +import org.apache.cxf.jaxrs.provider.jsrjsonp.JsrJsonpProvider + +public class BoostPackageMPHealth10Test extends AbstractBoostTest { + + static BuildResult result + + static File resourceDir = new File("build/resources/test/test-mpHealth-1.0") + static File testProjectDir = new File(integTestDir, "BoostPackageMPHealth10Test") + static String buildFilename = "testMPHealth10.gradle" + + private JsonArray servicesStates + private static HashMap dataWhenServicesUP + private static HashMap dataWhenInventoryDown + + static { + dataWhenServicesUP = new HashMap() + dataWhenInventoryDown = new HashMap() + + dataWhenServicesUP.put("SystemResource", "UP") + dataWhenServicesUP.put("InventoryResource", "UP") + + dataWhenInventoryDown.put("SystemResource", "UP") + dataWhenInventoryDown.put("InventoryResource", "DOWN") + } + + @BeforeClass + public static void setup() { + createDir(testProjectDir) + createTestProject(testProjectDir, resourceDir, buildFilename) + + result = GradleRunner.create() + .withProjectDir(testProjectDir) + .forwardOutput() + .withArguments("boostPackage", "boostStart", "-i", "-s") + .build() + } + + @AfterClass + public static void teardown() { + + HealthTestUtil.cleanUp() + + result = GradleRunner.create() + .withProjectDir(testProjectDir) + .forwardOutput() + .withArguments("boostStop", "-i", "-s") + .build() + + assertEquals(SUCCESS, result.task(":boostStop").getOutcome()) + + } + + @Test + public void testIfServicesAreUp() { + servicesStates = HealthTestUtil.connectToHealthEnpoint(200) + checkStates(dataWhenServicesUP, servicesStates) + } + + @Test + public void testIfInventoryServiceIsDown() { + servicesStates = HealthTestUtil.connectToHealthEnpoint(200) + checkStates(dataWhenServicesUP, servicesStates) + HealthTestUtil.changeInventoryProperty(HealthTestUtil.INV_MAINTENANCE_FALSE, + HealthTestUtil.INV_MAINTENANCE_TRUE) + servicesStates = HealthTestUtil.connectToHealthEnpoint(503) + checkStates(dataWhenInventoryDown, servicesStates) + } + + private void checkStates(HashMap testData, JsonArray servStates) { + testData.forEach { service, expectedState -> + assertEquals("The state of " + service + " service is not matching.", + expectedState, + HealthTestUtil.getActualState(service, servStates)); + } + } + + + private class HealthTestUtil { + + private static String port + private static String baseUrl + private final static String HEALTH_ENDPOINT = "health" + public static final String INV_MAINTENANCE_FALSE = "io_openliberty_guides_inventory_inMaintenance\":false" + public static final String INV_MAINTENANCE_TRUE = "io_openliberty_guides_inventory_inMaintenance\":true" + + static { + //port = System.getProperty("liberty.test.port"); + port = "9080" + baseUrl = "http://localhost:" + port + "/" + } + + public static JsonArray connectToHealthEnpoint(int expectedResponseCode) { + String healthURL = baseUrl + HEALTH_ENDPOINT + Client client = ClientBuilder.newClient().register(JsrJsonpProvider.class) + Response response = client.target(healthURL).request().get() + assertEquals("Response code is not matching " + healthURL, + expectedResponseCode, response.getStatus()) + JsonArray servicesStates = response.readEntity(JsonObject.class) + .getJsonArray("checks") + response.close() + client.close() + return servicesStates + } + + public static String getActualState(String service, + JsonArray servicesStates) { + String state = "" + for (Object obj : servicesStates) { + if (obj instanceof JsonObject) { + if (service.equals(((JsonObject) obj).getString("name"))) { + state = ((JsonObject) obj).getString("state") + } + } + } + return state + } + + public static void changeInventoryProperty(String oldValue, String newValue) { + try { + String fileName = System.getProperty("user.dir").split("target")[0] + + "target/it/test-mpHealth-1.0/src/main/resources/CustomConfigSource.json" + BufferedReader reader = new BufferedReader(new FileReader(new File(fileName))) + String line = "" + String oldContent = "", newContent = "" + while ((line = reader.readLine()) != null) { + oldContent += line + "\r\n" + } + reader.close() + newContent = oldContent.replaceAll(oldValue, newValue) + FileWriter writer = new FileWriter(fileName) + writer.write(newContent) + writer.close() + Thread.sleep(600) + } catch (Exception e) { + e.printStackTrace() + } + } + + public static void cleanUp() { + changeInventoryProperty(INV_MAINTENANCE_TRUE, INV_MAINTENANCE_FALSE) + } + + } +} diff --git a/boost-gradle/src/test/resources/test-mpHealth-1.0/build.gradle b/boost-gradle/src/test/resources/test-mpHealth-1.0/build.gradle new file mode 100644 index 00000000..ff2918c4 --- /dev/null +++ b/boost-gradle/src/test/resources/test-mpHealth-1.0/build.gradle @@ -0,0 +1,51 @@ +buildscript { + repositories { + mavenCentral() + mavenLocal() + maven { + url 'https://oss.sonatype.org/content/repositories/snapshots/' + } + maven { url 'https://repo.spring.io/plugins-snapshot' } + } + dependencies { + classpath("io.openliberty.boost:boost-gradle-plugin:$boostVersion") + classpath 'io.spring.gradle:dependency-management-plugin:1.0.6.RELEASE' + } +} + +apply plugin: 'war' +apply plugin: 'boost' +apply plugin: 'io.spring.dependency-management' + +war { + baseName = 'testWar' +} + +repositories { + mavenCentral() + mavenLocal() +} + +sourceCompatibility = 1.8 +targetCompatibility = 1.8 + +dependencyManagement { + imports { + mavenBom "io.openliberty.boosters:mp20-bom:$boosterVersion" + } +} + +dependencies { + compile "io.openliberty.boosters:jaxrs" + compile "io.openliberty.boosters:cdi" + compile "io.openliberty.boosters:mpConfig" + compile "io.openliberty.boosters:jsonp" + compile "io.openliberty.boosters:mpRestClient" + compile "io.openliberty.boosters:mpHealth" + compile("org.apache.httpcomponents:httpclient:4.5.6") + compile("org.apache.httpcomponents:httpcore:4.4.10") + compile("org.apache.commons:commons-lang3:3.0") + compile "javax.servlet:javax.servlet-api:3.1.0" + + libertyRuntime "$runtimeGroup:$runtimeArtifactId:$runtimeVersion" +} diff --git a/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/config/CustomConfigSource.java b/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/config/CustomConfigSource.java new file mode 100644 index 00000000..32b8d541 --- /dev/null +++ b/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/config/CustomConfigSource.java @@ -0,0 +1,103 @@ +// tag::copyright[] +/******************************************************************************* + * Copyright (c) 2017 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 implementation + *******************************************************************************/ +// end::copyright[] + +// tag::customConfig[] +package io.openliberty.guides.config; + +import javax.json.stream.JsonParser; +import javax.json.stream.JsonParser.Event; +import javax.json.Json; +import java.math.BigDecimal; +import java.util.*; +import java.io.StringReader; +import java.io.BufferedReader; +import java.io.FileReader; +import org.eclipse.microprofile.config.spi.ConfigSource; + +public class CustomConfigSource implements ConfigSource { + + String fileLocation = System.getProperty("user.dir").split("target")[0] + + "target/it/test-mpHealth-1.0/src/main/resources/CustomConfigSource.json"; + + @Override + public int getOrdinal() { + return Integer.parseInt(getProperties().get("config_ordinal")); + } + + @Override + public Set getPropertyNames() { + return getProperties().keySet(); + } + + @Override + public String getValue(String key) { + return getProperties().get(key); + } + + @Override + public String getName() { + return "Custom Config Source: file:" + this.fileLocation; + } + + public Map getProperties() { + Map m = new HashMap(); + String jsonData = this.readFile(this.fileLocation); + JsonParser parser = Json.createParser(new StringReader(jsonData)); + String key = null; + while (parser.hasNext()) { + final Event event = parser.next(); + switch (event) { + case KEY_NAME: + key = parser.getString(); + break; + case VALUE_STRING: + String string = parser.getString(); + m.put(key, string); + break; + case VALUE_NUMBER: + BigDecimal number = parser.getBigDecimal(); + m.put(key, number.toString()); + break; + case VALUE_TRUE: + m.put(key, "true"); + break; + case VALUE_FALSE: + m.put(key, "false"); + break; + default: + break; + } + } + parser.close(); + return m; + } + + public String readFile(String fileName) { + String result = ""; + try { + BufferedReader br = new BufferedReader(new FileReader(fileName)); + StringBuilder sb = new StringBuilder(); + String line = br.readLine(); + while (line != null) { + sb.append(line); + line = br.readLine(); + } + result = sb.toString(); + br.close(); + } catch (Exception e) { + e.printStackTrace(); + } + return result; + } +} +// end::customConfig[] diff --git a/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryApplication.java b/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryApplication.java new file mode 100644 index 00000000..612e61cc --- /dev/null +++ b/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryApplication.java @@ -0,0 +1,21 @@ +// tag::copyright[] +/******************************************************************************* + * Copyright (c) 2017 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 implementation + *******************************************************************************/ +// end::copyright[] +package io.openliberty.guides.inventory; + +import javax.ws.rs.ApplicationPath; +import javax.ws.rs.core.Application; + +@ApplicationPath("inventory") +public class InventoryApplication extends Application { + +} diff --git a/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryConfig.java b/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryConfig.java new file mode 100644 index 00000000..0ab6821c --- /dev/null +++ b/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryConfig.java @@ -0,0 +1,49 @@ +// tag::copyright[] +/******************************************************************************* + * Copyright (c) 2017 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 implementation + *******************************************************************************/ +// end::copyright[] + +// tag::config-class[] +package io.openliberty.guides.inventory; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; +import javax.inject.Provider; +import org.eclipse.microprofile.config.inject.ConfigProperty; + +@ApplicationScoped +public class InventoryConfig { + + // tag::port-number[] + @Inject + @ConfigProperty(name = "io_openliberty_guides_port_number") + private int portNumber; + // end::port-number[] + + // tag::build-in-converter[] + @Inject + @ConfigProperty(name = "io_openliberty_guides_inventory_inMaintenance") + private Provider inMaintenance; + // end::build-in-converter[] + + // tag::isInMaintenance[] + public boolean isInMaintenance() { + return inMaintenance.get(); + } + // end::isInMaintenance[] + + // tag::getPortNumber[] + public int getPortNumber() { + return portNumber; + } + // end::getPortNumber[] +} +// end::config-class[] diff --git a/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryHealth.java b/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryHealth.java new file mode 100644 index 00000000..26d22462 --- /dev/null +++ b/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryHealth.java @@ -0,0 +1,68 @@ +// tag::comment[] +/******************************************************************************* + * 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 implementation + *******************************************************************************/ +// end::comment[] +// tag::InventoryHealth[] +package io.openliberty.guides.inventory; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import io.openliberty.guides.inventory.client.SystemClient; +import org.eclipse.microprofile.health.Health; +import org.eclipse.microprofile.health.HealthCheck; +import org.eclipse.microprofile.health.HealthCheckResponse; + +@Health +@ApplicationScoped +public class InventoryHealth implements HealthCheck { + @Inject + InventoryConfig config; + + private InventoryUtils invUtils = new InventoryUtils(); + + public boolean isHealthy() { + if (config.isInMaintenance()) { + return false; + } + try { + String url = invUtils.buildUrl("http", "localhost", + //Integer.parseInt(System.getProperty("default.http.port")), + 9080, + "/system/properties"); + Client client = ClientBuilder.newClient(); + Response response = client.target(url).request(MediaType.APPLICATION_JSON) + .get(); + if (response.getStatus() != 200) { + return false; + } + return true; + } catch (Exception e) { + return false; + } + } + + @Override + public HealthCheckResponse call() { + if (!isHealthy()) { + return HealthCheckResponse.named(InventoryResource.class.getSimpleName()) + .withData("services", "not available").down() + .build(); + } + return HealthCheckResponse.named(InventoryResource.class.getSimpleName()) + .withData("services", "available").up().build(); + } + +} +// end::InventoryHealth[] diff --git a/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryManager.java b/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryManager.java new file mode 100644 index 00000000..d6e0ae9b --- /dev/null +++ b/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryManager.java @@ -0,0 +1,48 @@ +// tag::copyright[] +/******************************************************************************* + * Copyright (c) 2017, 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 implementation + *******************************************************************************/ +// end::copyright[] +// tag::manager[] +package io.openliberty.guides.inventory; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Properties; +import javax.enterprise.context.ApplicationScoped; +import io.openliberty.guides.inventory.model.*; + +@ApplicationScoped +public class InventoryManager { + + private List systems = Collections.synchronizedList(new ArrayList<>()); + private InventoryUtils invUtils = new InventoryUtils(); + + public Properties get(String hostname, int portNumber) { + return invUtils.getProperties(hostname, portNumber); + } + + public void add(String hostname, Properties systemProps) { + Properties props = new Properties(); + props.setProperty("os.name", systemProps.getProperty("os.name")); + props.setProperty("user.name", systemProps.getProperty("user.name")); + + SystemData host = new SystemData(hostname, props); + if (!systems.contains(host)) + systems.add(host); + } + + public InventoryList list() { + return new InventoryList(systems); + } + +} +// end::manager[] diff --git a/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryResource.java b/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryResource.java new file mode 100644 index 00000000..8eabe508 --- /dev/null +++ b/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryResource.java @@ -0,0 +1,81 @@ +// tag::copyright[] +/******************************************************************************* + * Copyright (c) 2017 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 implementation + *******************************************************************************/ +// end::copyright[] + +// tag::InventoryResource[] +package io.openliberty.guides.inventory; + +import java.util.Properties; +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import io.openliberty.guides.inventory.InventoryConfig; + +@RequestScoped +@Path("systems") +public class InventoryResource { + + @Inject + InventoryManager manager; + + // tag::config-injection[] + @Inject + InventoryConfig inventoryConfig; + // end::config-injection[] + + @GET + @Path("{hostname}") + @Produces(MediaType.APPLICATION_JSON) + public Response getPropertiesForHost(@PathParam("hostname") String hostname) { + + if (!inventoryConfig.isInMaintenance()) { + // Get properties + // tag::config-port[] + Properties props = manager.get(hostname, inventoryConfig.getPortNumber()); + // end::config-port[] + if (props == null) { + return Response.status(Response.Status.NOT_FOUND) + .entity( + "ERROR: Unknown hostname or the resource may not be running on the host machine") + .build(); + } + + // Add to inventory + manager.add(hostname, props); + return Response.ok(props).build(); + } else { + // tag::email[] + return Response.status(Response.Status.SERVICE_UNAVAILABLE) + .entity("ERROR: Service is currently in maintenance.").build(); + // end::email[] + } + } + + @GET + @Produces(MediaType.APPLICATION_JSON) + public Response listContents() { + if (!inventoryConfig.isInMaintenance()) { + return Response.ok(manager.list()).build(); + } else { + return Response.status(Response.Status.SERVICE_UNAVAILABLE) + .entity("ERROR: Service is currently in maintenance.").build(); + } + } + +} + +// end::InventoryResource[] diff --git a/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryUtils.java b/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryUtils.java new file mode 100644 index 00000000..fb1bdb93 --- /dev/null +++ b/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/InventoryUtils.java @@ -0,0 +1,87 @@ +// tag::copyright[] +/******************************************************************************* + * Copyright (c) 2017, 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 implementation + *******************************************************************************/ +// end::copyright[] +package io.openliberty.guides.inventory; + +import java.net.URL; +import java.net.URI; +import java.net.UnknownHostException; +import java.net.MalformedURLException; +import javax.ws.rs.ProcessingException; +import java.util.Properties; +import org.apache.commons.lang3.exception.ExceptionUtils; +import org.eclipse.microprofile.rest.client.RestClientBuilder; +import io.openliberty.guides.inventory.client.SystemClient; +import io.openliberty.guides.inventory.client.UnknownUrlException; +import io.openliberty.guides.inventory.client.UnknownUrlExceptionMapper; + +public class InventoryUtils { + + // tag::builder[] + public Properties getProperties(String hostname, int portNumber) { + String customURLString = "http://" + hostname + ":" + portNumber + "/system"; + URL customURL = null; + try { + customURL = new URL(customURLString); + SystemClient customRestClient = RestClientBuilder.newBuilder() + .baseUrl(customURL) + .register( + UnknownUrlExceptionMapper.class) + .build(SystemClient.class); + return customRestClient.getProperties(); + } catch (ProcessingException ex) { + handleProcessingException(ex); + } catch (UnknownUrlException e) { + System.err.println("The given URL is unreachable."); + } catch (MalformedURLException e) { + System.err.println("The given URL is not formatted correctly."); + } + return null; + } + // end::builder[] + + public void handleProcessingException(ProcessingException ex) { + Throwable rootEx = ExceptionUtils.getRootCause(ex); + if (rootEx != null && rootEx instanceof UnknownHostException) { + System.err.println("The specified host is unknown."); + } else { + throw ex; + } + } + + // tag::doc[] + /** + * Builds the URI string to the system service for a particular host. + * + * @param protocol + * - http or https. + * @param host + * - name of host. + * @param port + * - port number. + * @param path + * - Note that the path needs to start with a slash!!! + * @return String representation of the URI to the system properties service. + */ + // end::doc[] + public static String buildUrl(String protocol, String host, int port, + String path) { + try { + URI uri = new URI(protocol, null, host, port, path, null, null); + return uri.toString(); + } catch (Exception e) { + System.out.println("URISyntaxException"); + return null; + } + } + +} \ No newline at end of file diff --git a/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/client/SystemClient.java b/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/client/SystemClient.java new file mode 100644 index 00000000..173ff3ad --- /dev/null +++ b/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/client/SystemClient.java @@ -0,0 +1,37 @@ +// tag::copyright[] +/******************************************************************************* + * Copyright (c) 2017, 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 implementation + *******************************************************************************/ +// end::copyright[] +// tag::client[] +package io.openliberty.guides.inventory.client; + +import java.util.Properties; +import javax.enterprise.context.Dependent; +import javax.ws.rs.ProcessingException; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import org.eclipse.microprofile.rest.client.annotation.RegisterProvider; +import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; + +// tag::annotations[] +@Dependent +@RegisterRestClient +@RegisterProvider(UnknownUrlExceptionMapper.class) +@Path("/properties") +public interface SystemClient { + // end::annotations[] + @GET + @Produces(MediaType.APPLICATION_JSON) + public Properties getProperties() throws UnknownUrlException, ProcessingException; +} +// end::client[] diff --git a/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/client/UnknownUrlException.java b/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/client/UnknownUrlException.java new file mode 100644 index 00000000..45e740b6 --- /dev/null +++ b/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/client/UnknownUrlException.java @@ -0,0 +1,28 @@ +// tag::copyright[] +/******************************************************************************* + * Copyright (c) 2017, 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 implementation + *******************************************************************************/ +// end::copyright[] +// tag::exception[] +package io.openliberty.guides.inventory.client; + +public class UnknownUrlException extends Exception { + + private static final long serialVersionUID = 1L; + + public UnknownUrlException() { + super(); + } + + public UnknownUrlException(String message) { + super(message); + } +} +// end::exception[] diff --git a/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/client/UnknownUrlExceptionMapper.java b/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/client/UnknownUrlExceptionMapper.java new file mode 100644 index 00000000..a7eb66ae --- /dev/null +++ b/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/client/UnknownUrlExceptionMapper.java @@ -0,0 +1,38 @@ +// tag::copyright[] +/******************************************************************************* + * Copyright (c) 2017, 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 implementation + *******************************************************************************/ +// end::copyright[] +// tag::mapper[] +package io.openliberty.guides.inventory.client; + +import java.util.logging.Logger; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.Response; +import javax.ws.rs.ext.Provider; +import org.eclipse.microprofile.rest.client.ext.ResponseExceptionMapper; + +@Provider +public class UnknownUrlExceptionMapper + implements ResponseExceptionMapper { + Logger LOG = Logger.getLogger(UnknownUrlExceptionMapper.class.getName()); + + @Override + public boolean handles(int status, MultivaluedMap headers) { + LOG.info("status = " + status); + return status == 404; + } + + @Override + public UnknownUrlException toThrowable(Response response) { + return new UnknownUrlException(); + } +} +// end::mapper[] diff --git a/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/model/InventoryList.java b/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/model/InventoryList.java new file mode 100644 index 00000000..2a562109 --- /dev/null +++ b/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/model/InventoryList.java @@ -0,0 +1,32 @@ +// tag::copyright[] +/******************************************************************************* + * Copyright (c) 2017, 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 implementation + *******************************************************************************/ +// end::copyright[] +package io.openliberty.guides.inventory.model; + +import java.util.List; + +public class InventoryList { + + private List systems; + + public InventoryList(List systems) { + this.systems = systems; + } + + public List getSystems() { + return systems; + } + + public int getTotal() { + return systems.size(); + } +} diff --git a/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/model/SystemData.java b/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/model/SystemData.java new file mode 100644 index 00000000..84b37f30 --- /dev/null +++ b/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/inventory/model/SystemData.java @@ -0,0 +1,44 @@ +// tag::copyright[] +/******************************************************************************* + * Copyright (c) 2017, 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 implementation + *******************************************************************************/ +// end::copyright[] +package io.openliberty.guides.inventory.model; + +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +public class SystemData { + + private final String hostname; + private final Properties properties; + + public SystemData(String hostname, Properties properties) { + this.hostname = hostname; + this.properties = properties; + } + + public String getHostname() { + return hostname; + } + + public Properties getProperties() { + return properties; + } + + @Override + public boolean equals(Object host) { + if (host instanceof SystemData) { + return hostname.equals(((SystemData) host).getHostname()); + } + return false; + } +} diff --git a/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/system/SystemApplication.java b/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/system/SystemApplication.java new file mode 100644 index 00000000..e36ae744 --- /dev/null +++ b/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/system/SystemApplication.java @@ -0,0 +1,21 @@ +// tag::copyright[] +/******************************************************************************* + * Copyright (c) 2017 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 implementation + *******************************************************************************/ +// end::copyright[] +package io.openliberty.guides.system; + +import javax.ws.rs.core.Application; +import javax.ws.rs.ApplicationPath; + +@ApplicationPath("system") +public class SystemApplication extends Application { + +} diff --git a/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/system/SystemHealth.java b/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/system/SystemHealth.java new file mode 100644 index 00000000..cc5b0c23 --- /dev/null +++ b/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/system/SystemHealth.java @@ -0,0 +1,35 @@ +// tag::comment[] +/******************************************************************************* + * 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 implementation + *******************************************************************************/ +// end::comment[] +// tag::SystemHealth[] +package io.openliberty.guides.system; + +import javax.enterprise.context.ApplicationScoped; +import org.eclipse.microprofile.health.Health; +import org.eclipse.microprofile.health.HealthCheck; +import org.eclipse.microprofile.health.HealthCheckResponse; + +@Health +@ApplicationScoped +public class SystemHealth implements HealthCheck { + @Override + public HealthCheckResponse call() { + if (!System.getProperty("wlp.server.name").equals("BoostServer")) { + return HealthCheckResponse.named(SystemResource.class.getSimpleName()) + .withData("default server", "not available").down() + .build(); + } + return HealthCheckResponse.named(SystemResource.class.getSimpleName()) + .withData("default server", "available").up().build(); + } +} +// end::SystemHealth[] diff --git a/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/system/SystemResource.java b/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/system/SystemResource.java new file mode 100644 index 00000000..59d74eb8 --- /dev/null +++ b/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/system/SystemResource.java @@ -0,0 +1,31 @@ +// tag::copyright[] +/******************************************************************************* + * Copyright (c) 2017, 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 implementation + *******************************************************************************/ +// end::copyright[] +package io.openliberty.guides.system; + +import javax.enterprise.context.RequestScoped; +import javax.ws.rs.GET; +import javax.ws.rs.core.Response; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +@RequestScoped +@Path("properties") +public class SystemResource { + + @GET + @Produces(MediaType.APPLICATION_JSON) + public Response getProperties() { + return Response.ok(System.getProperties()).build(); + } +} diff --git a/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/resources/CustomConfigSource.json b/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/resources/CustomConfigSource.json new file mode 100644 index 00000000..0c2ee17c --- /dev/null +++ b/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/resources/CustomConfigSource.json @@ -0,0 +1,4 @@ +{ + "config_ordinal":700, + "io_openliberty_guides_inventory_inMaintenance":false +} diff --git a/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/resources/META-INF/microprofile-config.properties b/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/resources/META-INF/microprofile-config.properties new file mode 100644 index 00000000..b1b24d26 --- /dev/null +++ b/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/resources/META-INF/microprofile-config.properties @@ -0,0 +1,11 @@ +# tag::all-props[] +# tag::ordinal[] +config_ordinal=100 +# end::ordinal[] +# tag::inventory-port-number[] +io_openliberty_guides_port_number=9080 +# end::inventory-port-number[] +# tag::inventory-in-maintenance[] +io_openliberty_guides_inventory_inMaintenance=false +# end::inventory-in-maintenance[] +# end::all-props[] diff --git a/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource b/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource new file mode 100644 index 00000000..2b7d054c --- /dev/null +++ b/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource @@ -0,0 +1,3 @@ +# tag::register[] +io.openliberty.guides.config.CustomConfigSource +# end::register[] diff --git a/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/webapp/WEB-INF/web.xml b/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 00000000..a3823f10 --- /dev/null +++ b/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,10 @@ + + + Liberty Project + + + index.html + + \ No newline at end of file diff --git a/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/webapp/index.html b/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/webapp/index.html new file mode 100644 index 00000000..74ec6c74 --- /dev/null +++ b/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/webapp/index.html @@ -0,0 +1,78 @@ + + + +

Welcome to your Liberty Application

+

Thanks for generating this project using the app accelerator. Please see below for some extra information on each of the technologies you chose

+ +
+

REST

+

+ For the complete feature documentation, see the jaxrs-2.0 + feature description in IBM Knowledge Center. +

+
+ +
+

MicroProfile

+

+ The MicroProfile project is an open + community with the aim of optimizing Enterprise Java for a microservices + architecture. MicroProfile will be evolving with guidance from the community. +

+

+ For the complete feature documentation, see the + microProfile-1.0 + feature description in IBM Knowledge Center. +

+

+ If you want to share your thoughts you can post straight to the + MicroProfile Google group. +

+
+
+
+ + diff --git a/boost-gradle/src/test/resources/test-mpHealth-1.0/src/test/java/it/io/openliberty/guides/health/HealthTestIT.java b/boost-gradle/src/test/resources/test-mpHealth-1.0/src/test/java/it/io/openliberty/guides/health/HealthTestIT.java new file mode 100644 index 00000000..1656bc0c --- /dev/null +++ b/boost-gradle/src/test/resources/test-mpHealth-1.0/src/test/java/it/io/openliberty/guides/health/HealthTestIT.java @@ -0,0 +1,69 @@ +// tag::comment[] +/******************************************************************************* + * 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 implementation + *******************************************************************************/ +// end::comment[] +// tag::HealthTest[] +package it.io.openliberty.guides.health; + +import static org.junit.Assert.assertEquals; +import java.util.HashMap; +import javax.json.JsonArray; +import org.junit.After; +import org.junit.Test; + +public class HealthTestIT { + + private JsonArray servicesStates; + private static HashMap dataWhenServicesUP; + private static HashMap dataWhenInventoryDown; + + static { + dataWhenServicesUP = new HashMap(); + dataWhenInventoryDown = new HashMap(); + + dataWhenServicesUP.put("SystemResource", "UP"); + dataWhenServicesUP.put("InventoryResource", "UP"); + + dataWhenInventoryDown.put("SystemResource", "UP"); + dataWhenInventoryDown.put("InventoryResource", "DOWN"); + } + + @Test + public void testIfServicesAreUp() { + servicesStates = HealthTestUtil.connectToHealthEnpoint(200); + checkStates(dataWhenServicesUP, servicesStates); + } + + @Test + public void testIfInventoryServiceIsDown() { + servicesStates = HealthTestUtil.connectToHealthEnpoint(200); + checkStates(dataWhenServicesUP, servicesStates); + HealthTestUtil.changeInventoryProperty(HealthTestUtil.INV_MAINTENANCE_FALSE, + HealthTestUtil.INV_MAINTENANCE_TRUE); + servicesStates = HealthTestUtil.connectToHealthEnpoint(503); + checkStates(dataWhenInventoryDown, servicesStates); + } + + private void checkStates(HashMap testData, JsonArray servStates) { + testData.forEach((service, expectedState) -> { + assertEquals("The state of " + service + " service is not matching.", + expectedState, + HealthTestUtil.getActualState(service, servStates)); + }); + } + + @After + public void teardown() { + HealthTestUtil.cleanUp(); + } + +} +// end::HealthTest[] diff --git a/boost-gradle/src/test/resources/test-mpHealth-1.0/src/test/java/it/io/openliberty/guides/health/HealthTestUtil.java b/boost-gradle/src/test/resources/test-mpHealth-1.0/src/test/java/it/io/openliberty/guides/health/HealthTestUtil.java new file mode 100644 index 00000000..ab566809 --- /dev/null +++ b/boost-gradle/src/test/resources/test-mpHealth-1.0/src/test/java/it/io/openliberty/guides/health/HealthTestUtil.java @@ -0,0 +1,97 @@ +// tag::comment[] +/******************************************************************************* + * 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 implementation + *******************************************************************************/ +// end::comment[] +// tag::HealthTestUtil[] +package it.io.openliberty.guides.health; + +import static org.junit.Assert.assertEquals; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; + +import javax.json.JsonArray; +import javax.json.JsonObject; +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.core.Response; + +import org.apache.cxf.jaxrs.provider.jsrjsonp.JsrJsonpProvider; + +public class HealthTestUtil { + + private static String port; + private static String baseUrl; + private final static String HEALTH_ENDPOINT = "health"; + public static final String INV_MAINTENANCE_FALSE = "io_openliberty_guides_inventory_inMaintenance\":false"; + public static final String INV_MAINTENANCE_TRUE = "io_openliberty_guides_inventory_inMaintenance\":true"; + + static { + //port = System.getProperty("liberty.test.port"); + port = "9080"; + baseUrl = "http://localhost:" + port + "/"; + } + + public static JsonArray connectToHealthEnpoint(int expectedResponseCode) { + String healthURL = baseUrl + HEALTH_ENDPOINT; + Client client = ClientBuilder.newClient().register(JsrJsonpProvider.class); + Response response = client.target(healthURL).request().get(); + assertEquals("Response code is not matching " + healthURL, + expectedResponseCode, response.getStatus()); + JsonArray servicesStates = response.readEntity(JsonObject.class) + .getJsonArray("checks"); + response.close(); + client.close(); + return servicesStates; + } + + public static String getActualState(String service, + JsonArray servicesStates) { + String state = ""; + for (Object obj : servicesStates) { + if (obj instanceof JsonObject) { + if (service.equals(((JsonObject) obj).getString("name"))) { + state = ((JsonObject) obj).getString("state"); + } + } + } + return state; + } + + public static void changeInventoryProperty(String oldValue, String newValue) { + try { + String fileName = System.getProperty("user.dir").split("target")[0] + + "target/it/test-mpHealth-1.0/src/main/resources/CustomConfigSource.json"; + BufferedReader reader = new BufferedReader(new FileReader(new File(fileName))); + String line = ""; + String oldContent = "", newContent = ""; + while ((line = reader.readLine()) != null) { + oldContent += line + "\r\n"; + } + reader.close(); + newContent = oldContent.replaceAll(oldValue, newValue); + FileWriter writer = new FileWriter(fileName); + writer.write(newContent); + writer.close(); + Thread.sleep(600); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static void cleanUp() { + changeInventoryProperty(INV_MAINTENANCE_TRUE, INV_MAINTENANCE_FALSE); + } + +} +// end::HealthTestUtil[] From 79d5b0fc880c0a87be427a1838ca7eeb7e9a4840 Mon Sep 17 00:00:00 2001 From: Andrew Mauer Date: Wed, 9 Jan 2019 12:33:36 -0500 Subject: [PATCH 5/6] get mpHealth testcase working and remove stray printlns --- .../boost/common/config/LibertyServerConfigGenerator.java | 4 +--- .../boost/gradle/tasks/BoostPackageTask.groovy | 3 +-- .../boost/gradle/utils/GradleProjectUtil.groovy | 2 +- .../src/test/groovy/BoostPackageMPHealth10Test.groovy | 8 +++++--- .../io/openliberty/guides/config/CustomConfigSource.java | 5 +++-- .../{build.gradle => testMPHealth10.gradle} | 0 .../boost/maven/liberty/LibertyPackageMojo.java | 2 -- 7 files changed, 11 insertions(+), 13 deletions(-) rename boost-gradle/src/test/resources/test-mpHealth-1.0/{build.gradle => testMPHealth10.gradle} (100%) diff --git a/boost-common/src/main/java/io/openliberty/boost/common/config/LibertyServerConfigGenerator.java b/boost-common/src/main/java/io/openliberty/boost/common/config/LibertyServerConfigGenerator.java index d041b991..6de1db7b 100644 --- a/boost-common/src/main/java/io/openliberty/boost/common/config/LibertyServerConfigGenerator.java +++ b/boost-common/src/main/java/io/openliberty/boost/common/config/LibertyServerConfigGenerator.java @@ -144,9 +144,7 @@ public void addKeystore(Map keystoreProps, Map k * The full name of the Liberty feature to add. */ public void addFeature(String featureName) { - - System.out.println("AJM: in LSCUtil - feature to be added: " + featureName); - + if (!featuresAdded.contains(featureName)) { Element feature = doc.createElement(FEATURE); feature.appendChild(doc.createTextNode(featureName)); diff --git a/boost-gradle/src/main/groovy/io/openliberty/boost/gradle/tasks/BoostPackageTask.groovy b/boost-gradle/src/main/groovy/io/openliberty/boost/gradle/tasks/BoostPackageTask.groovy index 3fec9545..727abeeb 100644 --- a/boost-gradle/src/main/groovy/io/openliberty/boost/gradle/tasks/BoostPackageTask.groovy +++ b/boost-gradle/src/main/groovy/io/openliberty/boost/gradle/tasks/BoostPackageTask.groovy @@ -148,8 +148,7 @@ public class BoostPackageTask extends AbstractBoostTask { } else if (project.plugins.hasPlugin('war')) { // Get booster dependencies from project // Get booster dependencies from project - List boosterDependencies = GradleProjectUtil.getBoosterDependencies(project, - BoostLogger.getInstance()); + List boosterDependencies = GradleProjectUtil.getBoosterDependencies(project); //Map boosterDependencies = GradleProjectUtil.getBoosterDependencies(project) boosterUtil = new LibertyBoosterUtil(libertyServerPath, boosterDependencies, BoostLogger.getInstance()) diff --git a/boost-gradle/src/main/groovy/io/openliberty/boost/gradle/utils/GradleProjectUtil.groovy b/boost-gradle/src/main/groovy/io/openliberty/boost/gradle/utils/GradleProjectUtil.groovy index fd008bd3..4af038b9 100644 --- a/boost-gradle/src/main/groovy/io/openliberty/boost/gradle/utils/GradleProjectUtil.groovy +++ b/boost-gradle/src/main/groovy/io/openliberty/boost/gradle/utils/GradleProjectUtil.groovy @@ -65,7 +65,7 @@ public class GradleProjectUtil { project.configurations.compile.resolvedConfiguration.resolvedArtifacts.collect { it.moduleVersion.id }.each { ModuleVersionIdentifier id -> if ( id.group.equals("io.openliberty.boosters") ) { - BoosterDependencyInfo currBooster = new BoosterDependencyInfo(id.group.toString, id.name.toString, id.version.toString); + BoosterDependencyInfo currBooster = new BoosterDependencyInfo(id.group.toString(), id.name.toString(), id.version.toString()); boosterDependencies.add(currBooster); //boosterDependencies.put(id.name.toString(), id.version.toString()) } diff --git a/boost-gradle/src/test/groovy/BoostPackageMPHealth10Test.groovy b/boost-gradle/src/test/groovy/BoostPackageMPHealth10Test.groovy index 718f1bb4..0c722a88 100644 --- a/boost-gradle/src/test/groovy/BoostPackageMPHealth10Test.groovy +++ b/boost-gradle/src/test/groovy/BoostPackageMPHealth10Test.groovy @@ -71,7 +71,7 @@ public class BoostPackageMPHealth10Test extends AbstractBoostTest { public static void teardown() { HealthTestUtil.cleanUp() - + result = GradleRunner.create() .withProjectDir(testProjectDir) .forwardOutput() @@ -149,8 +149,10 @@ public class BoostPackageMPHealth10Test extends AbstractBoostTest { public static void changeInventoryProperty(String oldValue, String newValue) { try { - String fileName = System.getProperty("user.dir").split("target")[0] - + "target/it/test-mpHealth-1.0/src/main/resources/CustomConfigSource.json" + //String fileName = System.getProperty("user.dir").split("target")[0] + // + "target/it/test-mpHealth-1.0/src/main/resources/CustomConfigSource.json" + + String fileName = new File("build/resources/test/test-mpHealth-1.0/src/main/resources/CustomConfigSource.json") BufferedReader reader = new BufferedReader(new FileReader(new File(fileName))) String line = "" String oldContent = "", newContent = "" diff --git a/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/config/CustomConfigSource.java b/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/config/CustomConfigSource.java index 32b8d541..7056482c 100644 --- a/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/config/CustomConfigSource.java +++ b/boost-gradle/src/test/resources/test-mpHealth-1.0/src/main/java/io/openliberty/guides/config/CustomConfigSource.java @@ -26,8 +26,8 @@ public class CustomConfigSource implements ConfigSource { - String fileLocation = System.getProperty("user.dir").split("target")[0] - + "target/it/test-mpHealth-1.0/src/main/resources/CustomConfigSource.json"; + String fileLocation = System.getProperty("user.dir").split("build")[0] + + "build/resources/test/test-mpHealth-1.0/src/main/resources/CustomConfigSource.json"; @Override public int getOrdinal() { @@ -51,6 +51,7 @@ public String getName() { public Map getProperties() { Map m = new HashMap(); + String jsonData = this.readFile(this.fileLocation); JsonParser parser = Json.createParser(new StringReader(jsonData)); String key = null; diff --git a/boost-gradle/src/test/resources/test-mpHealth-1.0/build.gradle b/boost-gradle/src/test/resources/test-mpHealth-1.0/testMPHealth10.gradle similarity index 100% rename from boost-gradle/src/test/resources/test-mpHealth-1.0/build.gradle rename to boost-gradle/src/test/resources/test-mpHealth-1.0/testMPHealth10.gradle diff --git a/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/liberty/LibertyPackageMojo.java b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/liberty/LibertyPackageMojo.java index 36f6882e..93bf49a4 100644 --- a/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/liberty/LibertyPackageMojo.java +++ b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/liberty/LibertyPackageMojo.java @@ -128,7 +128,6 @@ public void execute() throws MojoExecutionException { copyBoosterDependencies(); - System.out.println("AJM: going to process the features"); generateServerConfigEE(); installMissingFeatures(); @@ -184,7 +183,6 @@ private void generateServerConfigEE() throws MojoExecutionException { try { // Generate server config - System.out.println("AJM: gernerating the srv cfg"); boosterUtil.generateLibertyServerConfig(warName); } catch (Exception e) { From 998427aed0e475deaa741941d3583fe1c3a2ee6c Mon Sep 17 00:00:00 2001 From: Andrew Mauer Date: Wed, 9 Jan 2019 15:10:47 -0500 Subject: [PATCH 6/6] update gradle plugin version and eliminate another println --- .../common/utils/LibertyBoosterUtil.java | 60 +++++++++---------- boost-gradle/build.gradle | 2 +- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/boost-common/src/main/java/io/openliberty/boost/common/utils/LibertyBoosterUtil.java b/boost-common/src/main/java/io/openliberty/boost/common/utils/LibertyBoosterUtil.java index 47844df7..aac6801c 100644 --- a/boost-common/src/main/java/io/openliberty/boost/common/utils/LibertyBoosterUtil.java +++ b/boost-common/src/main/java/io/openliberty/boost/common/utils/LibertyBoosterUtil.java @@ -41,7 +41,7 @@ public class LibertyBoosterUtil { public static String BOOSTER_MPCONFIG = "mpConfig"; public static String BOOSTER_MPRESTCLIENT = "mpRestClient"; public static String BOOSTER_OPENTRACING = "mpOpenTracing"; - + protected String libertyServerPath; protected List boosterPackConfigurators; protected BoostLoggerI logger; @@ -52,12 +52,12 @@ public LibertyBoosterUtil(String libertyServerPath, List this.logger = logger; try { - this.serverConfig = new LibertyServerConfigGenerator(libertyServerPath); - } catch (ParserConfigurationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - + this.serverConfig = new LibertyServerConfigGenerator(libertyServerPath); + } catch (ParserConfigurationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + this.boosterPackConfigurators = getBoosterPackConfigurators(dependencies); } @@ -74,7 +74,6 @@ private List getBoosterPackConfigurators(List boosterPackConfigList = new ArrayList(); - for (BoosterDependencyInfo dep : dependencies) { if (dep.getArtifact().equals(BOOSTER_JDBC)) { JDBCBoosterPackConfigurator jdbcConfig = new JDBCBoosterPackConfigurator(dep, serverConfig); @@ -82,25 +81,27 @@ private List getBoosterPackConfigurators(List getDependenciesToCopy() { - + List dependenciesToCopy = new ArrayList(); for (BoosterPackConfigurator configurator : boosterPackConfigurators) { diff --git a/boost-gradle/build.gradle b/boost-gradle/build.gradle index e0946618..b7ee1bc8 100644 --- a/boost-gradle/build.gradle +++ b/boost-gradle/build.gradle @@ -24,7 +24,7 @@ repositories { dependencies { compile localGroovy() - compile 'net.wasdev.wlp.gradle.plugins:liberty-gradle-plugin:2.6' + compile 'net.wasdev.wlp.gradle.plugins:liberty-gradle-plugin:2.6.2-SNAPSHOT' compile group: 'commons-io', name: 'commons-io', version: '2.6' compile 'io.openliberty.boost:boost-common:0.1.3-SNAPSHOT' compile 'com.spotify:docker-client:8.11.7'