From dba5999ebf16a85a996f1f5502c2c154ac3f38b2 Mon Sep 17 00:00:00 2001 From: "waqas.ikram" Date: Fri, 6 Jul 2018 16:37:36 +0100 Subject: Fixing Multi JVM Tests and sonar bugs Change-Id: I02df58695b44d5768410a0eaccb090cda7eb85ba Issue-ID: POLICY-865 Signed-off-by: waqas.ikram --- .gitignore | 1 + .../SequentialContextInstantiation.java | 2 +- .../context/test/locking/ConcurrentContext.java | 74 ++++++--- .../context/test/locking/ConcurrentContextJVM.java | 93 +++++++---- .../test/locking/ConcurrentContextJVMThread.java | 23 ++- .../test/locking/ConcurrentContextThread.java | 24 ++- .../policy/apex/context/test/utils/Constants.java | 2 +- .../test/utils/IntegrationThreadFactory.java | 48 ++++++ .../src/main/package/bin/apexApps.bat | 183 --------------------- .../src/main/package/bin/apexApps.sh | 165 ------------------- .../src/main/package/bin/apexBash.sh | 32 ---- .../src/main/package/bin/apexCLIEditor.bat | 52 ------ .../src/main/package/bin/apexCLIEditor.sh | 50 ------ .../src/main/package/bin/apexEngine.bat | 52 ------ .../src/main/package/bin/apexEngine.sh | 73 -------- .../src/main/package/bin/apexRESTEditor.bat | 52 ------ .../src/main/package/bin/apexRESTEditor.sh | 51 ------ .../src/main/package/scripts/apexApps.bat | 183 +++++++++++++++++++++ .../src/main/package/scripts/apexApps.sh | 165 +++++++++++++++++++ .../src/main/package/scripts/apexBash.sh | 32 ++++ .../src/main/package/scripts/apexCLIEditor.bat | 52 ++++++ .../src/main/package/scripts/apexCLIEditor.sh | 50 ++++++ .../src/main/package/scripts/apexEngine.bat | 52 ++++++ .../src/main/package/scripts/apexEngine.sh | 73 ++++++++ .../src/main/package/scripts/apexRESTEditor.bat | 52 ++++++ .../src/main/package/scripts/apexRESTEditor.sh | 51 ++++++ .../src/main/package/tarball/assembly.xml | 2 +- .../test/locking/TestConcurrentContext.java | 11 +- .../src/test/resources/hazelcast/hazelcast.xml | 13 +- .../src/test/resources/logback-test.xml | 76 --------- .../uservice/test/adapt/kafka/TestKafka2Kafka.java | 12 +- 31 files changed, 938 insertions(+), 863 deletions(-) create mode 100644 context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/utils/IntegrationThreadFactory.java delete mode 100644 packages/apex-pdp-package-full/src/main/package/bin/apexApps.bat delete mode 100755 packages/apex-pdp-package-full/src/main/package/bin/apexApps.sh delete mode 100755 packages/apex-pdp-package-full/src/main/package/bin/apexBash.sh delete mode 100644 packages/apex-pdp-package-full/src/main/package/bin/apexCLIEditor.bat delete mode 100755 packages/apex-pdp-package-full/src/main/package/bin/apexCLIEditor.sh delete mode 100644 packages/apex-pdp-package-full/src/main/package/bin/apexEngine.bat delete mode 100755 packages/apex-pdp-package-full/src/main/package/bin/apexEngine.sh delete mode 100644 packages/apex-pdp-package-full/src/main/package/bin/apexRESTEditor.bat delete mode 100755 packages/apex-pdp-package-full/src/main/package/bin/apexRESTEditor.sh create mode 100644 packages/apex-pdp-package-full/src/main/package/scripts/apexApps.bat create mode 100755 packages/apex-pdp-package-full/src/main/package/scripts/apexApps.sh create mode 100755 packages/apex-pdp-package-full/src/main/package/scripts/apexBash.sh create mode 100644 packages/apex-pdp-package-full/src/main/package/scripts/apexCLIEditor.bat create mode 100755 packages/apex-pdp-package-full/src/main/package/scripts/apexCLIEditor.sh create mode 100644 packages/apex-pdp-package-full/src/main/package/scripts/apexEngine.bat create mode 100755 packages/apex-pdp-package-full/src/main/package/scripts/apexEngine.sh create mode 100644 packages/apex-pdp-package-full/src/main/package/scripts/apexRESTEditor.bat create mode 100755 packages/apex-pdp-package-full/src/main/package/scripts/apexRESTEditor.sh delete mode 100644 testsuites/integration/integration-context-test/src/test/resources/logback-test.xml diff --git a/.gitignore b/.gitignore index 8f3629739..50d9bc3ea 100644 --- a/.gitignore +++ b/.gitignore @@ -7,5 +7,6 @@ target .metadata/ /bin/ +bin/ derby.log .checkstyle diff --git a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/distribution/SequentialContextInstantiation.java b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/distribution/SequentialContextInstantiation.java index e789ae90c..dbf5ab2c6 100644 --- a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/distribution/SequentialContextInstantiation.java +++ b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/distribution/SequentialContextInstantiation.java @@ -308,7 +308,7 @@ public class SequentialContextInstantiation { testBadItem001.setByteValue(BYTE_VAL); testBadItem002.setIntValue(INT_VAL); testBadItem003.setLongValue(LONG_VAL); - testBadItem004.setFloatValue(new Float(FLOAT_VAL)); + testBadItem004.setFloatValue(FLOAT_VAL); testBadItem005.setDoubleValue(PI_VAL); testBadItem006.setStringValue(STRING_GLOBAL_VAL); testBadItem007.setLongValue(testDate.getTime()); diff --git a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContext.java b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContext.java index 2eea957c6..a400bc79a 100644 --- a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContext.java +++ b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContext.java @@ -20,7 +20,13 @@ package org.onap.policy.apex.context.test.locking; +import java.io.Closeable; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; import org.onap.policy.apex.context.ContextAlbum; import org.onap.policy.apex.context.ContextException; @@ -28,6 +34,7 @@ import org.onap.policy.apex.context.Distributor; import org.onap.policy.apex.context.impl.distribution.DistributorFactory; import org.onap.policy.apex.context.test.concepts.TestContextLongItem; import org.onap.policy.apex.context.test.factory.TestContextAlbumFactory; +import org.onap.policy.apex.context.test.utils.IntegrationThreadFactory; import org.onap.policy.apex.model.basicmodel.concepts.ApexException; import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; import org.onap.policy.apex.model.basicmodel.handling.ApexModelException; @@ -41,8 +48,6 @@ import org.slf4j.ext.XLoggerFactory; * @author Liam Fallon (liam.fallon@ericsson.com) */ public class ConcurrentContext { - private static final int TEN_MILLISECONDS = 10; - // Logger for this class private static final XLogger LOGGER = XLoggerFactory.getXLogger(ConcurrentContext.class); @@ -75,45 +80,68 @@ public class ConcurrentContext { LOGGER.debug("starting JVMs and threads . . ."); - final Thread[] threadArray = new Thread[threadCount]; + final String name = getThreadFactoryName(jvmCount, testType); + final IntegrationThreadFactory threadFactory = new IntegrationThreadFactory(name); + final ExecutorService executorService = Executors.newFixedThreadPool(threadCount, threadFactory); + + final List tasks = new ArrayList<>(threadCount); + + addShutDownHook(tasks); // Check if we have a single JVM or multiple JVMs - int runningThreadCount = -1; if (jvmCount == 1) { // Run everything in this JVM for (int t = 0; t < threadCount; t++) { - threadArray[t] = new Thread(new ConcurrentContextThread(0, t, threadLoops)); - threadArray[t].setName(testType + ":TestConcurrentContextThread_0_" + t); - threadArray[t].start(); + final ConcurrentContextThread task = new ConcurrentContextThread(0, t, threadLoops); + tasks.add(task); + executorService.execute(task); } - runningThreadCount = threadCount; } else { // Spawn JVMs to run the tests for (int j = 0; j < jvmCount; j++) { - threadArray[j] = new Thread(new ConcurrentContextJVMThread(testType, j, threadCount, threadLoops)); - threadArray[j].setName(testType + ":TestConcurrentContextJVMThread_" + j); - threadArray[j].start(); + final ConcurrentContextJVMThread task = + new ConcurrentContextJVMThread(testType, j, threadCount, threadLoops); + tasks.add(task); + executorService.execute(task); } - runningThreadCount = jvmCount; } - boolean allFinished; - do { - allFinished = true; - for (int i = 0; i < runningThreadCount; i++) { - if (threadArray[i].isAlive()) { - allFinished = false; + try { + executorService.shutdown(); + // wait for threads to finish, if not Timeout + executorService.awaitTermination(10, TimeUnit.MINUTES); + } catch (final InterruptedException interruptedException) { + LOGGER.error("Exception while waiting for threads to finish", interruptedException); + } + + LOGGER.info("Shutting down now ..."); + executorService.shutdownNow(); + + return concurrentContext.verifyAndClearContext(jvmCount, threadCount, threadLoops); + } + + + private void addShutDownHook(final List tasks) { + Runtime.getRuntime().addShutdownHook(new Thread() { + @Override + public void run() { + LOGGER.info("Shutting down ..."); + for (final Closeable task : tasks) { try { - Thread.sleep(TEN_MILLISECONDS); - } catch (final Exception e) { + task.close(); + } catch (final IOException ioException) { + LOGGER.error("Unable to close task ... ", ioException); } - break; } } - } while (!allFinished); + }); + } - return concurrentContext.verifyAndClearContext(jvmCount, threadCount, threadLoops); + + private String getThreadFactoryName(final int jvmCount, final String testType) { + return jvmCount == 1 ? testType + ":TestConcurrentContextThread_0_" + : testType + ":TestConcurrentContextJVMThread_"; } /** diff --git a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContextJVM.java b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContextJVM.java index 0145bd161..b76b00840 100644 --- a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContextJVM.java +++ b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContextJVM.java @@ -20,20 +20,25 @@ package org.onap.policy.apex.context.test.locking; -import com.google.gson.Gson; - import java.net.InetAddress; import java.net.NetworkInterface; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Enumeration; +import java.util.List; import java.util.Map.Entry; import java.util.TreeSet; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; import org.onap.policy.apex.context.ContextAlbum; import org.onap.policy.apex.context.Distributor; import org.onap.policy.apex.context.impl.distribution.DistributorFactory; import org.onap.policy.apex.context.test.factory.TestContextAlbumFactory; +import org.onap.policy.apex.context.test.utils.IntegrationThreadFactory; import org.onap.policy.apex.model.basicmodel.concepts.ApexException; import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; import org.onap.policy.apex.model.basicmodel.service.AbstractParameters; @@ -42,6 +47,8 @@ import org.onap.policy.apex.model.contextmodel.concepts.AxContextModel; import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; +import com.google.gson.Gson; + /** * The Class ConcurrentContextJVM tests concurrent use of context in a single JVM. * @@ -51,9 +58,16 @@ public final class ConcurrentContextJVM { // Logger for this class private static final XLogger LOGGER = XLoggerFactory.getXLogger(ConcurrentContextJVM.class); - private static final int TEN_MILLISECONDS = 10; private static final int IPV4_ADDRESS_LENGTH = 4; + private final int jvmNo; + + private final int threadCount; + + private final int threadLoops; + + private final ExecutorService executorService; + /** * The Constructor. * @@ -63,9 +77,15 @@ public final class ConcurrentContextJVM { * @param threadLoops the thread loops * @throws ApexException the apex exception */ - private ConcurrentContextJVM(final String testType, final int jvmNo, final int threadCount, final int threadLoops) - throws ApexException { - super(); + private ConcurrentContextJVM(final String testType, final int jvmNo, final int threadCount, final int threadLoops) { + this.jvmNo = jvmNo; + this.threadCount = threadCount; + this.threadLoops = threadLoops; + final String name = testType + ":ConcurrentContextThread_" + jvmNo; + this.executorService = Executors.newFixedThreadPool(threadCount, new IntegrationThreadFactory(name)); + } + + public void execute() throws ApexException { LOGGER.debug("starting JVMs and threads . . ."); final AxArtifactKey distributorKey = new AxArtifactKey("ApexDistributor" + jvmNo, "0.0.1"); @@ -87,34 +107,28 @@ public final class ConcurrentContextJVM { assert (lTypeAlbum != null); lTypeAlbum.setUserArtifactStack(usedArtifactStackArray); - final Thread[] threadArray = new Thread[threadCount]; + final List> tasks = new ArrayList<>(threadCount); for (int t = 0; t < threadCount; t++) { - threadArray[t] = new Thread(new ConcurrentContextThread(jvmNo, t, threadLoops)); - threadArray[t].setName(testType + ":ConcurrentContextThread_" + jvmNo + "_" + t); - threadArray[t].start(); - LOGGER.debug("started thread " + threadArray[t].getName()); + tasks.add(executorService.submit(new ConcurrentContextThread(jvmNo, t, threadLoops))); } - boolean allFinished; - do { - allFinished = true; - for (int t = 0; t < threadCount; t++) { - if (threadArray[t].isAlive()) { - allFinished = false; - try { - Thread.sleep(TEN_MILLISECONDS); - } catch (final Exception e) { - } - break; - } - } - } while (!allFinished); + try { + executorService.shutdown(); + // wait for threads to finish, if not Timeout + executorService.awaitTermination(10, TimeUnit.MINUTES); + } catch (final InterruptedException interruptedException) { + LOGGER.error("Exception while waiting for threads to finish", interruptedException); + } LOGGER.debug("threads finished, end value is {}", lTypeAlbum.get("testValue")); contextDistributor.clear(); + LOGGER.info("Shutting down now ... "); + executorService.shutdownNow(); } + + /** * The main method. * @@ -129,7 +143,7 @@ public final class ConcurrentContextJVM { // CHECKSTYLE:OFF: checkstyle:magicNumber // An even number of arguments greater than 3 - if (args.length < 4 || (args.length % 2 != 0)) { + if (args.length < 7) { LOGGER.error("invalid arguments: " + Arrays.toString(args)); LOGGER.error( "usage: TestConcurrentContextJVM testType jvmNo threadCount threadLoops [parameterKey parameterJson].... "); @@ -139,6 +153,7 @@ public final class ConcurrentContextJVM { int jvmNo = -1; int threadCount = -1; int threadLoops = -1; + String hazelCastfileLocation = null; try { jvmNo = Integer.parseInt(args[1]); @@ -161,7 +176,16 @@ public final class ConcurrentContextJVM { return; } - for (int p = 4; p < args.length - 1; p += 2) { + try { + hazelCastfileLocation = args[4].trim(); + } catch (final Exception e) { + LOGGER.error("invalid argument hazelcast file location", e); + return; + } + + System.setProperty("hazelcast.config", hazelCastfileLocation); + + for (int p = 5; p < args.length - 1; p += 2) { @SuppressWarnings("rawtypes") final Class parametersClass = Class.forName(args[p]); final AbstractParameters parameters = @@ -175,12 +199,17 @@ public final class ConcurrentContextJVM { } try { - new ConcurrentContextJVM(args[0], jvmNo, threadCount, threadLoops); + final ConcurrentContextJVM concurrentContextJVM = + new ConcurrentContextJVM(args[0], jvmNo, threadCount, threadLoops); + concurrentContextJVM.execute(); + } catch (final Exception e) { LOGGER.error("error running test in JVM", e); return; } // CHECKSTYLE:ON: checkstyle:magicNumber + + } /** @@ -190,11 +219,11 @@ public final class ConcurrentContextJVM { */ public static void configure() throws Exception { System.setProperty("java.net.preferIPv4Stack", "true"); - System.setProperty("hazelcast.config", "src/test/resources/hazelcast/hazelcast.xml"); - - // The JGroups IP address must be set to a real (not loopback) IP address for Infinispan to work. IN order to + // The JGroups IP address must be set to a real (not loopback) IP address for Infinispan to + // work. IN order to // ensure that all - // the JVMs in a test pick up the same IP address, this function sets te address to be the first non-loopback + // the JVMs in a test pick up the same IP address, this function sets te address to be the + // first non-loopback // IPv4 address // on a host final TreeSet ipAddressSet = new TreeSet(); diff --git a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContextJVMThread.java b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContextJVMThread.java index da2741f7b..995772f05 100644 --- a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContextJVMThread.java +++ b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContextJVMThread.java @@ -20,9 +20,8 @@ package org.onap.policy.apex.context.test.locking; -import com.google.gson.Gson; - import java.io.BufferedReader; +import java.io.Closeable; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -36,12 +35,14 @@ import org.onap.policy.apex.model.basicmodel.service.ParameterService; import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; +import com.google.gson.Gson; + /** * The Class TestConcurrentContextThread tests concurrent use of context. * * @author Liam Fallon (liam.fallon@ericsson.com) */ -public class ConcurrentContextJVMThread implements Runnable { +public class ConcurrentContextJVMThread implements Runnable, Closeable { // Logger for this class private static final XLogger LOGGER = XLoggerFactory.getXLogger(ConcurrentContextJVMThread.class); @@ -49,6 +50,7 @@ public class ConcurrentContextJVMThread implements Runnable { private final int jvm; private final int threadCount; private final int target; + private Process process = null; /** * The Constructor. @@ -77,6 +79,8 @@ public class ConcurrentContextJVMThread implements Runnable { final List commandList = new ArrayList<>(); commandList.add(System.getProperty("java.home") + System.getProperty("file.separator") + "bin" + System.getProperty("file.separator") + "java"); + commandList.add("-Xms512m"); + commandList.add("-Xmx512m"); commandList.add("-cp"); commandList.add(System.getProperty("java.class.path")); commandList.add(ConcurrentContextJVM.class.getCanonicalName()); @@ -84,6 +88,7 @@ public class ConcurrentContextJVMThread implements Runnable { commandList.add(new Integer(jvm).toString()); commandList.add(new Integer(threadCount).toString()); commandList.add(new Integer(target).toString()); + commandList.add(System.getProperty("hazelcast.config")); for (final Entry, AbstractParameters> parameterServiceEntry : ParameterService.getAll()) { commandList.add(parameterServiceEntry.getKey().getCanonicalName()); @@ -95,7 +100,7 @@ public class ConcurrentContextJVMThread implements Runnable { // Run the JVM final ProcessBuilder processBuilder = new ProcessBuilder(commandList); processBuilder.redirectErrorStream(true); - Process process; + try { process = processBuilder.start(); @@ -121,4 +126,14 @@ public class ConcurrentContextJVMThread implements Runnable { LOGGER.error("Error occured while writing JVM Output for command ", ioException); } } + + + @Override + public void close() { + LOGGER.info("Shutting down {} thread ...", Thread.currentThread().getName()); + if (process != null) { + LOGGER.info("Destroying process ..."); + process.destroy(); + } + } } diff --git a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContextThread.java b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContextThread.java index 554c3d005..75a704557 100644 --- a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContextThread.java +++ b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContextThread.java @@ -20,6 +20,8 @@ package org.onap.policy.apex.context.test.locking; +import java.io.Closeable; + import org.onap.policy.apex.context.ContextAlbum; import org.onap.policy.apex.context.ContextException; import org.onap.policy.apex.context.Distributor; @@ -38,7 +40,8 @@ import org.slf4j.ext.XLoggerFactory; * * @author Liam Fallon (liam.fallon@ericsson.com) */ -public class ConcurrentContextThread implements Runnable { +public class ConcurrentContextThread implements Runnable, Closeable { + private static final String VALUE = "testValue"; // Logger for this class private static final XLogger LOGGER = XLoggerFactory.getXLogger(ConcurrentContextThread.class); private final Distributor distributor; @@ -108,8 +111,8 @@ public class ConcurrentContextThread implements Runnable { } try { - lTypeAlbum.lockForWriting("testValue"); - final TestContextLongItem item = (TestContextLongItem) lTypeAlbum.get("testValue"); + lTypeAlbum.lockForWriting(VALUE); + final TestContextLongItem item = (TestContextLongItem) lTypeAlbum.get(VALUE); final long value = item.getLongValue(); LOGGER.info("completed TestConcurrentContextThread_" + jvm + "_" + instance + ", value=" + value); } catch (final Exception e) { @@ -117,7 +120,7 @@ public class ConcurrentContextThread implements Runnable { LOGGER.error("failed TestConcurrentContextThread_" + jvm + "_" + instance); } finally { try { - lTypeAlbum.unlockForWriting("testValue"); + lTypeAlbum.unlockForWriting(VALUE); distributor.shutdown(); } catch (final ContextException e) { LOGGER.error("could not unlock test context album item", e); @@ -129,18 +132,23 @@ public class ConcurrentContextThread implements Runnable { private void updateAlbum(final ContextAlbum lTypeAlbum) throws Exception { for (int i = 0; i < threadLoops; i++) { try { - lTypeAlbum.lockForWriting("testValue"); - TestContextLongItem item = (TestContextLongItem) lTypeAlbum.get("testValue"); + lTypeAlbum.lockForWriting(VALUE); + TestContextLongItem item = (TestContextLongItem) lTypeAlbum.get(VALUE); if (item != null) { long value = item.getLongValue(); item.setLongValue(++value); } else { item = new TestContextLongItem(0L); } - lTypeAlbum.put("testValue", item); + lTypeAlbum.put(VALUE, item); } finally { - lTypeAlbum.unlockForWriting("testValue"); + lTypeAlbum.unlockForWriting(VALUE); } } } + + @Override + public void close() { + LOGGER.info("Shutting down {} thread ...", Thread.currentThread().getName()); + } } diff --git a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/utils/Constants.java b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/utils/Constants.java index 90e586e72..ac1e951d5 100644 --- a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/utils/Constants.java +++ b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/utils/Constants.java @@ -51,7 +51,7 @@ public class Constants { public static final String TEST_POLICY_CONTEXT_ITEM = TestPolicyContextItem.class.getName(); public static final TimeZone TIME_ZONE = TimeZone.getTimeZone("Europe/Dublin"); - public static final AxArtifactKey[] USED_ARTIFACT_STACK_ARRAY = {new AxArtifactKey("testC-top", VERSION), + public static AxArtifactKey[] USED_ARTIFACT_STACK_ARRAY = {new AxArtifactKey("testC-top", VERSION), new AxArtifactKey("testC-next", VERSION), new AxArtifactKey("testC-bot", VERSION)}; private Constants() {} diff --git a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/utils/IntegrationThreadFactory.java b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/utils/IntegrationThreadFactory.java new file mode 100644 index 000000000..b5ea84d2f --- /dev/null +++ b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/utils/IntegrationThreadFactory.java @@ -0,0 +1,48 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. All rights reserved. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.policy.apex.context.test.utils; + +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.atomic.AtomicInteger; + +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + +public class IntegrationThreadFactory implements ThreadFactory { + private static final XLogger LOGGER = XLoggerFactory.getXLogger(IntegrationThreadFactory.class); + + + private final String threadFactoryName; + + private final AtomicInteger counter = new AtomicInteger(); + + public IntegrationThreadFactory(final String threadFactoryName) { + this.threadFactoryName = threadFactoryName; + } + + @Override + public Thread newThread(final Runnable runnable) { + final Thread thread = new Thread(runnable); + thread.setName(threadFactoryName + "_" + counter.getAndIncrement()); + LOGGER.debug("started thread " + thread.getName()); + return thread; + } + +} diff --git a/packages/apex-pdp-package-full/src/main/package/bin/apexApps.bat b/packages/apex-pdp-package-full/src/main/package/bin/apexApps.bat deleted file mode 100644 index 5aba49702..000000000 --- a/packages/apex-pdp-package-full/src/main/package/bin/apexApps.bat +++ /dev/null @@ -1,183 +0,0 @@ -:: ============LICENSE_START======================================================= -:: Copyright (C) 2016-2018 Ericsson. All rights reserved. -:: ================================================================================ -:: 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. -:: -:: SPDX-License-Identifier: Apache-2.0 -:: ============LICENSE_END========================================================= - -:: -:: Script to run APEX Applications -:: Call -h for help -:: - adding a new app means to add a command to APEX_APP_MAP and a description to APEX_APP_DESCR_MAP using same/unique key -:: -:: @package org.onap.policy.apex -:: @author Sven van der Meer -:: @version v0.7.0 - -:: -:: DO NOT CHANGE CODE BELOW, unless you know what you are doing -:: - -@echo off -setlocal enableDelayedExpansion - - -if defined APEX_HOME ( - if exist "%APEX_HOME%\" ( - set _dummy=dir - ) else ( - echo[ - echo Apex directory 'APEX_HOME' not a directory - echo Please set environment for 'APEX_HOME' - echo[ - exit /b - ) -) else ( - echo[ - echo Apex directory 'APEX_HOME' not set - echo Please set environment for 'APEX_HOME' - echo[ - exit /b -) - - -:: script name for output -set MOD_SCRIPT_NAME=apexApps - -:: config for CP apps -SET _CONFIG=-Dlogback.configurationFile=%APEX_HOME%\etc\logback.xml -Dhazelcast.config=%APEX_HOME%\etc\hazelcast.xml -Dhazelcast.mancenter.enabled=false - -:: Maven/APEX version -set /p _VERSION=<%APEX_HOME%\etc\app-version.txt - - -:: CP separator -set cpsep=; - - -:: CP for CP apps -set CLASSPATH=%APEX_HOME%\etc%cpsep%%APEX_HOME%\etc\hazelcast%cpsep%%APEX_HOME%\etc\infinispan%cpsep%%APEX_HOME%\lib\* - - -:: array of applications with name=command -:: declare -A APEX_APP_MAP -set APEX_APP_MAP[ws-console]=java -jar %APEX_HOME%\lib\applications\apex-apps.wsclients-simple-%_VERSION%-jar-with-dependencies.jar -c -set APEX_APP_MAP[ws-echo]=java -jar %APEX_HOME%\lib\applications\apex-apps.wsclients-simple-%_VERSION%-jar-with-dependencies.jar -set APEX_APP_MAP[tpl-event-json]=java -Dlogback.configurationFile=%APEX_HOME%\etc\logback.xml -cp %CLASSPATH% %_CONFIG% org.onap.policy.apex.apps.generators.model.model2event.Application -set APEX_APP_MAP[model-2-cli]=java -Dlogback.configurationFile=%APEX_HOME%\etc\logback.xml -cp %CLASSPATH% %_CONFIG% org.onap.policy.apex.apps.generators.model.model2cli.Application -set APEX_APP_MAP[rest-editor]=java -Dlogback.configurationFile=%APEX_HOME%\etc\logback.xml -jar %APEX_HOME%\lib\applications\apex-services.client-editor-%_VERSION%-editor.jar -set APEX_APP_MAP[cli-editor]=java -Dlogback.configurationFile=%APEX_HOME%\etc\logback.xml -cp %CLASSPATH% %_CONFIG% org.onap.policy.apex.auth.clieditor.ApexCLIEditorMain -set APEX_APP_MAP[engine]=java -Dlogback.configurationFile=%APEX_HOME%\etc\logback.xml -cp %CLASSPATH% %_CONFIG% org.onap.policy.apex.service.engine.main.ApexMain -set APEX_APP_MAP[eng-deployment]=java -Dlogback.configurationFile=%APEX_HOME%\etc\logback.xml -jar %APEX_HOME%\lib\applications\apex-services.client-deployment-%_VERSION%-deployment.jar -set APEX_APP_MAP[eng-monitoring]=java -Dlogback.configurationFile=%APEX_HOME%\etc\logback.xml -jar %APEX_HOME%\lib\applications\apex-services.client-monitoring-%_VERSION%-monitoring.jar -set APEX_APP_MAP[full-client]=java -Dlogback.configurationFile=%APEX_HOME%\etc\logback.xml -jar %APEX_HOME%\lib\applications\apex-services.client-full-%_VERSION%-full.jar - -:: array of applications with name=description -:: declare -A APEX_APP_DESCR_MAP -set APEX_APP_DESCR_MAP[ws-console]=a simple console sending events to APEX, connect to APEX consumer port -set APEX_APP_DESCR_MAP[ws-echo]=a simple echo client printing events received from APEX, connect to APEX producer port -set APEX_APP_DESCR_MAP[tpl-event-json]=provides JSON templates for events generated from a policy model -set APEX_APP_DESCR_MAP[model-2-cli]=generates CLI Editor Commands from a policy model -set APEX_APP_DESCR_MAP[rest-editor]=starts the APEX REST Editor inside a simple webserver -set APEX_APP_DESCR_MAP[cli-editor]=runs the APEX CLI Editor -set APEX_APP_DESCR_MAP[engine]=starts the APEX engine -set APEX_APP_DESCR_MAP[eng-deployment]=starts the APEX deployment client in a simple webserver -set APEX_APP_DESCR_MAP[eng-monitoring]=starts the APEX engine monitoring client in a simple webserver -set APEX_APP_DESCR_MAP[full-client]=starts the full APEX client (rest editor, deployment, monitoring) in a simple webserver - - -:: no command line means help, -h means help -if "%1" == "" goto Help -if "%1" == "-h" goto Help - -:: -l means list -if "%1" == "-l" goto ListApps - -:: -d means describe -if "%1" == "-d" goto DescribeApp - - -:: -:: ok, we need to look for an application, should be in %1 -:: -set _APP=%1 - -set _CMD=!APEX_APP_MAP[%_APP%]! -if "!_CMD!" == "" ( - echo %MOD_SCRIPT_NAME%: : application '%_APP%' not supported - echo[ - exit /b -) - -for /f "tokens=1,* delims= " %%a in ("%*") do set ACTUAL_CLI=%%b -set _CMD_RUN=%_CMD% %ACTUAL_CLI% -:: echo %MOD_SCRIPT_NAME%: running application %_APP%' with command '%_CMD_RUN%' -%_CMD_RUN% -exit /b - - -:: -:: Help screen and exit condition (i.e. too few arguments) -:: -:Help -echo[ -echo %MOD_SCRIPT_NAME% - runs APEX applications -echo[ -echo Usage: %MOD_SCRIPT_NAME% [options] ^| [^ [^]] -echo[ -echo Options -echo -d ^ - describes an application -echo -l - lists all applications supported by this script -echo -h - this help screen -echo[ -echo[ -exit /b - - - -:: -:: List applications -:: -:ListApps -echo[ -echo %MOD_SCRIPT_NAME%: supported applications: -for /F "tokens=2,3 delims=[]=" %%a in ('set APEX_APP_MAP') do ( - echo --^> %%a -) -echo[ -exit /b - - -:: -:: Describe an application -:: -:DescribeApp -if "%2" == "" ( - echo %MOD_SCRIPT_NAME%: : supported applications: - for /F "tokens=2,3 delims=[]=" %%a in ('set APEX_APP_MAP') do ( - echo --^> %%a - ) - echo[ - exit /b -) -set _CMD=!APEX_APP_DESCR_MAP[%2%]! -if "%_CMD%" == "" ( - echo %MOD_SCRIPT_NAME%: : unknown application '%2%' - echo[ - exit /b -) -echo %MOD_SCRIPT_NAME%: : application '%2%' -echo --^> %_CMD% -echo[ -exit /b diff --git a/packages/apex-pdp-package-full/src/main/package/bin/apexApps.sh b/packages/apex-pdp-package-full/src/main/package/bin/apexApps.sh deleted file mode 100755 index adcbfcbb1..000000000 --- a/packages/apex-pdp-package-full/src/main/package/bin/apexApps.sh +++ /dev/null @@ -1,165 +0,0 @@ -#!/usr/bin/env bash - -#------------------------------------------------------------------------------- -# ============LICENSE_START======================================================= -# Copyright (C) 2016-2018 Ericsson. All rights reserved. -# ================================================================================ -# 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. -# -# SPDX-License-Identifier: Apache-2.0 -# ============LICENSE_END========================================================= -#------------------------------------------------------------------------------- - -## -## DO NOT CHANGE CODE BELOW, unless you know what you are doing -## - - -if [ -z $APEX_HOME ] -then - APEX_HOME="/opt/onap/policy/apex-pdp" -fi - -if [ ! -d $APEX_HOME ] -then - echo - echo 'Apex directory "'$APEX_HOME'" not set or not a directory' - echo "Please set environment for 'APEX_HOME'" - exit -fi - - -## script name for output -MOD_SCRIPT_NAME=`basename $0` - -## check BASH version, we need >=4 for associative arrays -if [ "${BASH_VERSION:0:1}" -lt 4 ] ; then - echo - echo "$MOD_SCRIPT_NAME: requires bash 4 or higher for associative arrays" - echo - exit -fi - -## config for CP apps -_config="-Dlogback.configurationFile=$APEX_HOME/etc/logback.xml -Dhazelcast.config=$APEX_HOME/etc/hazelcast.xml -Dhazelcast.mancenter.enabled=false" - -## Maven/APEX version -_version=`cat $APEX_HOME/etc/app-version.txt` - - -## system to get CygWin paths -system=`uname -s | cut -c1-6` -cpsep=":" -if [ "$system" == "CYGWIN" ] ; then - APEX_HOME=`cygpath -m ${APEX_HOME}` - cpsep=";" -fi - -## CP for CP apps -CLASSPATH="$APEX_HOME/etc${cpsep}$APEX_HOME/etc/hazelcast${cpsep}$APEX_HOME/etc/infinispan${cpsep}$APEX_HOME/lib/*" - - -## array of applications with name=command -declare -A APEX_APP_MAP -APEX_APP_MAP["ws-console"]="java -jar $APEX_HOME/lib/applications/apex-apps.wsclients-simple-$_version-jar-with-dependencies.jar -c" -APEX_APP_MAP["ws-echo"]="java -jar $APEX_HOME/lib/applications/apex-apps.wsclients-simple-$_version-jar-with-dependencies.jar" -APEX_APP_MAP["tpl-event-json"]="java -Dlogback.configurationFile=$APEX_HOME/etc/logback.xml -cp ${CLASSPATH} $_config org.onap.policy.apex.apps.generators.model.model2event.Application" -APEX_APP_MAP["model-2-cli"]="java -Dlogback.configurationFile=$APEX_HOME/etc/logback.xml -cp ${CLASSPATH} $_config org.onap.policy.apex.apps.generators.model.model2cli.Application" -APEX_APP_MAP["rest-editor"]="java -Dlogback.configurationFile=$APEX_HOME/etc/logback.xml -jar $APEX_HOME/lib/applications/apex-services.client-editor-$_version-editor.jar" -APEX_APP_MAP["cli-editor"]="java -Dlogback.configurationFile=$APEX_HOME/etc/logback.xml -cp ${CLASSPATH} $_config org.onap.policy.apex.auth.clieditor.ApexCLIEditorMain" -APEX_APP_MAP["engine"]="java -Dlogback.configurationFile=$APEX_HOME/etc/logback.xml -cp ${CLASSPATH} $_config org.onap.policy.apex.service.engine.main.ApexMain" -APEX_APP_MAP["eng-deployment"]="java -Dlogback.configurationFile=$APEX_HOME/etc/logback.xml -jar $APEX_HOME/lib/applications/apex-services.client-deployment-$_version-deployment.jar" -APEX_APP_MAP["eng-monitoring"]="java -Dlogback.configurationFile=$APEX_HOME/etc/logback.xml -jar $APEX_HOME/lib/applications/apex-services.client-monitoring-$_version-monitoring.jar" -APEX_APP_MAP["full-client"]="java -Dlogback.configurationFile=$APEX_HOME/etc/logback.xml -jar $APEX_HOME/lib/applications/apex-services.client-full-$_version-full.jar" - -## array of applications with name=description -declare -A APEX_APP_DESCR_MAP -APEX_APP_DESCR_MAP["ws-console"]="a simple console sending events to APEX, connect to APEX consumer port" -APEX_APP_DESCR_MAP["ws-echo"]="a simple echo client printing events received from APEX, connect to APEX producer port" -APEX_APP_DESCR_MAP["tpl-event-json"]="provides JSON templates for events generated from a policy model" -APEX_APP_DESCR_MAP["model-2-cli"]="generates CLI Editor Commands from a policy model" -APEX_APP_DESCR_MAP["rest-editor"]="starts the APEX REST Editor inside a simple webserver" -APEX_APP_DESCR_MAP["cli-editor"]="runs the APEX CLI Editor" -APEX_APP_DESCR_MAP["engine"]="starts the APEX engine" -APEX_APP_DESCR_MAP["eng-deployment"]="starts the APEX deployment client in a simple webserver" -APEX_APP_DESCR_MAP["eng-monitoring"]="starts the APEX engine monitoring client in a simple webserver" -APEX_APP_DESCR_MAP["full-client"]="starts the full APEX client (rest editor, deployment, monitoring) in a simple webserver" - -## -## Help screen and exit condition (i.e. too few arguments) -## -Help() -{ - echo "" - echo "$MOD_SCRIPT_NAME - runs APEX applications" - echo "" - echo " Usage: $MOD_SCRIPT_NAME [options] | [ []]" - echo "" - echo " Options" - echo " -d - describes an application" - echo " -l - lists all applications supported by this script" - echo " -h - this help screen" - echo "" - echo "" - exit 255; -} -if [ $# -eq 0 ]; then - Help -fi - - -## -## read command line, cannot do as while here due to 2-view CLI -## -if [ "$1" == "-l" ]; then - echo "$MOD_SCRIPT_NAME: supported applications:" - echo " --> ${!APEX_APP_MAP[@]}" - echo "" - exit 0 -fi -if [ "$1" == "-d" ]; then - if [ -z "$2" ]; then - echo "$MOD_SCRIPT_NAME: no application given to describe, supported applications:" - echo " --> ${!APEX_APP_MAP[@]}" - echo "" - exit 0; - else - _cmd=${APEX_APP_DESCR_MAP[$2]} - if [ -z "$_cmd" ]; then - echo "$MOD_SCRIPT_NAME: unknown application '$2'" - echo "" - exit 0; - fi - echo "$MOD_SCRIPT_NAME: application '$2'" - echo " --> $_cmd" - echo "" - exit 0; - fi -fi -if [ "$1" == "-h" ]; then - Help - exit 0 -fi - - -_app=$1 -shift -_cmd=${APEX_APP_MAP[$_app]} -if [ -z "$_cmd" ]; then - echo "$MOD_SCRIPT_NAME: application '$_app' not supported" - exit 1 -fi -_cmd="$_cmd $*" -## echo "$MOD_SCRIPT_NAME: running application '$_app' with command '$_cmd'" -exec $_cmd - diff --git a/packages/apex-pdp-package-full/src/main/package/bin/apexBash.sh b/packages/apex-pdp-package-full/src/main/package/bin/apexBash.sh deleted file mode 100755 index 2a201cc72..000000000 --- a/packages/apex-pdp-package-full/src/main/package/bin/apexBash.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash - -#------------------------------------------------------------------------------- -# ============LICENSE_START======================================================= -# Copyright (C) 2016-2018 Ericsson. All rights reserved. -# ================================================================================ -# 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. -# -# SPDX-License-Identifier: Apache-2.0 -# ============LICENSE_END========================================================= -#------------------------------------------------------------------------------- - -# Run from the Apex home directory -if [ ! -d /home/apexuser ] -then - echo Apex user home directory "/home/apexuser" not found - exit -fi - -# Run the command as "apexuser" -cd /home/apexuser -su apexuser diff --git a/packages/apex-pdp-package-full/src/main/package/bin/apexCLIEditor.bat b/packages/apex-pdp-package-full/src/main/package/bin/apexCLIEditor.bat deleted file mode 100644 index c4cb649bc..000000000 --- a/packages/apex-pdp-package-full/src/main/package/bin/apexCLIEditor.bat +++ /dev/null @@ -1,52 +0,0 @@ -:: ============LICENSE_START======================================================= -:: Copyright (C) 2016-2018 Ericsson. All rights reserved. -:: ================================================================================ -:: 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. -:: -:: SPDX-License-Identifier: Apache-2.0 -:: ============LICENSE_END========================================================= - -:: -:: Script to run the APEX CLI Editor -:: -:: @package org.onap.policy.apex -:: @author Sven van der Meer -:: @version v0.7.0 - -:: -:: DO NOT CHANGE CODE BELOW, unless you know what you are doing -:: - -@echo off -setlocal enableDelayedExpansion - - -if defined APEX_HOME ( - if exist "%APEX_HOME%\" ( - set _dummy=dir - ) else ( - echo[ - echo Apex directory 'APEX_HOME' not a directory - echo Please set environment for 'APEX_HOME' - echo[ - exit /b - ) -) else ( - echo[ - echo Apex directory 'APEX_HOME' not set - echo Please set environment for 'APEX_HOME' - echo[ - exit /b -) - -%APEX_HOME%\bin\apexApps.bat cli-editor %* diff --git a/packages/apex-pdp-package-full/src/main/package/bin/apexCLIEditor.sh b/packages/apex-pdp-package-full/src/main/package/bin/apexCLIEditor.sh deleted file mode 100755 index 28a26171b..000000000 --- a/packages/apex-pdp-package-full/src/main/package/bin/apexCLIEditor.sh +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/env bash - -#------------------------------------------------------------------------------- -# ============LICENSE_START======================================================= -# Copyright (C) 2016-2018 Ericsson. All rights reserved. -# ================================================================================ -# 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. -# -# SPDX-License-Identifier: Apache-2.0 -# ============LICENSE_END========================================================= -#------------------------------------------------------------------------------- - -## -## Script to run the APEX CLI Editor -## - requires BASH with associative arrays, bash of at least version 4 -## - for BASH examples with arrays see for instance: http://www.artificialworlds.net/blog/2012/10/17/bash-associative-array-examples/ -## - adding a new app means to add a command to APEX_APP_MAP and a description to APEX_APP_DESCR_MAP using same/unique key -## -## @package org.onap.policy.apex -## @author Sven van der Meer -## @version v0.7.0 - -## -## DO NOT CHANGE CODE BELOW, unless you know what you are doing -## - -if [ -z $APEX_HOME ] -then - APEX_HOME="/opt/onap/policy/apex-pdp" -fi - -if [ ! -d $APEX_HOME ] -then - echo - echo 'Apex directory "'$APEX_HOME'" not set or not a directory' - echo "Please set environment for 'APEX_HOME'" - exit -fi - -$APEX_HOME/bin/apexApps.sh cli-editor $* diff --git a/packages/apex-pdp-package-full/src/main/package/bin/apexEngine.bat b/packages/apex-pdp-package-full/src/main/package/bin/apexEngine.bat deleted file mode 100644 index d44adbbe6..000000000 --- a/packages/apex-pdp-package-full/src/main/package/bin/apexEngine.bat +++ /dev/null @@ -1,52 +0,0 @@ -:: ============LICENSE_START======================================================= -:: Copyright (C) 2016-2018 Ericsson. All rights reserved. -:: ================================================================================ -:: 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. -:: -:: SPDX-License-Identifier: Apache-2.0 -:: ============LICENSE_END========================================================= - -:: -:: Script to run the APEX -:: -:: @package org.onap.policy.apex -:: @author Sven van der Meer -:: @version v0.7.0 - -:: -:: DO NOT CHANGE CODE BELOW, unless you know what you are doing -:: - -@echo off -setlocal enableDelayedExpansion - - -if defined APEX_HOME ( - if exist "%APEX_HOME%\" ( - set _dummy=dir - ) else ( - echo[ - echo Apex directory 'APEX_HOME' not a directory - echo Please set environment for 'APEX_HOME' - echo[ - exit /b - ) -) else ( - echo[ - echo Apex directory 'APEX_HOME' not set - echo Please set environment for 'APEX_HOME' - echo[ - exit /b -) - -%APEX_HOME%\bin\apexApps.bat engine %* diff --git a/packages/apex-pdp-package-full/src/main/package/bin/apexEngine.sh b/packages/apex-pdp-package-full/src/main/package/bin/apexEngine.sh deleted file mode 100755 index c07e38b51..000000000 --- a/packages/apex-pdp-package-full/src/main/package/bin/apexEngine.sh +++ /dev/null @@ -1,73 +0,0 @@ -#!/usr/bin/env bash - -#------------------------------------------------------------------------------- -# ============LICENSE_START======================================================= -# Copyright (C) 2016-2018 Ericsson. All rights reserved. -# ================================================================================ -# 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. -# -# SPDX-License-Identifier: Apache-2.0 -# ============LICENSE_END========================================================= -#------------------------------------------------------------------------------- - -## -## Script to run the APEX -## - requires BASH with associative arrays, bash of at least version 4 -## - for BASH examples with arrays see for instance: http://www.artificialworlds.net/blog/2012/10/17/bash-associative-array-examples/ -## - adding a new app means to add a command to APEX_APP_MAP and a description to APEX_APP_DESCR_MAP using same/unique key -## -## @package org.onap.policy.apex -## @author Sven van der Meer -## @version v0.7.0 - -## -## DO NOT CHANGE CODE BELOW, unless you know what you are doing -## - -if [ -z $APEX_USER ] -then - APEX_USER="apexuser" -fi - -id $APEX_USER > /dev/null 2>& 1 -if [ "$?" -ne "0" ] -then - echo 'cannot run apex, user "'$APEX_USER'" does not exit' - exit -fi - -if [ $(whoami) != "$APEX_USER" ] -then - echo 'Apex must be run as user "'$APEX_USER'"' - exit -fi - -if [ -z $APEX_HOME ] -then - APEX_HOME="/opt/onap/policy/apex-pdp" -fi - -if [ ! -d $APEX_HOME ] -then - echo - echo 'Apex directory "'$APEX_HOME'" not set or not a directory' - echo "Please set environment for 'APEX_HOME'" - exit -fi - -if [ $(whoami) == "$APEX_USER" ] -then - $APEX_HOME/bin/apexApps.sh engine $* -else - su $APEX_USER -c "$APEX_HOME/bin/apexApps.sh engine $*" -fi diff --git a/packages/apex-pdp-package-full/src/main/package/bin/apexRESTEditor.bat b/packages/apex-pdp-package-full/src/main/package/bin/apexRESTEditor.bat deleted file mode 100644 index 69ada95bf..000000000 --- a/packages/apex-pdp-package-full/src/main/package/bin/apexRESTEditor.bat +++ /dev/null @@ -1,52 +0,0 @@ -:: ============LICENSE_START======================================================= -:: Copyright (C) 2016-2018 Ericsson. All rights reserved. -:: ================================================================================ -:: 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. -:: -:: SPDX-License-Identifier: Apache-2.0 -:: ============LICENSE_END========================================================= - -:: -:: Script to run the APEX REST Editor -:: -:: @package org.onap.policy.apex -:: @author Sven van der Meer -:: @version v0.7.0 - -:: -:: DO NOT CHANGE CODE BELOW, unless you know what you are doing -:: - -@echo off -setlocal enableDelayedExpansion - - -if defined APEX_HOME ( - if exist "%APEX_HOME%\" ( - set _dummy=dir - ) else ( - echo[ - echo Apex directory 'APEX_HOME' not a directory - echo Please set environment for 'APEX_HOME' - echo[ - exit /b - ) -) else ( - echo[ - echo Apex directory 'APEX_HOME' not set - echo Please set environment for 'APEX_HOME' - echo[ - exit /b -) - -%APEX_HOME%\bin\apexApps.bat rest-editor %* diff --git a/packages/apex-pdp-package-full/src/main/package/bin/apexRESTEditor.sh b/packages/apex-pdp-package-full/src/main/package/bin/apexRESTEditor.sh deleted file mode 100755 index 3f2ae867b..000000000 --- a/packages/apex-pdp-package-full/src/main/package/bin/apexRESTEditor.sh +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/env bash - -#------------------------------------------------------------------------------- -# ============LICENSE_START======================================================= -# Copyright (C) 2016-2018 Ericsson. All rights reserved. -# ================================================================================ -# 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. -# -# SPDX-License-Identifier: Apache-2.0 -# ============LICENSE_END========================================================= -#------------------------------------------------------------------------------- - -## -## Script to run the APEX REST Editor -## - requires BASH with associative arrays, bash of at least version 4 -## - for BASH examples with arrays see for instance: http://www.artificialworlds.net/blog/2012/10/17/bash-associative-array-examples/ -## - adding a new app means to add a command to APEX_APP_MAP and a description to APEX_APP_DESCR_MAP using same/unique key -## -## @package org.onap.policy.apex -## @author Sven van der Meer -## @version v0.7.0 - -## -## DO NOT CHANGE CODE BELOW, unless you know what you are doing -## - - -if [ -z $APEX_HOME ] -then - APEX_HOME="/opt/onap/policy/apex-pdp" -fi - -if [ ! -d $APEX_HOME ] -then - echo - echo 'Apex directory "'$APEX_HOME'" not set or not a directory' - echo "Please set environment for 'APEX_HOME'" - exit -fi - -$APEX_HOME/bin/apexApps.sh rest-editor $* diff --git a/packages/apex-pdp-package-full/src/main/package/scripts/apexApps.bat b/packages/apex-pdp-package-full/src/main/package/scripts/apexApps.bat new file mode 100644 index 000000000..5aba49702 --- /dev/null +++ b/packages/apex-pdp-package-full/src/main/package/scripts/apexApps.bat @@ -0,0 +1,183 @@ +:: ============LICENSE_START======================================================= +:: Copyright (C) 2016-2018 Ericsson. All rights reserved. +:: ================================================================================ +:: 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. +:: +:: SPDX-License-Identifier: Apache-2.0 +:: ============LICENSE_END========================================================= + +:: +:: Script to run APEX Applications +:: Call -h for help +:: - adding a new app means to add a command to APEX_APP_MAP and a description to APEX_APP_DESCR_MAP using same/unique key +:: +:: @package org.onap.policy.apex +:: @author Sven van der Meer +:: @version v0.7.0 + +:: +:: DO NOT CHANGE CODE BELOW, unless you know what you are doing +:: + +@echo off +setlocal enableDelayedExpansion + + +if defined APEX_HOME ( + if exist "%APEX_HOME%\" ( + set _dummy=dir + ) else ( + echo[ + echo Apex directory 'APEX_HOME' not a directory + echo Please set environment for 'APEX_HOME' + echo[ + exit /b + ) +) else ( + echo[ + echo Apex directory 'APEX_HOME' not set + echo Please set environment for 'APEX_HOME' + echo[ + exit /b +) + + +:: script name for output +set MOD_SCRIPT_NAME=apexApps + +:: config for CP apps +SET _CONFIG=-Dlogback.configurationFile=%APEX_HOME%\etc\logback.xml -Dhazelcast.config=%APEX_HOME%\etc\hazelcast.xml -Dhazelcast.mancenter.enabled=false + +:: Maven/APEX version +set /p _VERSION=<%APEX_HOME%\etc\app-version.txt + + +:: CP separator +set cpsep=; + + +:: CP for CP apps +set CLASSPATH=%APEX_HOME%\etc%cpsep%%APEX_HOME%\etc\hazelcast%cpsep%%APEX_HOME%\etc\infinispan%cpsep%%APEX_HOME%\lib\* + + +:: array of applications with name=command +:: declare -A APEX_APP_MAP +set APEX_APP_MAP[ws-console]=java -jar %APEX_HOME%\lib\applications\apex-apps.wsclients-simple-%_VERSION%-jar-with-dependencies.jar -c +set APEX_APP_MAP[ws-echo]=java -jar %APEX_HOME%\lib\applications\apex-apps.wsclients-simple-%_VERSION%-jar-with-dependencies.jar +set APEX_APP_MAP[tpl-event-json]=java -Dlogback.configurationFile=%APEX_HOME%\etc\logback.xml -cp %CLASSPATH% %_CONFIG% org.onap.policy.apex.apps.generators.model.model2event.Application +set APEX_APP_MAP[model-2-cli]=java -Dlogback.configurationFile=%APEX_HOME%\etc\logback.xml -cp %CLASSPATH% %_CONFIG% org.onap.policy.apex.apps.generators.model.model2cli.Application +set APEX_APP_MAP[rest-editor]=java -Dlogback.configurationFile=%APEX_HOME%\etc\logback.xml -jar %APEX_HOME%\lib\applications\apex-services.client-editor-%_VERSION%-editor.jar +set APEX_APP_MAP[cli-editor]=java -Dlogback.configurationFile=%APEX_HOME%\etc\logback.xml -cp %CLASSPATH% %_CONFIG% org.onap.policy.apex.auth.clieditor.ApexCLIEditorMain +set APEX_APP_MAP[engine]=java -Dlogback.configurationFile=%APEX_HOME%\etc\logback.xml -cp %CLASSPATH% %_CONFIG% org.onap.policy.apex.service.engine.main.ApexMain +set APEX_APP_MAP[eng-deployment]=java -Dlogback.configurationFile=%APEX_HOME%\etc\logback.xml -jar %APEX_HOME%\lib\applications\apex-services.client-deployment-%_VERSION%-deployment.jar +set APEX_APP_MAP[eng-monitoring]=java -Dlogback.configurationFile=%APEX_HOME%\etc\logback.xml -jar %APEX_HOME%\lib\applications\apex-services.client-monitoring-%_VERSION%-monitoring.jar +set APEX_APP_MAP[full-client]=java -Dlogback.configurationFile=%APEX_HOME%\etc\logback.xml -jar %APEX_HOME%\lib\applications\apex-services.client-full-%_VERSION%-full.jar + +:: array of applications with name=description +:: declare -A APEX_APP_DESCR_MAP +set APEX_APP_DESCR_MAP[ws-console]=a simple console sending events to APEX, connect to APEX consumer port +set APEX_APP_DESCR_MAP[ws-echo]=a simple echo client printing events received from APEX, connect to APEX producer port +set APEX_APP_DESCR_MAP[tpl-event-json]=provides JSON templates for events generated from a policy model +set APEX_APP_DESCR_MAP[model-2-cli]=generates CLI Editor Commands from a policy model +set APEX_APP_DESCR_MAP[rest-editor]=starts the APEX REST Editor inside a simple webserver +set APEX_APP_DESCR_MAP[cli-editor]=runs the APEX CLI Editor +set APEX_APP_DESCR_MAP[engine]=starts the APEX engine +set APEX_APP_DESCR_MAP[eng-deployment]=starts the APEX deployment client in a simple webserver +set APEX_APP_DESCR_MAP[eng-monitoring]=starts the APEX engine monitoring client in a simple webserver +set APEX_APP_DESCR_MAP[full-client]=starts the full APEX client (rest editor, deployment, monitoring) in a simple webserver + + +:: no command line means help, -h means help +if "%1" == "" goto Help +if "%1" == "-h" goto Help + +:: -l means list +if "%1" == "-l" goto ListApps + +:: -d means describe +if "%1" == "-d" goto DescribeApp + + +:: +:: ok, we need to look for an application, should be in %1 +:: +set _APP=%1 + +set _CMD=!APEX_APP_MAP[%_APP%]! +if "!_CMD!" == "" ( + echo %MOD_SCRIPT_NAME%: : application '%_APP%' not supported + echo[ + exit /b +) + +for /f "tokens=1,* delims= " %%a in ("%*") do set ACTUAL_CLI=%%b +set _CMD_RUN=%_CMD% %ACTUAL_CLI% +:: echo %MOD_SCRIPT_NAME%: running application %_APP%' with command '%_CMD_RUN%' +%_CMD_RUN% +exit /b + + +:: +:: Help screen and exit condition (i.e. too few arguments) +:: +:Help +echo[ +echo %MOD_SCRIPT_NAME% - runs APEX applications +echo[ +echo Usage: %MOD_SCRIPT_NAME% [options] ^| [^ [^]] +echo[ +echo Options +echo -d ^ - describes an application +echo -l - lists all applications supported by this script +echo -h - this help screen +echo[ +echo[ +exit /b + + + +:: +:: List applications +:: +:ListApps +echo[ +echo %MOD_SCRIPT_NAME%: supported applications: +for /F "tokens=2,3 delims=[]=" %%a in ('set APEX_APP_MAP') do ( + echo --^> %%a +) +echo[ +exit /b + + +:: +:: Describe an application +:: +:DescribeApp +if "%2" == "" ( + echo %MOD_SCRIPT_NAME%: : supported applications: + for /F "tokens=2,3 delims=[]=" %%a in ('set APEX_APP_MAP') do ( + echo --^> %%a + ) + echo[ + exit /b +) +set _CMD=!APEX_APP_DESCR_MAP[%2%]! +if "%_CMD%" == "" ( + echo %MOD_SCRIPT_NAME%: : unknown application '%2%' + echo[ + exit /b +) +echo %MOD_SCRIPT_NAME%: : application '%2%' +echo --^> %_CMD% +echo[ +exit /b diff --git a/packages/apex-pdp-package-full/src/main/package/scripts/apexApps.sh b/packages/apex-pdp-package-full/src/main/package/scripts/apexApps.sh new file mode 100755 index 000000000..adcbfcbb1 --- /dev/null +++ b/packages/apex-pdp-package-full/src/main/package/scripts/apexApps.sh @@ -0,0 +1,165 @@ +#!/usr/bin/env bash + +#------------------------------------------------------------------------------- +# ============LICENSE_START======================================================= +# Copyright (C) 2016-2018 Ericsson. All rights reserved. +# ================================================================================ +# 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. +# +# SPDX-License-Identifier: Apache-2.0 +# ============LICENSE_END========================================================= +#------------------------------------------------------------------------------- + +## +## DO NOT CHANGE CODE BELOW, unless you know what you are doing +## + + +if [ -z $APEX_HOME ] +then + APEX_HOME="/opt/onap/policy/apex-pdp" +fi + +if [ ! -d $APEX_HOME ] +then + echo + echo 'Apex directory "'$APEX_HOME'" not set or not a directory' + echo "Please set environment for 'APEX_HOME'" + exit +fi + + +## script name for output +MOD_SCRIPT_NAME=`basename $0` + +## check BASH version, we need >=4 for associative arrays +if [ "${BASH_VERSION:0:1}" -lt 4 ] ; then + echo + echo "$MOD_SCRIPT_NAME: requires bash 4 or higher for associative arrays" + echo + exit +fi + +## config for CP apps +_config="-Dlogback.configurationFile=$APEX_HOME/etc/logback.xml -Dhazelcast.config=$APEX_HOME/etc/hazelcast.xml -Dhazelcast.mancenter.enabled=false" + +## Maven/APEX version +_version=`cat $APEX_HOME/etc/app-version.txt` + + +## system to get CygWin paths +system=`uname -s | cut -c1-6` +cpsep=":" +if [ "$system" == "CYGWIN" ] ; then + APEX_HOME=`cygpath -m ${APEX_HOME}` + cpsep=";" +fi + +## CP for CP apps +CLASSPATH="$APEX_HOME/etc${cpsep}$APEX_HOME/etc/hazelcast${cpsep}$APEX_HOME/etc/infinispan${cpsep}$APEX_HOME/lib/*" + + +## array of applications with name=command +declare -A APEX_APP_MAP +APEX_APP_MAP["ws-console"]="java -jar $APEX_HOME/lib/applications/apex-apps.wsclients-simple-$_version-jar-with-dependencies.jar -c" +APEX_APP_MAP["ws-echo"]="java -jar $APEX_HOME/lib/applications/apex-apps.wsclients-simple-$_version-jar-with-dependencies.jar" +APEX_APP_MAP["tpl-event-json"]="java -Dlogback.configurationFile=$APEX_HOME/etc/logback.xml -cp ${CLASSPATH} $_config org.onap.policy.apex.apps.generators.model.model2event.Application" +APEX_APP_MAP["model-2-cli"]="java -Dlogback.configurationFile=$APEX_HOME/etc/logback.xml -cp ${CLASSPATH} $_config org.onap.policy.apex.apps.generators.model.model2cli.Application" +APEX_APP_MAP["rest-editor"]="java -Dlogback.configurationFile=$APEX_HOME/etc/logback.xml -jar $APEX_HOME/lib/applications/apex-services.client-editor-$_version-editor.jar" +APEX_APP_MAP["cli-editor"]="java -Dlogback.configurationFile=$APEX_HOME/etc/logback.xml -cp ${CLASSPATH} $_config org.onap.policy.apex.auth.clieditor.ApexCLIEditorMain" +APEX_APP_MAP["engine"]="java -Dlogback.configurationFile=$APEX_HOME/etc/logback.xml -cp ${CLASSPATH} $_config org.onap.policy.apex.service.engine.main.ApexMain" +APEX_APP_MAP["eng-deployment"]="java -Dlogback.configurationFile=$APEX_HOME/etc/logback.xml -jar $APEX_HOME/lib/applications/apex-services.client-deployment-$_version-deployment.jar" +APEX_APP_MAP["eng-monitoring"]="java -Dlogback.configurationFile=$APEX_HOME/etc/logback.xml -jar $APEX_HOME/lib/applications/apex-services.client-monitoring-$_version-monitoring.jar" +APEX_APP_MAP["full-client"]="java -Dlogback.configurationFile=$APEX_HOME/etc/logback.xml -jar $APEX_HOME/lib/applications/apex-services.client-full-$_version-full.jar" + +## array of applications with name=description +declare -A APEX_APP_DESCR_MAP +APEX_APP_DESCR_MAP["ws-console"]="a simple console sending events to APEX, connect to APEX consumer port" +APEX_APP_DESCR_MAP["ws-echo"]="a simple echo client printing events received from APEX, connect to APEX producer port" +APEX_APP_DESCR_MAP["tpl-event-json"]="provides JSON templates for events generated from a policy model" +APEX_APP_DESCR_MAP["model-2-cli"]="generates CLI Editor Commands from a policy model" +APEX_APP_DESCR_MAP["rest-editor"]="starts the APEX REST Editor inside a simple webserver" +APEX_APP_DESCR_MAP["cli-editor"]="runs the APEX CLI Editor" +APEX_APP_DESCR_MAP["engine"]="starts the APEX engine" +APEX_APP_DESCR_MAP["eng-deployment"]="starts the APEX deployment client in a simple webserver" +APEX_APP_DESCR_MAP["eng-monitoring"]="starts the APEX engine monitoring client in a simple webserver" +APEX_APP_DESCR_MAP["full-client"]="starts the full APEX client (rest editor, deployment, monitoring) in a simple webserver" + +## +## Help screen and exit condition (i.e. too few arguments) +## +Help() +{ + echo "" + echo "$MOD_SCRIPT_NAME - runs APEX applications" + echo "" + echo " Usage: $MOD_SCRIPT_NAME [options] | [ []]" + echo "" + echo " Options" + echo " -d - describes an application" + echo " -l - lists all applications supported by this script" + echo " -h - this help screen" + echo "" + echo "" + exit 255; +} +if [ $# -eq 0 ]; then + Help +fi + + +## +## read command line, cannot do as while here due to 2-view CLI +## +if [ "$1" == "-l" ]; then + echo "$MOD_SCRIPT_NAME: supported applications:" + echo " --> ${!APEX_APP_MAP[@]}" + echo "" + exit 0 +fi +if [ "$1" == "-d" ]; then + if [ -z "$2" ]; then + echo "$MOD_SCRIPT_NAME: no application given to describe, supported applications:" + echo " --> ${!APEX_APP_MAP[@]}" + echo "" + exit 0; + else + _cmd=${APEX_APP_DESCR_MAP[$2]} + if [ -z "$_cmd" ]; then + echo "$MOD_SCRIPT_NAME: unknown application '$2'" + echo "" + exit 0; + fi + echo "$MOD_SCRIPT_NAME: application '$2'" + echo " --> $_cmd" + echo "" + exit 0; + fi +fi +if [ "$1" == "-h" ]; then + Help + exit 0 +fi + + +_app=$1 +shift +_cmd=${APEX_APP_MAP[$_app]} +if [ -z "$_cmd" ]; then + echo "$MOD_SCRIPT_NAME: application '$_app' not supported" + exit 1 +fi +_cmd="$_cmd $*" +## echo "$MOD_SCRIPT_NAME: running application '$_app' with command '$_cmd'" +exec $_cmd + diff --git a/packages/apex-pdp-package-full/src/main/package/scripts/apexBash.sh b/packages/apex-pdp-package-full/src/main/package/scripts/apexBash.sh new file mode 100755 index 000000000..2a201cc72 --- /dev/null +++ b/packages/apex-pdp-package-full/src/main/package/scripts/apexBash.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +#------------------------------------------------------------------------------- +# ============LICENSE_START======================================================= +# Copyright (C) 2016-2018 Ericsson. All rights reserved. +# ================================================================================ +# 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. +# +# SPDX-License-Identifier: Apache-2.0 +# ============LICENSE_END========================================================= +#------------------------------------------------------------------------------- + +# Run from the Apex home directory +if [ ! -d /home/apexuser ] +then + echo Apex user home directory "/home/apexuser" not found + exit +fi + +# Run the command as "apexuser" +cd /home/apexuser +su apexuser diff --git a/packages/apex-pdp-package-full/src/main/package/scripts/apexCLIEditor.bat b/packages/apex-pdp-package-full/src/main/package/scripts/apexCLIEditor.bat new file mode 100644 index 000000000..c4cb649bc --- /dev/null +++ b/packages/apex-pdp-package-full/src/main/package/scripts/apexCLIEditor.bat @@ -0,0 +1,52 @@ +:: ============LICENSE_START======================================================= +:: Copyright (C) 2016-2018 Ericsson. All rights reserved. +:: ================================================================================ +:: 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. +:: +:: SPDX-License-Identifier: Apache-2.0 +:: ============LICENSE_END========================================================= + +:: +:: Script to run the APEX CLI Editor +:: +:: @package org.onap.policy.apex +:: @author Sven van der Meer +:: @version v0.7.0 + +:: +:: DO NOT CHANGE CODE BELOW, unless you know what you are doing +:: + +@echo off +setlocal enableDelayedExpansion + + +if defined APEX_HOME ( + if exist "%APEX_HOME%\" ( + set _dummy=dir + ) else ( + echo[ + echo Apex directory 'APEX_HOME' not a directory + echo Please set environment for 'APEX_HOME' + echo[ + exit /b + ) +) else ( + echo[ + echo Apex directory 'APEX_HOME' not set + echo Please set environment for 'APEX_HOME' + echo[ + exit /b +) + +%APEX_HOME%\bin\apexApps.bat cli-editor %* diff --git a/packages/apex-pdp-package-full/src/main/package/scripts/apexCLIEditor.sh b/packages/apex-pdp-package-full/src/main/package/scripts/apexCLIEditor.sh new file mode 100755 index 000000000..28a26171b --- /dev/null +++ b/packages/apex-pdp-package-full/src/main/package/scripts/apexCLIEditor.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env bash + +#------------------------------------------------------------------------------- +# ============LICENSE_START======================================================= +# Copyright (C) 2016-2018 Ericsson. All rights reserved. +# ================================================================================ +# 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. +# +# SPDX-License-Identifier: Apache-2.0 +# ============LICENSE_END========================================================= +#------------------------------------------------------------------------------- + +## +## Script to run the APEX CLI Editor +## - requires BASH with associative arrays, bash of at least version 4 +## - for BASH examples with arrays see for instance: http://www.artificialworlds.net/blog/2012/10/17/bash-associative-array-examples/ +## - adding a new app means to add a command to APEX_APP_MAP and a description to APEX_APP_DESCR_MAP using same/unique key +## +## @package org.onap.policy.apex +## @author Sven van der Meer +## @version v0.7.0 + +## +## DO NOT CHANGE CODE BELOW, unless you know what you are doing +## + +if [ -z $APEX_HOME ] +then + APEX_HOME="/opt/onap/policy/apex-pdp" +fi + +if [ ! -d $APEX_HOME ] +then + echo + echo 'Apex directory "'$APEX_HOME'" not set or not a directory' + echo "Please set environment for 'APEX_HOME'" + exit +fi + +$APEX_HOME/bin/apexApps.sh cli-editor $* diff --git a/packages/apex-pdp-package-full/src/main/package/scripts/apexEngine.bat b/packages/apex-pdp-package-full/src/main/package/scripts/apexEngine.bat new file mode 100644 index 000000000..d44adbbe6 --- /dev/null +++ b/packages/apex-pdp-package-full/src/main/package/scripts/apexEngine.bat @@ -0,0 +1,52 @@ +:: ============LICENSE_START======================================================= +:: Copyright (C) 2016-2018 Ericsson. All rights reserved. +:: ================================================================================ +:: 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. +:: +:: SPDX-License-Identifier: Apache-2.0 +:: ============LICENSE_END========================================================= + +:: +:: Script to run the APEX +:: +:: @package org.onap.policy.apex +:: @author Sven van der Meer +:: @version v0.7.0 + +:: +:: DO NOT CHANGE CODE BELOW, unless you know what you are doing +:: + +@echo off +setlocal enableDelayedExpansion + + +if defined APEX_HOME ( + if exist "%APEX_HOME%\" ( + set _dummy=dir + ) else ( + echo[ + echo Apex directory 'APEX_HOME' not a directory + echo Please set environment for 'APEX_HOME' + echo[ + exit /b + ) +) else ( + echo[ + echo Apex directory 'APEX_HOME' not set + echo Please set environment for 'APEX_HOME' + echo[ + exit /b +) + +%APEX_HOME%\bin\apexApps.bat engine %* diff --git a/packages/apex-pdp-package-full/src/main/package/scripts/apexEngine.sh b/packages/apex-pdp-package-full/src/main/package/scripts/apexEngine.sh new file mode 100755 index 000000000..c07e38b51 --- /dev/null +++ b/packages/apex-pdp-package-full/src/main/package/scripts/apexEngine.sh @@ -0,0 +1,73 @@ +#!/usr/bin/env bash + +#------------------------------------------------------------------------------- +# ============LICENSE_START======================================================= +# Copyright (C) 2016-2018 Ericsson. All rights reserved. +# ================================================================================ +# 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. +# +# SPDX-License-Identifier: Apache-2.0 +# ============LICENSE_END========================================================= +#------------------------------------------------------------------------------- + +## +## Script to run the APEX +## - requires BASH with associative arrays, bash of at least version 4 +## - for BASH examples with arrays see for instance: http://www.artificialworlds.net/blog/2012/10/17/bash-associative-array-examples/ +## - adding a new app means to add a command to APEX_APP_MAP and a description to APEX_APP_DESCR_MAP using same/unique key +## +## @package org.onap.policy.apex +## @author Sven van der Meer +## @version v0.7.0 + +## +## DO NOT CHANGE CODE BELOW, unless you know what you are doing +## + +if [ -z $APEX_USER ] +then + APEX_USER="apexuser" +fi + +id $APEX_USER > /dev/null 2>& 1 +if [ "$?" -ne "0" ] +then + echo 'cannot run apex, user "'$APEX_USER'" does not exit' + exit +fi + +if [ $(whoami) != "$APEX_USER" ] +then + echo 'Apex must be run as user "'$APEX_USER'"' + exit +fi + +if [ -z $APEX_HOME ] +then + APEX_HOME="/opt/onap/policy/apex-pdp" +fi + +if [ ! -d $APEX_HOME ] +then + echo + echo 'Apex directory "'$APEX_HOME'" not set or not a directory' + echo "Please set environment for 'APEX_HOME'" + exit +fi + +if [ $(whoami) == "$APEX_USER" ] +then + $APEX_HOME/bin/apexApps.sh engine $* +else + su $APEX_USER -c "$APEX_HOME/bin/apexApps.sh engine $*" +fi diff --git a/packages/apex-pdp-package-full/src/main/package/scripts/apexRESTEditor.bat b/packages/apex-pdp-package-full/src/main/package/scripts/apexRESTEditor.bat new file mode 100644 index 000000000..69ada95bf --- /dev/null +++ b/packages/apex-pdp-package-full/src/main/package/scripts/apexRESTEditor.bat @@ -0,0 +1,52 @@ +:: ============LICENSE_START======================================================= +:: Copyright (C) 2016-2018 Ericsson. All rights reserved. +:: ================================================================================ +:: 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. +:: +:: SPDX-License-Identifier: Apache-2.0 +:: ============LICENSE_END========================================================= + +:: +:: Script to run the APEX REST Editor +:: +:: @package org.onap.policy.apex +:: @author Sven van der Meer +:: @version v0.7.0 + +:: +:: DO NOT CHANGE CODE BELOW, unless you know what you are doing +:: + +@echo off +setlocal enableDelayedExpansion + + +if defined APEX_HOME ( + if exist "%APEX_HOME%\" ( + set _dummy=dir + ) else ( + echo[ + echo Apex directory 'APEX_HOME' not a directory + echo Please set environment for 'APEX_HOME' + echo[ + exit /b + ) +) else ( + echo[ + echo Apex directory 'APEX_HOME' not set + echo Please set environment for 'APEX_HOME' + echo[ + exit /b +) + +%APEX_HOME%\bin\apexApps.bat rest-editor %* diff --git a/packages/apex-pdp-package-full/src/main/package/scripts/apexRESTEditor.sh b/packages/apex-pdp-package-full/src/main/package/scripts/apexRESTEditor.sh new file mode 100755 index 000000000..3f2ae867b --- /dev/null +++ b/packages/apex-pdp-package-full/src/main/package/scripts/apexRESTEditor.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash + +#------------------------------------------------------------------------------- +# ============LICENSE_START======================================================= +# Copyright (C) 2016-2018 Ericsson. All rights reserved. +# ================================================================================ +# 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. +# +# SPDX-License-Identifier: Apache-2.0 +# ============LICENSE_END========================================================= +#------------------------------------------------------------------------------- + +## +## Script to run the APEX REST Editor +## - requires BASH with associative arrays, bash of at least version 4 +## - for BASH examples with arrays see for instance: http://www.artificialworlds.net/blog/2012/10/17/bash-associative-array-examples/ +## - adding a new app means to add a command to APEX_APP_MAP and a description to APEX_APP_DESCR_MAP using same/unique key +## +## @package org.onap.policy.apex +## @author Sven van der Meer +## @version v0.7.0 + +## +## DO NOT CHANGE CODE BELOW, unless you know what you are doing +## + + +if [ -z $APEX_HOME ] +then + APEX_HOME="/opt/onap/policy/apex-pdp" +fi + +if [ ! -d $APEX_HOME ] +then + echo + echo 'Apex directory "'$APEX_HOME'" not set or not a directory' + echo "Please set environment for 'APEX_HOME'" + exit +fi + +$APEX_HOME/bin/apexApps.sh rest-editor $* diff --git a/packages/apex-pdp-package-full/src/main/package/tarball/assembly.xml b/packages/apex-pdp-package-full/src/main/package/tarball/assembly.xml index 79ad9e11c..cd242f33c 100644 --- a/packages/apex-pdp-package-full/src/main/package/tarball/assembly.xml +++ b/packages/apex-pdp-package-full/src/main/package/tarball/assembly.xml @@ -45,7 +45,7 @@ - ${project.basedir}/src/main/package/bin + ${project.basedir}/src/main/package/scripts * diff --git a/testsuites/integration/integration-context-test/src/test/java/org/onap/policy/apex/plugins/context/test/locking/TestConcurrentContext.java b/testsuites/integration/integration-context-test/src/test/java/org/onap/policy/apex/plugins/context/test/locking/TestConcurrentContext.java index 7a3a29cc1..e2c2de97a 100644 --- a/testsuites/integration/integration-context-test/src/test/java/org/onap/policy/apex/plugins/context/test/locking/TestConcurrentContext.java +++ b/testsuites/integration/integration-context-test/src/test/java/org/onap/policy/apex/plugins/context/test/locking/TestConcurrentContext.java @@ -48,6 +48,7 @@ import org.onap.policy.apex.context.test.locking.ConcurrentContext; import org.onap.policy.apex.model.basicmodel.concepts.ApexException; import org.onap.policy.apex.model.basicmodel.handling.ApexModelException; import org.onap.policy.apex.model.basicmodel.service.ParameterService; +import org.onap.policy.apex.model.utilities.ResourceUtils; import org.onap.policy.apex.plugins.context.distribution.hazelcast.HazelcastContextDistributor; import org.onap.policy.apex.plugins.context.distribution.infinispan.InfinispanContextDistributor; import org.onap.policy.apex.plugins.context.distribution.infinispan.InfinispanDistributorParameters; @@ -65,6 +66,11 @@ import com.hazelcast.config.Config; * @author Liam Fallon (liam.fallon@ericsson.com) */ public class TestConcurrentContext { + private static final String HAZELCAST_CONFIG = "hazelcast.config"; + + private static final String JAVA_NET_PREFER_IPV4_STACK = "java.net.preferIPv4Stack"; + private static final String HAZELCAST_XML_FILE = "src/test/resources/hazelcast/hazelcast.xml"; + // Logger for this class private static final XLogger logger = XLoggerFactory.getXLogger(TestConcurrentContext.class); @@ -89,8 +95,9 @@ public class TestConcurrentContext { @BeforeClass public static void configure() throws Exception { - System.setProperty("java.net.preferIPv4Stack", "true"); - System.setProperty("hazelcast.config", "src/test/resources/hazelcast/hazelcast.xml"); + System.setProperty(JAVA_NET_PREFER_IPV4_STACK, "true"); + final String hazelCastfileLocation = ResourceUtils.getFilePath4Resource(HAZELCAST_XML_FILE); + System.setProperty(HAZELCAST_CONFIG, hazelCastfileLocation); // The JGroups IP address must be set to a real (not loopback) IP address for Infinispan to // work. IN order to ensure that all diff --git a/testsuites/integration/integration-context-test/src/test/resources/hazelcast/hazelcast.xml b/testsuites/integration/integration-context-test/src/test/resources/hazelcast/hazelcast.xml index d69f24b90..2918909c3 100644 --- a/testsuites/integration/integration-context-test/src/test/resources/hazelcast/hazelcast.xml +++ b/testsuites/integration/integration-context-test/src/test/resources/hazelcast/hazelcast.xml @@ -41,14 +41,23 @@ - true + false slf4j false 60 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 - 16 + 2 diff --git a/testsuites/integration/integration-context-test/src/test/resources/logback-test.xml b/testsuites/integration/integration-context-test/src/test/resources/logback-test.xml deleted file mode 100644 index 7fd818d4b..000000000 --- a/testsuites/integration/integration-context-test/src/test/resources/logback-test.xml +++ /dev/null @@ -1,76 +0,0 @@ - - - - - Apex - - - - - - - %d %contextName [%t] %level %logger{36} - %msg%n - - - - - - - - - ${LOG_DIR}/apex.log - - %d %-5relative [procId=${processId}] [%thread] %-5level - %logger{26} - %msg %n %ex{full} - - - - - ${LOG_DIR}/apex_ctxt.log - - %d %-5relative [procId=${processId}] [%thread] %-5level - %logger{26} - %msg %n %ex{full} - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/kafka/TestKafka2Kafka.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/kafka/TestKafka2Kafka.java index 0874d9827..8468b6d7f 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/kafka/TestKafka2Kafka.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/kafka/TestKafka2Kafka.java @@ -91,9 +91,15 @@ public class TestKafka2Kafka { @AfterClass public static void shutdownDummyKafkaServer() throws IOException { - kafkaServer.shutdown(); - zkClient.close(); - zkServer.shutdown(); + if (kafkaServer != null) { + kafkaServer.shutdown(); + } + if (zkClient != null) { + zkClient.close(); + } + if (zkServer != null) { + zkServer.shutdown(); + } } @Test -- cgit 1.2.3-korg