aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJohnKeeney <John.Keeney@est.tech>2019-07-02 15:50:56 +0000
committerJohnKeeney <John.Keeney@est.tech>2019-07-02 15:50:56 +0000
commit9f0678f3ab333949076b5b9747158cf40e08fbef (patch)
tree6cd31546cbbda461eb90518df0af867ccf0066bd /core
parent791ef7832edc7478ec344ed47c90aa5826e95b8e (diff)
ApexPDP: Fixed jenkin failure in Nordix
getLocalHost() fails in Nordix jenkins test build - misconfiguration of nordix jenkins vms/containers Change-Id: I726fc141ced07f15cfaa8a9815b4d090dbb74c9a Issue-ID: POLICY-1879 Signed-off-by: JohnKeeney <John.Keeney@est.tech>
Diffstat (limited to 'core')
-rw-r--r--core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/DeploymentClient.java25
-rw-r--r--core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/PeriodicEventManagerTest.java32
-rw-r--r--core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WsStringMessageServer.java31
-rw-r--r--core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/util/MessagingUtils.java5
4 files changed, 61 insertions, 32 deletions
diff --git a/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/DeploymentClient.java b/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/DeploymentClient.java
index eb51271d5..900e0a2f8 100644
--- a/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/DeploymentClient.java
+++ b/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/DeploymentClient.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,12 +22,12 @@
package org.onap.policy.apex.core.deployment;
import com.google.common.eventbus.Subscribe;
-
+import java.net.InetAddress;
import java.net.URI;
+import java.net.UnknownHostException;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
-
import org.onap.policy.apex.core.infrastructure.messaging.MessageHolder;
import org.onap.policy.apex.core.infrastructure.messaging.MessageListener;
import org.onap.policy.apex.core.infrastructure.messaging.MessagingService;
@@ -66,7 +67,7 @@ public class DeploymentClient implements Runnable {
// Thread management fields
private boolean started = false;
private Thread thisThread = null;
-
+
// Number of messages processed
private long messagesSent = 0;
private long messagesReceived = 0;
@@ -127,7 +128,8 @@ public class DeploymentClient implements Runnable {
}
// Send the message in its message holder
- final MessageHolder<Message> messageHolder = new MessageHolder<>(MessagingUtils.getHost());
+ InetAddress local = getLocalAddress();
+ final MessageHolder<Message> messageHolder = new MessageHolder<>(local);
messageHolder.addMessage(messageForSending);
service.send(messageHolder);
messagesSent++;
@@ -138,11 +140,24 @@ public class DeploymentClient implements Runnable {
thisThread.interrupt();
return false;
}
-
+
return true;
}
/**
+ * Get the local address for the WS MessageHolder, or null if there is a problem.
+ */
+ private InetAddress getLocalAddress() {
+ try {
+ return MessagingUtils.getLocalHostLanAddress();
+ }
+ catch (UnknownHostException e) {
+ LOGGER.debug("engine<-->deployment client failed to find the localhost address - continuing ...", e);
+ return null;
+ }
+ }
+
+ /**
* Gets the host.
*
* @return the host
diff --git a/core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/PeriodicEventManagerTest.java b/core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/PeriodicEventManagerTest.java
index 816c528bb..22344cfc4 100644
--- a/core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/PeriodicEventManagerTest.java
+++ b/core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/PeriodicEventManagerTest.java
@@ -1,19 +1,20 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* 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=========================================================
*/
@@ -28,7 +29,6 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.PrintStream;
-
import org.junit.Test;
/**
@@ -133,26 +133,26 @@ public class PeriodicEventManagerTest {
} catch (ApexDeploymentException ade) {
assertEquals("model deployment failed on parameters localhost 12345 true", ade.getMessage());
}
-
+
try {
peManager.init();
} catch (ApexDeploymentException ade) {
ade.printStackTrace();
fail("test should not throw an exception");
}
-
+
try {
peManager.runCommand();
} catch (ApexDeploymentException ade) {
assertEquals("failed response Operation failed received from serverlocalhost:12345", ade.getMessage());
}
-
+
try {
peManager.runCommand();
} catch (ApexDeploymentException ade) {
fail("test should not throw an exception");
}
-
+
peManager.close();
}
@@ -176,26 +176,26 @@ public class PeriodicEventManagerTest {
} catch (ApexDeploymentException ade) {
assertEquals("model deployment failed on parameters localhost 12345 true", ade.getMessage());
}
-
+
try {
peManager.init();
} catch (ApexDeploymentException ade) {
ade.printStackTrace();
fail("test should not throw an exception");
}
-
+
try {
peManager.runCommand();
} catch (ApexDeploymentException ade) {
assertEquals("failed response Operation failed received from serverlocalhost:12345", ade.getMessage());
}
-
+
try {
peManager.runCommand();
} catch (ApexDeploymentException ade) {
fail("test should not throw an exception");
}
-
+
peManager.close();
}
@@ -220,7 +220,7 @@ public class PeriodicEventManagerTest {
} catch (ApexDeploymentException ade) {
assertEquals("connection to apex is not initialized", ade.getMessage());
}
-
+
try {
peManager.runCommand();
fail("test should throw an exception");
@@ -228,7 +228,7 @@ public class PeriodicEventManagerTest {
assertEquals("connection to apex is not initialized", ade.getMessage());
ade.printStackTrace();
}
-
+
peManager.close();
}
@@ -253,13 +253,13 @@ public class PeriodicEventManagerTest {
} catch (ApexDeploymentException ade) {
assertEquals("connection to apex is not initialized", ade.getMessage());
}
-
+
peManager.close();
}
/**
* Run the application.
- *
+ *
* @param eventArgs the command arguments
* @return a string containing the command output
*/
diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WsStringMessageServer.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WsStringMessageServer.java
index b244feab0..41fb82a9e 100644
--- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WsStringMessageServer.java
+++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WsStringMessageServer.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,10 +22,9 @@
package org.onap.policy.apex.core.infrastructure.messaging.stringmessaging;
import com.google.common.eventbus.Subscribe;
-
import java.net.InetAddress;
import java.net.InetSocketAddress;
-
+import java.net.UnknownHostException;
import org.onap.policy.apex.core.infrastructure.messaging.MessageListener;
import org.onap.policy.apex.core.infrastructure.messaging.MessagingException;
import org.onap.policy.apex.core.infrastructure.messaging.MessagingService;
@@ -66,19 +66,32 @@ public class WsStringMessageServer implements WsStringMessager {
*/
@Override
public void start(final WsStringMessageListener newWsStringMessageListener) throws MessagingException {
- this.wsStringMessageListener = newWsStringMessageListener;
LOGGER.entry("web socket event consumer server starting . . .");
+ if (LOGGER.isDebugEnabled()) {
+ String lanaddress = "unknown";
+ try {
+ lanaddress = MessagingUtils.getLocalHostLanAddress().getHostAddress();
+ }
+ catch (final UnknownHostException ignore) {
+ LOGGER.debug("Failed to find name of local address name",ignore);
+ }
+ LOGGER.debug("web socket string message server LAN address=" + lanaddress);
+ String hostaddress = "unknown";
+ try {
+ hostaddress = InetAddress.getLocalHost().getHostAddress();
+ }
+ catch (final UnknownHostException ignore) {
+ LOGGER.debug("Failed to find name of local address",ignore);
+ }
+ LOGGER.debug("web socket string message server host address=" + hostaddress);
+ }
- try {
- final InetAddress addrLan = MessagingUtils.getLocalHostLanAddress();
- LOGGER.debug("web socket string message server LAN address=" + addrLan.getHostAddress());
- final InetAddress addr = InetAddress.getLocalHost();
- LOGGER.debug("web socket string message server host address=" + addr.getHostAddress());
+ this.wsStringMessageListener = newWsStringMessageListener;
+ try {
service = factory.createServer(new InetSocketAddress(port));
service.addMessageListener(new WsStringMessageServerListener());
-
service.startConnection();
} catch (final Exception e) {
LOGGER.warn("web socket string message server start failed", e);
diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/util/MessagingUtils.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/util/MessagingUtils.java
index a501a66d6..a6c3c5854 100644
--- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/util/MessagingUtils.java
+++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/util/MessagingUtils.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,7 +29,6 @@ import java.net.NetworkInterface;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Enumeration;
-
import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
@@ -101,7 +101,7 @@ public final class MessagingUtils {
/**
* Check if port is available or not.
- *
+ *
* @param port the port to test
* @return true if port is available
*/
@@ -118,6 +118,7 @@ public final class MessagingUtils {
* Returns the local host address.
*
* @return the local host address
+ * @throws IllegalStateException if the local host's address cannot be found
*/
public static InetAddress getHost() {
try {