From c5331e6fe565e7d0a22d1752e8f793d55dbe7c2e Mon Sep 17 00:00:00 2001 From: Michael Arrastia Date: Tue, 1 May 2018 14:55:56 +0100 Subject: Replace AJSC with Spring Boot 1.5.12.RELEASE Updates include: Remove AJSC references Use PropertiesLoader (loader.path) to allow loading external janus or titan deps Fix dependency conflicts between janus/titan deps and Spring Boot deps Use Jetty container Use Jersey registration of Champ REST interface Change-Id: Ic33b886b0b039cce0366c0f0910cc5a3fe5bfd9b Issue-ID: AAI-1041 Signed-off-by: Michael Arrastia --- .../champ-service/v1/conf/jaxrsBeans.groovy | 11 - .../champ-service/v1/docs/README.txt | 1 - .../champ-service/v1/lib/README.txt | 1 - .../champ-service/v1/routes/champ.route | 4 - .../champ-service/v1/routes/jaxrsExample.route | 5 - champ-service/src/main/bin/start.sh | 81 +++---- .../main/java/org/onap/champ/ChampApplication.java | 46 ++++ .../src/main/java/org/onap/champ/ChampRESTAPI.java | 7 +- .../src/main/java/org/onap/champ/JerseyConfig.java | 35 +++ .../src/main/resources/application.properties | 11 + champ-service/src/main/resources/logback.xml | 238 +++++++++++++++++++++ .../onap/champ/event/GraphEventEnvelopeTest.java | 20 ++ .../test/java/org/onap/champ/util/TestUtil.java | 58 +++-- 13 files changed, 416 insertions(+), 102 deletions(-) delete mode 100644 champ-service/src/main/ajsc/champ-service_v1/champ-service/v1/conf/jaxrsBeans.groovy delete mode 100644 champ-service/src/main/ajsc/champ-service_v1/champ-service/v1/docs/README.txt delete mode 100644 champ-service/src/main/ajsc/champ-service_v1/champ-service/v1/lib/README.txt delete mode 100644 champ-service/src/main/ajsc/champ-service_v1/champ-service/v1/routes/champ.route delete mode 100644 champ-service/src/main/ajsc/champ-service_v1/champ-service/v1/routes/jaxrsExample.route create mode 100644 champ-service/src/main/java/org/onap/champ/ChampApplication.java create mode 100644 champ-service/src/main/java/org/onap/champ/JerseyConfig.java create mode 100644 champ-service/src/main/resources/application.properties create mode 100644 champ-service/src/main/resources/logback.xml (limited to 'champ-service/src') diff --git a/champ-service/src/main/ajsc/champ-service_v1/champ-service/v1/conf/jaxrsBeans.groovy b/champ-service/src/main/ajsc/champ-service_v1/champ-service/v1/conf/jaxrsBeans.groovy deleted file mode 100644 index 17d80a4..0000000 --- a/champ-service/src/main/ajsc/champ-service_v1/champ-service/v1/conf/jaxrsBeans.groovy +++ /dev/null @@ -1,11 +0,0 @@ -beans{ - xmlns cxf: "http://camel.apache.org/schema/cxf" - xmlns jaxrs: "http://cxf.apache.org/jaxrs" - xmlns util: "http://www.springframework.org/schema/util" - - echoService(org.onap.champ.service.EchoService) - - util.list(id: 'echoServices') { - ref(bean:'echoService') - } -} \ No newline at end of file diff --git a/champ-service/src/main/ajsc/champ-service_v1/champ-service/v1/docs/README.txt b/champ-service/src/main/ajsc/champ-service_v1/champ-service/v1/docs/README.txt deleted file mode 100644 index 3707179..0000000 --- a/champ-service/src/main/ajsc/champ-service_v1/champ-service/v1/docs/README.txt +++ /dev/null @@ -1 +0,0 @@ -Place any docs here that you want to access within the ajsc upon deployment of your service. diff --git a/champ-service/src/main/ajsc/champ-service_v1/champ-service/v1/lib/README.txt b/champ-service/src/main/ajsc/champ-service_v1/champ-service/v1/lib/README.txt deleted file mode 100644 index 639e21b..0000000 --- a/champ-service/src/main/ajsc/champ-service_v1/champ-service/v1/lib/README.txt +++ /dev/null @@ -1 +0,0 @@ -3rd party JAR's needed by your jars (if any) for a ajsc deployment package go here... \ No newline at end of file diff --git a/champ-service/src/main/ajsc/champ-service_v1/champ-service/v1/routes/champ.route b/champ-service/src/main/ajsc/champ-service_v1/champ-service/v1/routes/champ.route deleted file mode 100644 index cf8d115..0000000 --- a/champ-service/src/main/ajsc/champ-service_v1/champ-service/v1/routes/champ.route +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/champ-service/src/main/ajsc/champ-service_v1/champ-service/v1/routes/jaxrsExample.route b/champ-service/src/main/ajsc/champ-service_v1/champ-service/v1/routes/jaxrsExample.route deleted file mode 100644 index a132030..0000000 --- a/champ-service/src/main/ajsc/champ-service_v1/champ-service/v1/routes/jaxrsExample.route +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/champ-service/src/main/bin/start.sh b/champ-service/src/main/bin/start.sh index de8a4fb..d82d438 100644 --- a/champ-service/src/main/bin/start.sh +++ b/champ-service/src/main/bin/start.sh @@ -21,74 +21,43 @@ # ECOMP is a trademark and service mark of AT&T Intellectual Property. # - -BASEDIR="/opt/app/champ-service/" -AJSC_HOME="$BASEDIR" -AJSC_CONF_HOME="$AJSC_HOME/bundleconfig/" +APP_HOME="/opt/app/champ-service" +GRAPH_DEPS_HOME="${APP_HOME}/graph-deps" if [ -z "$CONFIG_HOME" ]; then - echo "CONFIG_HOME must be set in order to start up process" - exit 1 + echo "CONFIG_HOME must be set in order to start up process" + exit 1 fi if [ -z "$KEY_STORE_PASSWORD" ]; then - echo "KEY_STORE_PASSWORD must be set in order to start up process" - exit 1 -else - echo "KEY_STORE_PASSWORD=$KEY_STORE_PASSWORD\n" >> $AJSC_CONF_HOME/etc/sysprops/sys-props.properties -fi - -if [ -z "$KEY_MANAGER_PASSWORD" ]; then - echo "KEY_MANAGER_PASSWORD must be set in order to start up process" - exit 1 -else - echo "KEY_MANAGER_PASSWORD=$KEY_MANAGER_PASSWORD\n" >> $AJSC_CONF_HOME/etc/sysprops/sys-props.properties + echo "KEY_STORE_PASSWORD must be set in order to start up process" + exit 1 fi -# Add any spring bean configuration files to the Gizmo deployment -if [ -n "$SERVICE_BEANS" ]; then - echo "Adding the following dynamic service beans to the deployment: " - mkdir -p /tmp/champ-service/v1/conf - for f in `ls $SERVICE_BEANS` - do - cp $SERVICE_BEANS/$f /tmp/champ-service/v1/conf - echo "Adding dynamic service bean $SERVICE_BEANS/$f" - done - jar uf /opt/app/champ-service/services/champ-service_v1.zip* -C /tmp/ champ-service - rm -rf /tmp/champ-service +if [ -z "$SERVICE_BEANS" ]; then + echo "SERVICE_BEANS must be set in order to start up process" + exit 1 fi -CLASSPATH="$AJSC_HOME/lib/*" -CLASSPATH="$CLASSPATH:$AJSC_HOME/extJars/" -CLASSPATH="$CLASSPATH:$AJSC_HOME/etc/" - -# Check to see if the provided implementation exists in the image and add it to the classpath -for file in $( find ${BASEDIR}graph-deps/* -maxdepth 0 -type d ); do - CURRIMPL=$(echo $file | cut -d"/" -f6) - if [ "x$GRAPHIMPL" = "x$CURRIMPL" ]; then - CLASSPATH_GRAPHIMPL=$file - echo "Setting up graph implementation of $GRAPHIMPL" - else - SUPPORTED_GRAPHIMPL="$SUPPORTED_GRAPHIMPL $CURRIMPL" - fi +for dir in $( find ${GRAPH_DEPS_HOME}/* -maxdepth 0 -type d ); do + CURRIMPL=$(basename $dir) + if [ "x$GRAPHIMPL" = "x$CURRIMPL" ]; then + GRAPHIMPL_DEPS="${GRAPH_DEPS_HOME}/${GRAPHIMPL}" + echo "Setting up graph implementation to $GRAPHIMPL" + else + SUPPORTED_GRAPHIMPL="$SUPPORTED_GRAPHIMPL $CURRIMPL" + fi done -if [ -n "$CLASSPATH_GRAPHIMPL" ]; then - cp $CLASSPATH_GRAPHIMPL/* $AJSC_HOME/extJars/ -else - echo "Configured graph implementation '$GRAPHIMPL' is not supported. Acceptable implementations are one of: $SUPPORTED_GRAPHIMPL" - exit 1 + +if [ -z "$GRAPHIMPL_DEPS" ]; then + echo "Configured graph implementation '$GRAPHIMPL' is not supported. Acceptable implementations are one of: $SUPPORTED_GRAPHIMPL" + exit 1 fi -PROPS="-DAJSC_HOME=$AJSC_HOME" -PROPS="$PROPS -DAJSC_CONF_HOME=$BASEDIR/bundleconfig/" -PROPS="$PROPS -Dlogback.configurationFile=$BASEDIR/bundleconfig/etc/logback.xml" -PROPS="$PROPS -DAJSC_SHARED_CONFIG=$AJSC_CONF_HOME" -PROPS="$PROPS -DAJSC_SERVICE_NAMESPACE=champ-service" -PROPS="$PROPS -DAJSC_SERVICE_VERSION=v1" -PROPS="$PROPS -Dserver.port=9522" +PROPS="-DAPP_HOME=$APP_HOME" PROPS="$PROPS -DCONFIG_HOME=$CONFIG_HOME" +PROPS="$PROPS -DKEY_STORE_PASSWORD=$KEY_STORE_PASSWORD" JVM_MAX_HEAP=${MAX_HEAP:-1024} -echo $CLASSPATH - -exec java -Xmx${JVM_MAX_HEAP}m $PROPS -classpath $CLASSPATH com.att.ajsc.runner.Runner context=// sslport=9522 +set -x +exec java -Xmx${JVM_MAX_HEAP}m $PROPS -Dloader.path="${GRAPHIMPL_DEPS}" -jar "${APP_HOME}/champ-service.jar" diff --git a/champ-service/src/main/java/org/onap/champ/ChampApplication.java b/champ-service/src/main/java/org/onap/champ/ChampApplication.java new file mode 100644 index 0000000..bc74469 --- /dev/null +++ b/champ-service/src/main/java/org/onap/champ/ChampApplication.java @@ -0,0 +1,46 @@ +/** + * ============LICENSE_START========================================== + * org.onap.aai + * =================================================================== + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 Amdocs + * =================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END============================================ + */ +package org.onap.champ; + +import java.util.HashMap; +import java.util.Map; +import org.eclipse.jetty.util.security.Password; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.support.SpringBootServletInitializer; +import org.springframework.context.annotation.ImportResource; + +@SpringBootApplication +@ImportResource({"file:${SERVICE_BEANS}/*.xml"}) +public class ChampApplication extends SpringBootServletInitializer { + + public static void main(String[] args) { + String keyStorePassword = System.getProperty("KEY_STORE_PASSWORD"); + if (keyStorePassword == null || keyStorePassword.isEmpty()) { + throw new RuntimeException("Environment property KEY_STORE_PASSWORD not set"); + } + + Map props = new HashMap<>(); + props.put("server.ssl.key-store-password", Password.deobfuscate(keyStorePassword)); + new ChampApplication().configure(new SpringApplicationBuilder(ChampApplication.class).properties(props)) + .run(args); + } +} diff --git a/champ-service/src/main/java/org/onap/champ/ChampRESTAPI.java b/champ-service/src/main/java/org/onap/champ/ChampRESTAPI.java index b75ba53..1a68027 100644 --- a/champ-service/src/main/java/org/onap/champ/ChampRESTAPI.java +++ b/champ-service/src/main/java/org/onap/champ/ChampRESTAPI.java @@ -27,7 +27,6 @@ import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Timer; - import javax.servlet.http.HttpServletRequest; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; @@ -44,7 +43,6 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.UriInfo; - import org.json.JSONException; import org.json.JSONObject; import org.onap.aai.champcore.ChampTransaction; @@ -67,12 +65,11 @@ import org.onap.champ.service.logging.ChampMsgs; import org.onap.champ.service.logging.LoggingUtil; import org.onap.champ.util.ChampProperties; import org.onap.champ.util.ChampServiceConstants; - import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.module.SimpleModule; -@Path(value = "/") +@Path(value = "/services/champ-service/v1/") public class ChampRESTAPI { private ObjectMapper mapper; @@ -88,7 +85,7 @@ public class ChampRESTAPI { public ChampRESTAPI(ChampDataService champDataService, ChampAsyncRequestProcessor champAsyncRequestProcessor) { this.champDataService = champDataService; - // Async request handling is optional. + // Async request handling is optional. if (champAsyncRequestProcessor != null) { timer = new Timer("ChampAsyncRequestProcessor-1"); timer.schedule(champAsyncRequestProcessor, champAsyncRequestProcessor.getRequestPollingTimeSeconds(), diff --git a/champ-service/src/main/java/org/onap/champ/JerseyConfig.java b/champ-service/src/main/java/org/onap/champ/JerseyConfig.java new file mode 100644 index 0000000..f72a2e4 --- /dev/null +++ b/champ-service/src/main/java/org/onap/champ/JerseyConfig.java @@ -0,0 +1,35 @@ +/** + * ============LICENSE_START========================================== + * org.onap.aai + * =================================================================== + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 Amdocs + * =================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END============================================ + */ +package org.onap.champ; + +import org.glassfish.jersey.server.ResourceConfig; +import org.springframework.stereotype.Component; + +/** + * Registers Crud Rest interface as JAX-RS endpoints. + */ +@Component +public class JerseyConfig extends ResourceConfig { + + public JerseyConfig(ChampRESTAPI champRestApi) { + register(champRestApi); + } +} diff --git a/champ-service/src/main/resources/application.properties b/champ-service/src/main/resources/application.properties new file mode 100644 index 0000000..07d7e08 --- /dev/null +++ b/champ-service/src/main/resources/application.properties @@ -0,0 +1,11 @@ +server.port=9522 + +SERVICE_BEANS=dynamic/conf + +server.ssl.key-store=${CONFIG_HOME}/auth/tomcat_keystore +server.ssl.key-store-type=JKS +server.ssl.enabled=true +server.ssl.client-auth=need +server.ssl.key-store-password=${KEY_STORE_PASSWORD} + +logging.config=classpath:logback.xml diff --git a/champ-service/src/main/resources/logback.xml b/champ-service/src/main/resources/logback.xml new file mode 100644 index 0000000..497adb6 --- /dev/null +++ b/champ-service/src/main/resources/logback.xml @@ -0,0 +1,238 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + ${errorLogPattern} + + + + + + + + + + + ${logDirectory}/${generalLogName}.log + + ${logDirectory}/${generalLogName}.%d{yyyy-MM-dd}.log.zip + + 60 + + + ${errorLogPattern} + + + + + + INFO + + 256 + + + + + + + + ${logDirectory}/${auditLogName}.log + + ${logDirectory}/${auditLogName}.%d{yyyy-MM-dd}.log.zip + + 60 + + + ${auditMetricPattern} + + + + 256 + + + + + ${logDirectory}/${metricsLogName}.log + + ${logDirectory}/${metricsLogName}.%d{yyyy-MM-dd}.log.zip + + 60 + + + + ${auditMetricPattern} + + + + + + 256 + + + + + ${logDirectory}/${debugLogName}.log + + ${logDirectory}/${debugLogName}.%d{yyyy-MM-dd}.log.zip + + 60 + + + ${errorLogPattern} + + + + + 256 + + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/champ-service/src/test/java/org/onap/champ/event/GraphEventEnvelopeTest.java b/champ-service/src/test/java/org/onap/champ/event/GraphEventEnvelopeTest.java index 5c39f99..4d30901 100644 --- a/champ-service/src/test/java/org/onap/champ/event/GraphEventEnvelopeTest.java +++ b/champ-service/src/test/java/org/onap/champ/event/GraphEventEnvelopeTest.java @@ -1,3 +1,23 @@ +/** + * ============LICENSE_START========================================== + * org.onap.aai + * =================================================================== + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 Amdocs + * =================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END============================================ + */ package org.onap.champ.event; import static org.hamcrest.Matchers.is; diff --git a/champ-service/src/test/java/org/onap/champ/util/TestUtil.java b/champ-service/src/test/java/org/onap/champ/util/TestUtil.java index b9924e4..65597fe 100644 --- a/champ-service/src/test/java/org/onap/champ/util/TestUtil.java +++ b/champ-service/src/test/java/org/onap/champ/util/TestUtil.java @@ -1,3 +1,23 @@ +/** + * ============LICENSE_START========================================== + * org.onap.aai + * =================================================================== + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 Amdocs + * =================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END============================================ + */ package org.onap.champ.util; import java.io.File; @@ -10,25 +30,25 @@ import java.nio.file.Paths; public class TestUtil { - public static Path getPath(String resourceFilename) throws URISyntaxException { - URL resource = ClassLoader.getSystemResource(resourceFilename); - if (resource != null) { - return Paths.get(resource.toURI()); - } + public static Path getPath(String resourceFilename) throws URISyntaxException { + URL resource = ClassLoader.getSystemResource(resourceFilename); + if (resource != null) { + return Paths.get(resource.toURI()); + } - // If the resource is not found relative to the classpath, try to get it from the file system directly. - File file = new File(resourceFilename); - if (!file.exists()) { - throw new RuntimeException("Resource does not exist: " + resourceFilename); - } - return file.toPath(); - } + // If the resource is not found relative to the classpath, try to get it from the file system directly. + File file = new File(resourceFilename); + if (!file.exists()) { + throw new RuntimeException("Resource does not exist: " + resourceFilename); + } + return file.toPath(); + } - public static String getContentUtf8(Path filePath) throws IOException { - return new String(Files.readAllBytes(filePath)); - } + public static String getContentUtf8(Path filePath) throws IOException { + return new String(Files.readAllBytes(filePath)); + } - public static String getFileAsString(String resourceFilename) throws IOException, URISyntaxException { - return getContentUtf8(getPath(resourceFilename)); - } -} \ No newline at end of file + public static String getFileAsString(String resourceFilename) throws IOException, URISyntaxException { + return getContentUtf8(getPath(resourceFilename)); + } +} -- cgit 1.2.3-korg