diff options
Diffstat (limited to 'core/core-deployment')
4 files changed, 83 insertions, 87 deletions
diff --git a/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/BatchDeployer.java b/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/BatchDeployer.java index 499644fd9..8bfb15025 100644 --- a/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/BatchDeployer.java +++ b/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/BatchDeployer.java @@ -33,8 +33,8 @@ import org.slf4j.ext.XLoggerFactory; * The Class {@link BatchDeployer} deploys an Apex model held as an XML or Json file onto an Apex engine. It uses the * EngDep protocol to communicate with the engine, with the EngDep protocol being carried on Java web sockets. * - * This deployer is a simple command line deployer that reads the communication parameters and the location of the Apex - * model file as arguments. + * <p>This deployer is a simple command line deployer that reads the communication parameters and the location of the + * Apex model file as arguments. * * @author Liam Fallon (liam.fallon@ericsson.com) */ @@ -55,8 +55,9 @@ public class BatchDeployer { */ public static void main(final String[] args) { if (args.length != NUM_ARGUMENTS) { - LOGGER.error("invalid arguments: " + Arrays.toString(args)); - LOGGER.error("usage: Deployer <server address> <port address> <Apex Model file location>"); + String message = "invalid arguments: " + Arrays.toString(args) + + "usage: Deployer <server address> <port address> <Apex Model file location>"; + LOGGER.error(message); return; } @@ -112,7 +113,7 @@ public class BatchDeployer { * @throws IOException on IO exceptions from the operating system */ public void deployModel(final String modelFileName, final boolean ignoreConflicts, final boolean force) - throws ApexException, IOException { + throws ApexException, IOException { engineServiceFacade.deployModel(modelFileName, ignoreConflicts, force); } @@ -126,7 +127,7 @@ public class BatchDeployer { * @throws IOException on IO exceptions from the operating system */ public void deployModel(final AxPolicyModel policyModel, final boolean ignoreConflicts, final boolean force) - throws ApexException, IOException { + throws ApexException, IOException { engineServiceFacade.deployModel(policyModel, ignoreConflicts, force); } 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 5fc7dc8c6..d0af94930 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 @@ -20,6 +20,8 @@ package org.onap.policy.apex.core.deployment; +import com.google.common.eventbus.Subscribe; + import java.net.URI; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; @@ -35,8 +37,6 @@ import org.onap.policy.apex.core.protocols.Message; import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; -import com.google.common.eventbus.Subscribe; - /** * The Class DeploymentClient handles the client side of an EngDep communication session with an * Apex server. It runs a thread to handle message sending and session monitoring. It uses a sending @@ -84,7 +84,7 @@ public class DeploymentClient implements Runnable { */ @Override public void run() { - LOGGER.debug("engine<-->deployment to \"ws://" + host + ":" + port + "\" thread starting . . ."); + LOGGER.debug("engine<-->deployment to \"ws://{}:{}\" thread starting . . .", host, port); // Set up the thread name thisThread = Thread.currentThread(); @@ -104,7 +104,7 @@ public class DeploymentClient implements Runnable { return; } // Loop forever, sending messages as they appear on the queue - while (true) { + while (started) { try { final Message messageForSending = sendQueue.take(); sendMessage(messageForSending); @@ -143,9 +143,7 @@ public class DeploymentClient implements Runnable { thisThread.interrupt(); // Wait for the thread to stop - while (thisThread != null && thisThread.isAlive()) { - ThreadUtilities.sleep(CLIENT_STOP_WAIT_INTERVAL); - } + ThreadUtilities.sleep(CLIENT_STOP_WAIT_INTERVAL); // Close the Web Services connection service.stopConnection(); diff --git a/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/EngineServiceFacade.java b/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/EngineServiceFacade.java index f0616e20a..9b24bcd96 100644 --- a/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/EngineServiceFacade.java +++ b/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/EngineServiceFacade.java @@ -50,12 +50,11 @@ import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; /** - * The Class Deployer deploys an Apex model held as an XML file onto an Apex engine. It uses the - * EngDep protocol to communicate with the engine, with the EngDep protocol being carried on Java - * web sockets. + * The Class Deployer deploys an Apex model held as an XML file onto an Apex engine. It uses the EngDep protocol to + * communicate with the engine, with the EngDep protocol being carried on Java web sockets. * - * This deployer is a simple command line deployer that reads the communication parameters and the - * location of the XML model file as arguments. + * <p>his deployer is a simple command line deployer that reads the communication parameters and the location of the XML + * model file as arguments. * * @author Liam Fallon (liam.fallon@ericsson.com) */ @@ -63,6 +62,10 @@ public class EngineServiceFacade { // Get a reference to the logger private static final XLogger LOGGER = XLoggerFactory.getXLogger(EngineServiceFacade.class); + // Repeated string constants + private static final String RECEIVED_FROM_SERVER = " received from server"; + private static final String FAILED_RESPONSE = "failed response "; + // The default message timeout and timeout increment (the amount of time between polls) in // milliseconds private static final int CLIENT_START_WAIT_INTERVAL = 100; @@ -125,12 +128,12 @@ public class EngineServiceFacade { // Get engine service information to see what engines we're dealing with final GetEngineServiceInfo engineServiceInfo = new GetEngineServiceInfo(null); LOGGER.debug("sending get engine service info message {} to server {}:{} . . .", engineServiceInfo, - hostName, port); + hostName, port); client.sendMessage(engineServiceInfo); LOGGER.debug("sent get engine service info message to server {}:{} . . .", hostName, port); - final EngineServiceInfoResponse engineServiceInfoResponse = - (EngineServiceInfoResponse) getResponse(engineServiceInfo); + final EngineServiceInfoResponse engineServiceInfoResponse = (EngineServiceInfoResponse) getResponse( + engineServiceInfo); if (engineServiceInfoResponse.isSuccessful()) { engineServiceKey = engineServiceInfoResponse.getEngineServiceKey(); engineKeyArray = engineServiceInfoResponse.getEngineKeyArray(); @@ -187,30 +190,29 @@ public class EngineServiceFacade { * * @param modelFileName the name of the model file containing the model to deploy * @param ignoreConflicts true if conflicts between context in polices is to be ignored - * @param force true if the model is to be applied even if it is incompatible with the existing - * model + * @param force true if the model is to be applied even if it is incompatible with the existing model * @throws ApexException on Apex errors * @throws IOException on IO exceptions from the operating system */ public void deployModel(final String modelFileName, final boolean ignoreConflicts, final boolean force) - throws ApexException, IOException { + throws ApexException, IOException { if (engineServiceKey == null || engineKeyArray == null || engineKeyArray.length == 0) { LOGGER.error("cound not deploy apex model, deployer is not initialized"); throw new ApexDeploymentException("cound not deploy apex model, deployer is not initialized"); } // Get the model file as a string - URL apexModelURL = ResourceUtils.getLocalFile(modelFileName); - if (apexModelURL == null) { - apexModelURL = ResourceUtils.getUrlResource(modelFileName); - if (apexModelURL == null) { + URL apexModelUrl = ResourceUtils.getLocalFile(modelFileName); + if (apexModelUrl == null) { + apexModelUrl = ResourceUtils.getUrlResource(modelFileName); + if (apexModelUrl == null) { LOGGER.error("cound not create apex model, could not read from XML file {}", modelFileName); throw new ApexDeploymentException( - "cound not create apex model, could not read XML file " + modelFileName); + "cound not create apex model, could not read XML file " + modelFileName); } } - deployModel(modelFileName, apexModelURL.openStream(), ignoreConflicts, force); + deployModel(modelFileName, apexModelUrl.openStream(), ignoreConflicts, force); } /** @@ -219,12 +221,11 @@ public class EngineServiceFacade { * @param modelFileName the name of the model file containing the model to deploy * @param modelInputStream the stream that holds the Apex model * @param ignoreConflicts true if conflicts between context in polices is to be ignored - * @param force true if the model is to be applied even if it is incompatible with the existing - * model + * @param force true if the model is to be applied even if it is incompatible with the existing model * @throws ApexException on model deployment errors */ public void deployModel(final String modelFileName, final InputStream modelInputStream, - final boolean ignoreConflicts, final boolean force) throws ApexException { + final boolean ignoreConflicts, final boolean force) throws ApexException { // Read the policy model from the stream final ApexModelReader<AxPolicyModel> modelReader = new ApexModelReader<>(AxPolicyModel.class); modelReader.setValidateFlag(!ignoreConflicts); @@ -243,20 +244,19 @@ public class EngineServiceFacade { * * @param apexPolicyModel the name of the model to deploy * @param ignoreConflicts true if conflicts between context in polices is to be ignored - * @param force true if the model is to be applied even if it is incompatible with the existing - * model + * @param force true if the model is to be applied even if it is incompatible with the existing model * @throws ApexException on model deployment errors */ public void deployModel(final AxPolicyModel apexPolicyModel, final boolean ignoreConflicts, final boolean force) - throws ApexException { + throws ApexException { // Write the model into a byte array final ByteArrayOutputStream baOutputStream = new ByteArrayOutputStream(); final ApexModelWriter<AxPolicyModel> modelWriter = new ApexModelWriter<>(AxPolicyModel.class); modelWriter.write(apexPolicyModel, baOutputStream); // Create and send Update message - final UpdateModel umMessage = - new UpdateModel(engineServiceKey, baOutputStream.toString(), ignoreConflicts, force); + final UpdateModel umMessage = new UpdateModel(engineServiceKey, baOutputStream.toString(), ignoreConflicts, + force); LOGGER.debug("sending update message {} to server {}:{} . . .", umMessage, hostName, port); client.sendMessage(umMessage); @@ -264,12 +264,10 @@ public class EngineServiceFacade { // Check if we got a response final Response response = getResponse(umMessage); - if (response.isSuccessful()) { - LOGGER.debug(response.toString()); - } else { - LOGGER.warn("failed response {} received from server {}:{}", response.getMessageData(), hostName, port); - throw new ApexException( - "failed response " + response.getMessageData() + " received from server" + hostName + ':' + port); + if (!response.isSuccessful()) { + LOGGER.warn(FAILED_RESPONSE + "{} received from server {}:{}", response.getMessageData(), hostName, port); + throw new ApexException(FAILED_RESPONSE + response.getMessageData() + RECEIVED_FROM_SERVER + hostName + + ':' + port); } } @@ -287,12 +285,11 @@ public class EngineServiceFacade { // Check if we got a response final Response response = getResponse(startEngineMessage); - if (response.isSuccessful()) { - LOGGER.debug(response.toString()); - } else { - LOGGER.warn("failed response {} received from server {}:{}", response.getMessageData(), hostName, port); - throw new ApexDeploymentException( - "failed response " + response.getMessageData() + " received from server" + hostName + ':' + port); + if (!response.isSuccessful()) { + String message = FAILED_RESPONSE + response.getMessageData() + RECEIVED_FROM_SERVER + + hostName + ':' + port; + LOGGER.warn(message); + throw new ApexDeploymentException(message); } } @@ -310,12 +307,11 @@ public class EngineServiceFacade { // Check if we got a response final Response response = getResponse(stopEngineMessage); - if (response.isSuccessful()) { - LOGGER.debug(response.toString()); - } else { - LOGGER.warn("failed response {} received from server {}:{}", response.getMessageData(), hostName, port); - throw new ApexDeploymentException( - "failed response " + response.getMessageData() + " received from server" + hostName + ':' + port); + if (!response.isSuccessful()) { + String message = FAILED_RESPONSE + response.getMessageData() + RECEIVED_FROM_SERVER + + hostName + ':' + port; + LOGGER.warn(message); + throw new ApexDeploymentException(message); } } @@ -330,18 +326,17 @@ public class EngineServiceFacade { final StartPeriodicEvents startPerioidicEventsMessage = new StartPeriodicEvents(engineKey); startPerioidicEventsMessage.setMessageData(Long.toString(period)); LOGGER.debug("sending start perioidic events {} to server {}:{} . . .", startPerioidicEventsMessage, hostName, - port); + port); client.sendMessage(startPerioidicEventsMessage); LOGGER.debug("sent start perioidic events message to server {}:{} . . .", hostName, port); // Check if we got a response final Response response = getResponse(startPerioidicEventsMessage); - if (response.isSuccessful()) { - LOGGER.debug(response.toString()); - } else { - LOGGER.warn("failed response {} received from server {}:{}", response.getMessageData(), hostName, port); - throw new ApexDeploymentException( - "failed response " + response.getMessageData() + " received from server" + hostName + ':' + port); + if (!response.isSuccessful()) { + String message = FAILED_RESPONSE + response.getMessageData() + RECEIVED_FROM_SERVER + + hostName + ':' + port; + LOGGER.warn(message); + throw new ApexDeploymentException(message); } } @@ -354,18 +349,17 @@ public class EngineServiceFacade { public void stopPerioidicEvents(final AxArtifactKey engineKey) throws ApexDeploymentException { final StopPeriodicEvents stopPerioidicEventsMessage = new StopPeriodicEvents(engineKey); LOGGER.debug("sending stop perioidic events {} to server {}:{} . . .", stopPerioidicEventsMessage, hostName, - port); + port); client.sendMessage(stopPerioidicEventsMessage); LOGGER.debug("sent stop perioidic events message to server {}:{} . . .", hostName, port); // Check if we got a response final Response response = getResponse(stopPerioidicEventsMessage); - if (response.isSuccessful()) { - LOGGER.debug(response.toString()); - } else { - LOGGER.warn("failed response {} received from server {}:{}", response.getMessageData(), hostName, port); - throw new ApexDeploymentException( - "failed response " + response.getMessageData() + " received from server" + hostName + ':' + port); + if (!response.isSuccessful()) { + String message = FAILED_RESPONSE + response.getMessageData() + RECEIVED_FROM_SERVER + + hostName + ':' + port; + LOGGER.warn(message); + throw new ApexDeploymentException(message); } } @@ -385,9 +379,10 @@ public class EngineServiceFacade { // Check if we got a response final Response response = getResponse(engineStatusMessage); if (!response.isSuccessful()) { - LOGGER.warn("failed response {} received from server {}:{}", response.getMessageData(), hostName, port); - throw new ApexException( - "failed response " + response.getMessageData() + " received from server" + hostName + ':' + port); + String message = FAILED_RESPONSE + response.getMessageData() + RECEIVED_FROM_SERVER + hostName + + ':' + port; + LOGGER.warn(message); + throw new ApexException(message); } final ByteArrayInputStream baInputStream = new ByteArrayInputStream(response.getMessageData().getBytes()); @@ -406,16 +401,17 @@ public class EngineServiceFacade { public String getEngineInfo(final AxArtifactKey engineKey) throws ApexException { final GetEngineInfo engineInfoMessage = new GetEngineInfo(engineKey); LOGGER.debug("sending get engine information message {} to server {}:{} . . .", engineInfoMessage, hostName, - port); + port); client.sendMessage(engineInfoMessage); LOGGER.debug("sent get engine information message to server {}:{} . . .", hostName, port); // Check if we got a response final Response response = getResponse(engineInfoMessage); if (!response.isSuccessful()) { - LOGGER.warn("failed response {} received from server {}:{}", response.getMessageData(), hostName, port); - throw new ApexException( - "failed response " + response.getMessageData() + " received from server" + hostName + ':' + port); + String message = FAILED_RESPONSE + response.getMessageData() + RECEIVED_FROM_SERVER + hostName + + ':' + port; + LOGGER.warn(message); + throw new ApexException(message); } return response.getMessageData(); @@ -437,8 +433,8 @@ public class EngineServiceFacade { // Wait for the required amount of milliseconds for the response from the Apex server Message receivedMessage = null; - for (int timeWaitedSoFar = 0; receivedMessage == null && timeWaitedSoFar < timeoutTime; timeWaitedSoFar += - REPLY_MESSAGE_TIMEOUT_INCREMENT) { + for (int timeWaitedSoFar = 0; receivedMessage == null + && timeWaitedSoFar < timeoutTime; timeWaitedSoFar += REPLY_MESSAGE_TIMEOUT_INCREMENT) { try { receivedMessage = client.getReceiveQueue().poll(REPLY_MESSAGE_TIMEOUT_INCREMENT, TimeUnit.MILLISECONDS); } catch (final InterruptedException e) { @@ -446,7 +442,7 @@ public class EngineServiceFacade { Thread.currentThread().interrupt(); LOGGER.warn("reception of response from server interrupted {}:{}", hostName, port, e); throw new ApexDeploymentException( - "reception of response from server interrupted " + hostName + ':' + port, e); + "reception of response from server interrupted " + hostName + ':' + port, e); } } @@ -459,9 +455,9 @@ public class EngineServiceFacade { // Check instance is a response message if (!(receivedMessage instanceof Response)) { LOGGER.warn("response received from server is of incorrect type {}, should be of type {}", - receivedMessage.getClass().getName(), Response.class.getName()); + receivedMessage.getClass().getName(), Response.class.getName()); throw new ApexDeploymentException("response received from server is of incorrect type " - + receivedMessage.getClass().getName() + ", should be of type " + Response.class.getName()); + + receivedMessage.getClass().getName() + ", should be of type " + Response.class.getName()); } // Cast the response message @@ -471,16 +467,16 @@ public class EngineServiceFacade { if (!responseMessage.getResponseTo().equals(sentMessage)) { LOGGER.warn("response received is not response to sent message " + sentMessage.getAction()); throw new ApexDeploymentException( - "response received is not correct response to sent message " + sentMessage.getAction()); + "response received is not correct response to sent message " + sentMessage.getAction()); } // Check if successful if (responseMessage.isSuccessful()) { LOGGER.debug("response received: {} message was succssful: {}", sentMessage.getAction(), - responseMessage.getMessageData()); + responseMessage.getMessageData()); } else { LOGGER.debug("response received: {} message failed: {}", sentMessage.getAction(), - responseMessage.getMessageData()); + responseMessage.getMessageData()); } return responseMessage; diff --git a/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/PeriodicEventManager.java b/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/PeriodicEventManager.java index bfaece4c6..a1db5ef07 100644 --- a/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/PeriodicEventManager.java +++ b/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/PeriodicEventManager.java @@ -48,8 +48,9 @@ public class PeriodicEventManager { */ public static void main(final String[] args) { if (args.length != NUM_ARGUMENTS) { - LOGGER.error("invalid arguments: " + Arrays.toString(args)); - LOGGER.error("usage: Deployer <server address> <port address> <start/stop> <periods in ms>"); + String message = "invalid arguments: " + Arrays.toString(args) + + "\nusage: Deployer <server address> <port address> <start/stop> <periods in ms>"; + LOGGER.error(message); return; } |