/*-
* ============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.
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;
// Thread management fields
private boolean started = false;
private Thread thisThread = null;
-
+
// Number of messages processed
private long messagesSent = 0;
private long messagesReceived = 0;
}
// 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++;
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.
*
/*-
* ============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=========================================================
*/
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.PrintStream;
-
import org.junit.Test;
/**
} 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();
}
} 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();
}
} catch (ApexDeploymentException ade) {
assertEquals("connection to apex is not initialized", ade.getMessage());
}
-
+
try {
peManager.runCommand();
fail("test should throw an exception");
assertEquals("connection to apex is not initialized", ade.getMessage());
ade.printStackTrace();
}
-
+
peManager.close();
}
} 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
*/
/*-
* ============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.
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;
*/
@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);
/*-
* ============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.
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Enumeration;
-
import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
/**
* Check if port is available or not.
- *
+ *
* @param port the port to test
* @return true if port is available
*/
* 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 {
/*-
* ============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.
* 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.service.engine.engdep;
import com.google.common.eventbus.Subscribe;
-
+import java.net.InetAddress;
+import java.net.UnknownHostException;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;
-
import org.java_websocket.WebSocket;
import org.onap.policy.apex.core.infrastructure.messaging.MessageHolder;
import org.onap.policy.apex.core.infrastructure.messaging.MessageListener;
* event implements this interface, and the object created with that class is registered with a component using the
* component's <code>addEngDepMessageListener</code> method. When the engDepMessage event occurs, that object's
* appropriate method is invoked.
- *
+ *
* <p>This class uses a queue to buffer incoming messages. When the listener is called, it places the incoming message
* on the queue. A thread runs which removes the messages from the queue and forwards them to the Apex engine.
*
/**
* Handle incoming EngDep messages.
- *
+ *
* @param message the incoming message
* @param webSocket the web socket the message came in on
* @param enDepAction the action from the message
case GET_ENGINE_INFO:
handleEngineInfoMessage(message, webSocket);
break;
-
+
default:
throw new ApexException("action " + enDepAction + " on received message not handled by engine");
}
/**
* Handle the get engine service information message.
- *
+ *
* @param message the message
* @param webSocket the web socket that the message came on
* @throws ApexException on message handling exceptions
/**
* Handle the update model message.
- *
+ *
* @param message the message
* @param webSocket the web socket that the message came on
* @throws ApexException on message handling exceptions
/**
* Handle the start engine message.
- *
+ *
* @param message the message
* @param webSocket the web socket that the message came on
* @throws ApexException on message handling exceptions
/**
* Handle the stop engine message.
- *
+ *
* @param message the message
* @param webSocket the web socket that the message came on
* @throws ApexException on message handling exceptions
/**
* Handle the start periodic events message.
- *
+ *
* @param message the message
* @param webSocket the web socket that the message came on
* @throws ApexException on message handling exceptions
/**
* Handle the stop periodic events message.
- *
+ *
* @param message the message
* @param webSocket the web socket that the message came on
* @throws ApexException on message handling exceptions
/**
* Handle the engine status message.
- *
+ *
* @param message the message
* @param webSocket the web socket that the message came on
* @throws ApexException on message handling exceptions
/**
* Handle the engine information message.
- *
+ *
* @param message the message
* @param webSocket the web socket that the message came on
* @throws ApexException on message handling exceptions
LOGGER.debug("returned runtime information for engine {}", getEngineInfo.getTarget().getId());
}
+ /**
+ * 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("failed to find the localhost address - continuing ...", e);
+ return null;
+ }
+ }
+
/**
* Send the Response message to the client.
*
final Response responseMessage = new Response(requestMessage.getTarget(), result, requestMessage);
responseMessage.setMessageData(messageData);
- final MessageHolder<Message> messageHolder = new MessageHolder<>(MessagingUtils.getHost());
+ final MessageHolder<Message> messageHolder = new MessageHolder<>(getLocalAddress());
messageHolder.addMessage(responseMessage);
client.send(MessagingUtils.serializeObject(messageHolder));
responseMessage.setEngineKeyArray(engineKeyCollection);
responseMessage.setApexModelKey(apexModelKey);
- final MessageHolder<Message> messageHolder = new MessageHolder<>(MessagingUtils.getHost());
+ final MessageHolder<Message> messageHolder = new MessageHolder<>(getLocalAddress());
messageHolder.addMessage(responseMessage);
client.send(MessagingUtils.serializeObject(messageHolder));