parameters.getApexPropertiesStream());
} catch (final Exception e) {
LOGGER.error("start of Apex command line editor failed, error reading Apex model properties from "
- + parameters.getApexPropertiesLocation());
- LOGGER.error(e.getMessage());
+ + parameters.getApexPropertiesLocation(), e);
errorCount++;
return;
}
errorCount);
}
} catch (final IOException e) {
- LOGGER.error("execution of Apex command line editor failed: " + e.getMessage());
+ LOGGER.error("execution of Apex command line editor failed: " + e.getMessage(), e);
}
}
+ "\" not found for command \"" + command.getName() + "\"");
} catch (final ClassNotFoundException e) {
throw new CommandLineException("specified class \"" + command.getApiMethod() + "\" not found for command \""
- + command.getName() + "\"");
+ + command.getName() + "\"", e);
}
}
}
} catch (final Exception e) {
throw new CommandLineException("number of argument mismatch on method \"" + command.getApiMethod()
- + "\" for command \"" + command.getName() + "\"");
+ + "\" for command \"" + command.getName() + "\"", e);
}
return parameterArray;
import org.onap.policy.apex.model.modelapi.ApexApiResult.Result;
import org.onap.policy.apex.model.utilities.TextFileUtils;
import org.onap.policy.apex.model.utilities.TreeMapUtils;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
/**
* This class implements the editor loop, the loop of execution that continuously executes commands until the quit
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
public class CommandLineEditorLoop {
+ // Get a reference to the logger
+ private static final XLogger LOGGER = XLoggerFactory.getXLogger(CommandLineEditorLoop.class);
+
// Recurring string constants
private static final String COMMAND = "command ";
catch (final CommandLineException e) {
writer.println(e.getMessage());
errorCount++;
+ LOGGER.debug("command line error", e);
continue;
}
catch (final CommandLineException e) {
writer.println(e.getMessage());
errorCount++;
+ LOGGER.debug("command line error", e);
continue;
}
catch (final CommandLineException e) {
writer.println(e.getMessage());
errorCount++;
+ LOGGER.debug("command line error", e);
} catch (final Exception e) {
e.printStackTrace(writer);
+ LOGGER.error("command line error", e);
}
}
final KeywordNode searchKeywordNode = keywordNodeDeque.peek();
// We have got to the arguments, time to stop looking
- if (commandWords.get(i).indexOf('=') > 0) {
+ if (commandWords.get(i).indexOf('=') >= 0) {
unwindStack(startKeywordNode);
throw new CommandLineException("command not found: " + stringAL2String(commandWords));
}
parameters = parser.parse(args);
} catch (final ApexDeploymentRestParameterException e) {
throw new ApexDeploymentRestParameterException(
- REST_ENDPOINT_PREFIX + this.toString() + ") parameter error, " + e.getMessage() + '\n'
- + parser.getHelp(ApexDeploymentRestMain.class.getCanonicalName()));
+ REST_ENDPOINT_PREFIX + this.toString() + ") parameter error, " + e.getMessage() + '\n'
+ + parser.getHelp(ApexDeploymentRestMain.class.getCanonicalName()), e);
}
if (parameters.isHelpSet()) {
throw new ApexDeploymentRestParameterException(
- parser.getHelp(ApexDeploymentRestMain.class.getCanonicalName()));
+ parser.getHelp(ApexDeploymentRestMain.class.getCanonicalName()));
}
// Validate the parameters
final String validationMessage = parameters.validate();
if (validationMessage.length() > 0) {
throw new ApexDeploymentRestParameterException(
- REST_ENDPOINT_PREFIX + this.toString() + ") parameters invalid, " + validationMessage
- + '\n' + parser.getHelp(ApexDeploymentRestMain.class.getCanonicalName()));
+ REST_ENDPOINT_PREFIX + this.toString() + ") parameters invalid, " + validationMessage + '\n'
+ + parser.getHelp(ApexDeploymentRestMain.class.getCanonicalName()));
}
state = ServicesState.READY;
* Initialize the rest service.
*/
public void init() {
- outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") starting at "
- + parameters.getBaseUri().toString() + " . . .");
+ outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") starting at " + parameters.getBaseUri().toString()
+ + " . . .");
try {
state = ServicesState.INITIALIZING;
if (parameters.getTimeToLive() == ApexDeploymentRestParameters.INFINITY_TIME_TO_LIVE) {
outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") started at "
- + parameters.getBaseUri().toString());
+ + parameters.getBaseUri().toString());
} else {
outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") started");
}
Thread.sleep(1000);
}
} catch (final Exception e) {
- outStream.println(
- REST_ENDPOINT_PREFIX + this.toString() + ") failed at with error: " + e.getMessage());
+ String message = REST_ENDPOINT_PREFIX + this.toString() + ") failed at with error: " + e.getMessage();
+ outStream.println(message);
+ LOGGER.warn(message, e);
} finally {
if (apexDeploymentRest != null) {
apexDeploymentRest.shutdown();
public String toString() {
final StringBuilder ret = new StringBuilder();
ret.append(this.getClass().getSimpleName()).append(": Config=[").append(this.parameters).append("], State=")
- .append(this.getState());
+ .append(this.getState());
return ret.toString();
}
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
public final class ParameterCheck {
+ // Recurring string constants
+ private static final String OF_PARAMETER = "\"of parameter \"";
+ private static final String VALUE = "value \"";
+ private static final String PARAMETER = "parameter \"";
+ private static final String NOT_FOUND = "\" not found";
+
private static final int MAX_PORT = 65535;
/**
* private constructor to prevent subclassing of this utility class.
*/
- private ParameterCheck() {}
+ private ParameterCheck() {
+ }
/**
* The Enum StartStop is used to hold.
*/
public static String getHostName(final Map<String, String[]> parameterMap) {
if (!parameterMap.containsKey(HOSTNAME_PAR)) {
- LOGGER.warn("parameter \"" + HOSTNAME_PAR + "\" not found");
+ LOGGER.warn(PARAMETER + HOSTNAME_PAR + NOT_FOUND);
return null;
}
final String[] hostNameValue = parameterMap.get(HOSTNAME_PAR);
if (hostNameValue.length == 0 || hostNameValue[0].trim().length() == 0) {
- LOGGER.warn("value of parameter \"" + HOSTNAME_PAR + "\" not found");
+ LOGGER.warn("value of parameter \"" + HOSTNAME_PAR + NOT_FOUND);
return null;
}
*/
public static int getPort(final Map<String, String[]> parameterMap) {
if (!parameterMap.containsKey(PORT_PAR)) {
- LOGGER.warn("parameter \"" + PORT_PAR + "\" not found");
+ LOGGER.warn(PARAMETER + PORT_PAR + NOT_FOUND);
return -1;
}
final String[] portValue = parameterMap.get(PORT_PAR);
if (portValue.length == 0 || portValue[0].trim().length() == 0) {
- LOGGER.warn("value of parameter \"" + PORT_PAR + "\" not found");
+ LOGGER.warn("value of parameter \"" + PORT_PAR + NOT_FOUND);
return -1;
}
try {
port = Integer.parseInt(portValue[0]);
} catch (final Exception e) {
- LOGGER.warn("value \"" + portValue[0] + "\"of parameter \"" + PORT_PAR + "\" not a valid integer", e);
+ LOGGER.warn(VALUE + portValue[0] + OF_PARAMETER + PORT_PAR + "\" not a valid integer", e);
return -1;
}
if (port <= 0 || port > MAX_PORT) {
- LOGGER.warn("value \"" + portValue[0] + "\"of parameter \"" + PORT_PAR
- + "\" not a valid port between 0 and 65535");
+ String message = VALUE + portValue[0] + OF_PARAMETER + PORT_PAR
+ + "\" not a valid port between 0 and 65535";
+ LOGGER.warn(message);
return -1;
}
}
}
if (artifactKeyParameter == null) {
- LOGGER.warn("parameter \"" + AXARTIFACTKEY_PAR + "\" not found");
+ LOGGER.warn(PARAMETER + AXARTIFACTKEY_PAR + NOT_FOUND);
return null;
}
final String[] axArtifactKeyArray = artifactKeyParameter.split("#");
if (axArtifactKeyArray.length != 2) {
- LOGGER.warn("value \"" + artifactKeyParameter + "\" of parameter \"" + AXARTIFACTKEY_PAR + "\" not valid");
+ String message = VALUE + artifactKeyParameter + "\" of parameter \"" + AXARTIFACTKEY_PAR
+ + "\" not valid";
+ LOGGER.warn(message);
return null;
}
* @return the start stop
*/
public static ParameterCheck.StartStop getStartStop(final Map<String, String[]> parameterMap,
- final AxArtifactKey engineKey) {
+ final AxArtifactKey engineKey) {
final String startStopPar = AXARTIFACTKEY_PAR + '#' + engineKey.getId();
if (!parameterMap.containsKey(startStopPar)) {
- LOGGER.warn("parameter \"" + startStopPar + "\" not found");
+ LOGGER.warn("parameter \"{}\" not found", startStopPar);
return null;
}
final String[] startStopValue = parameterMap.get(startStopPar);
if (startStopValue.length == 0 || startStopValue[0].trim().length() == 0) {
- LOGGER.warn("value of parameter \"" + startStopPar + "\" not found");
+ LOGGER.warn("value of parameter \"{}\" not found", startStopPar);
return null;
}
} else if (startStopValue[0].equalsIgnoreCase("stop")) {
startStop = ParameterCheck.StartStop.STOP;
} else {
- LOGGER.warn("value \"" + startStopValue[0] + "\"of parameter \"" + startStopPar
- + "\" not \"start\" or \"stop\"");
+ LOGGER.warn("value \"{}\"of parameter \"{}\" not \"start\" or \"stop\"", startStopValue[0], startStopPar);
return null;
}
*/
public static long getLong(final Map<String, String[]> parameterMap, final String longName) {
if (!parameterMap.containsKey(longName)) {
- LOGGER.warn("parameter \"" + longName + "\" not found");
+ LOGGER.warn("parameter \"{}\" not found", longName);
return -1;
}
final String[] longValue = parameterMap.get(longName);
if (longValue.length == 0 || longValue[0].trim().length() == 0) {
- LOGGER.warn("value of parameter \"" + longName + "\" not found");
+ LOGGER.warn("value of parameter \"{}\" not found", longName);
return -1;
}
try {
return Long.parseLong(longValue[0]);
} catch (final Exception e) {
- LOGGER.warn("value \"" + longValue[0] + "\"of parameter \"" + longName + "\" not a valid long", e);
+ LOGGER.warn(VALUE + longValue[0] + OF_PARAMETER + longName + "\" not a valid long", e);
return -1;
}
}
// Get and check the parameters
parameters = parser.parse(args);
} catch (final ApexEditorParameterException e) {
- throw new ApexEditorParameterException(
- REST_ENDPOINT_PREFIX + this.toString() + ") parameter error, " + e.getMessage() + '\n'
- + parser.getHelp(ApexEditorMain.class.getCanonicalName()));
+ throw new ApexEditorParameterException(REST_ENDPOINT_PREFIX + this.toString() + ") parameter error, "
+ + e.getMessage() + '\n' + parser.getHelp(ApexEditorMain.class.getCanonicalName()), e);
}
if (parameters.isHelpSet()) {
// Validate the parameters
final String validationMessage = parameters.validate();
if (validationMessage.length() > 0) {
- throw new ApexEditorParameterException(
- REST_ENDPOINT_PREFIX + this.toString() + ") parameters invalid, " + validationMessage
- + '\n' + parser.getHelp(ApexEditorMain.class.getCanonicalName()));
+ throw new ApexEditorParameterException(REST_ENDPOINT_PREFIX + this.toString() + ") parameters invalid, "
+ + validationMessage + '\n' + parser.getHelp(ApexEditorMain.class.getCanonicalName()));
}
state = EditorState.READY;
* Initialize the Apex editor.
*/
public void init() {
- outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") starting at "
- + parameters.getBaseUri().toString() + " . . .");
+ outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") starting at " + parameters.getBaseUri().toString()
+ + " . . .");
try {
state = EditorState.INITIALIZING;
if (parameters.getTimeToLive() == ApexEditorParameters.INFINITY_TIME_TO_LIVE) {
outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") started at "
- + parameters.getBaseUri().toString());
+ + parameters.getBaseUri().toString());
} else {
outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") started");
}
Thread.sleep(EDITOR_RNNING_CHECK_TIMEOUT);
}
} catch (final Exception e) {
- outStream.println(
- REST_ENDPOINT_PREFIX + this.toString() + ") failed at with error: " + e.getMessage());
+ String message = REST_ENDPOINT_PREFIX + this.toString() + ") failed at with error: " + e.getMessage();
+ outStream.println(message);
+ LOGGER.warn(message, e);
} finally {
if (apexEditor != null) {
apexEditor.shutdown();
public String toString() {
final StringBuilder ret = new StringBuilder();
ret.append(this.getClass().getSimpleName()).append(": Config=[").append(parameters).append("], State=")
- .append(this.getState());
+ .append(this.getState());
return ret.toString();
}
import java.net.URI;
import java.net.URISyntaxException;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+
/**
* This class reads and handles command line parameters to the Apex CLI editor.
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
public class ApexEditorParameters {
+ // Logger for this class
+ private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexEditorParameters.class);
+
/** The default port for connecting to the Web editor on. */
public static final int DEFAULT_REST_PORT = 18989;
new URI(getBaseUri().toString()).parseServerAuthority();
return "";
} catch (final URISyntaxException e) {
- return "listen address is not valid. " + e.getMessage() + "\n";
+ String message = "listen address is not valid. " + e.getMessage() + "\n";
+ LOGGER.warn(message, e);
+ return message;
}
}
objecttochange.addProperty(DESCRIPTION, desc);
augmessages.add(gson.toJson(jsonObject));
} catch (final Exception e) {
+ LOGGER.debug("error adding key information", e);
augmessages.add(message);
}
}
* The base class for Beans.
*/
public abstract class BeanBase {
+ // Recurring string constants
+ private static final String PROBLEM_RETRIEVING_FIELD_PREFIX = "Problem retrieving field called ('";
+ private static final String JSON_BEAN_SUFFIX = "') from JSON bean ";
/**
* Gets a named field from the bean.
return (String) method.invoke(this);
} catch (final Exception e) {
throw new IllegalArgumentException(
- "Problem retrieving field called ('" + field + "') from JSON bean " + this, e);
+ PROBLEM_RETRIEVING_FIELD_PREFIX + field + JSON_BEAN_SUFFIX + this, e);
}
}
}
}
} catch (final Exception e) {
throw new IllegalArgumentException(
- "Problem retrieving field called ('" + field + "') from JSON bean " + this, e);
+ PROBLEM_RETRIEVING_FIELD_PREFIX + field + JSON_BEAN_SUFFIX + this, e);
}
}
- throw new IllegalArgumentException("Problem retrieving field called ('" + field + "') from JSON bean " + this);
+ throw new IllegalArgumentException(PROBLEM_RETRIEVING_FIELD_PREFIX + field + JSON_BEAN_SUFFIX + this);
}
}
final ApexServicesRestMain editorMain = new ApexServicesRestMain(args, System.out);
editorMain.init();
} catch (final Exception e) {
- LOGGER.error(e.getMessage());
+ LOGGER.error("error starting REST client", e);
}
}
// Get and check the parameters
parameters = parser.parse(args);
} catch (final ApexServicesRestParameterException e) {
- throw new ApexServicesRestParameterException(
- REST_ENDPOINT_PREFIX + this.toString() + ") parameter error, " + e.getMessage() + '\n'
- + parser.getHelp(ApexServicesRestMain.class.getCanonicalName()));
+ throw new ApexServicesRestParameterException(REST_ENDPOINT_PREFIX + this.toString() + ") parameter error, "
+ + e.getMessage() + '\n' + parser.getHelp(ApexServicesRestMain.class.getCanonicalName()), e);
}
if (parameters.isHelpSet()) {
final String validationMessage = parameters.validate();
if (validationMessage.length() > 0) {
throw new ApexServicesRestParameterException(
- REST_ENDPOINT_PREFIX + this.toString() + ") parameters invalid, " + validationMessage
- + '\n' + parser.getHelp(ApexServicesRestMain.class.getCanonicalName()));
+ REST_ENDPOINT_PREFIX + this.toString() + ") parameters invalid, " + validationMessage + '\n'
+ + parser.getHelp(ApexServicesRestMain.class.getCanonicalName()));
}
state = EditorState.READY;
* Initialize the Apex editor.
*/
public void init() {
- outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") starting at "
- + parameters.getBaseUri().toString() + " . . .");
+ outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") starting at " + parameters.getBaseUri().toString()
+ + " . . .");
try {
state = EditorState.INITIALIZING;
if (parameters.getTimeToLive() == ApexServicesRestParameters.INFINITY_TIME_TO_LIVE) {
outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") started at "
- + parameters.getBaseUri().toString());
+ + parameters.getBaseUri().toString());
} else {
outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") started");
}
Thread.sleep(EDITOR_RNNING_CHECK_TIMEOUT);
}
} catch (final Exception e) {
- outStream.println(
- REST_ENDPOINT_PREFIX + this.toString() + ") failed at with error: " + e.getMessage());
+ String message = REST_ENDPOINT_PREFIX + this.toString() + ") failed at with error: " + e.getMessage();
+ outStream.println(message);
+ LOGGER.warn(message, e);
} finally {
if (apexServices != null) {
apexServices.shutdown();
public String toString() {
final StringBuilder ret = new StringBuilder();
ret.append(this.getClass().getSimpleName()).append(": Config=[").append(parameters).append("], State=")
- .append(this.getState());
+ .append(this.getState());
return ret.toString();
}
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
public final class ParameterCheck {
+ // Recurring string constants
+ private static final String PARAMETER = "parameter \"";
+ private static final String NOT_FOUND = "\" not found";
+
private static final int MAX_PORT = 65535;
/**
* private constructor to prevent subclassing of this utility class.
*/
- private ParameterCheck() {}
+ private ParameterCheck() {
+ }
/**
* The Enum StartStop is used to hold.
*/
public static String getHostName(final Map<String, String[]> parameterMap) {
if (!parameterMap.containsKey(HOSTNAME_PAR)) {
- LOGGER.warn("parameter \"" + HOSTNAME_PAR + "\" not found");
+ LOGGER.warn(PARAMETER + HOSTNAME_PAR + NOT_FOUND);
return null;
}
final String[] hostNameValue = parameterMap.get(HOSTNAME_PAR);
if (hostNameValue.length == 0 || hostNameValue[0].trim().length() == 0) {
- LOGGER.warn("value of parameter \"" + HOSTNAME_PAR + "\" not found");
+ LOGGER.warn("value of parameter \"" + HOSTNAME_PAR + NOT_FOUND);
return null;
}
*/
public static int getPort(final Map<String, String[]> parameterMap) {
if (!parameterMap.containsKey(PORT_PAR)) {
- LOGGER.warn("parameter \"" + PORT_PAR + "\" not found");
+ LOGGER.warn(PARAMETER + PORT_PAR + NOT_FOUND);
return -1;
}
final String[] portValue = parameterMap.get(PORT_PAR);
if (portValue.length == 0 || portValue[0].trim().length() == 0) {
- LOGGER.warn("value of parameter \"" + PORT_PAR + "\" not found");
+ LOGGER.warn("value of parameter \"" + PORT_PAR + NOT_FOUND);
return -1;
}
try {
port = Integer.parseInt(portValue[0]);
} catch (final Exception e) {
- LOGGER.warn("value \"" + portValue[0] + "\"of parameter \"" + PORT_PAR + "\" not a valid integer", e);
+ LOGGER.warn("value \"{}\"of parameter \"" + PORT_PAR + "\" not a valid integer", portValue[0], e);
return -1;
}
if (port <= 0 || port > MAX_PORT) {
- LOGGER.warn("value \"" + portValue[0] + "\"of parameter \"" + PORT_PAR
- + "\" not a valid port between 0 and 65535");
+ LOGGER.warn("value \"{}\"of parameter \"" + PORT_PAR + "\" not a valid port between 0 and 65535",
+ portValue[0]);
return -1;
}
}
}
if (artifactKeyParameter == null) {
- LOGGER.warn("parameter \"" + AXARTIFACTKEY_PAR + "\" not found");
+ LOGGER.warn(PARAMETER + AXARTIFACTKEY_PAR + NOT_FOUND);
return null;
}
final String[] axArtifactKeyArray = artifactKeyParameter.split("#");
if (axArtifactKeyArray.length != 2) {
- LOGGER.warn("value \"" + artifactKeyParameter + "\" of parameter \"" + AXARTIFACTKEY_PAR + "\" not valid");
+ LOGGER.warn("value \"{}\" of parameter \"" + AXARTIFACTKEY_PAR + "\" not valid", artifactKeyParameter);
return null;
}
* @return the start stop
*/
public static ParameterCheck.StartStop getStartStop(final Map<String, String[]> parameterMap,
- final AxArtifactKey engineKey) {
+ final AxArtifactKey engineKey) {
final String startStopPar = AXARTIFACTKEY_PAR + '#' + engineKey.getId();
if (!parameterMap.containsKey(startStopPar)) {
- LOGGER.warn("parameter \"" + startStopPar + "\" not found");
+ LOGGER.warn("parameter \"{}\" not found", startStopPar);
return null;
}
final String[] startStopValue = parameterMap.get(startStopPar);
if (startStopValue.length == 0 || startStopValue[0].trim().length() == 0) {
- LOGGER.warn("value of parameter \"" + startStopPar + "\" not found");
+ LOGGER.warn("value of parameter \"{}\" not found", startStopPar);
return null;
}
} else if (startStopValue[0].equalsIgnoreCase("stop")) {
startStop = ParameterCheck.StartStop.STOP;
} else {
- LOGGER.warn("value \"" + startStopValue[0] + "\"of parameter \"" + startStopPar
- + "\" not \"start\" or \"stop\"");
+ LOGGER.warn("value \"{}\" of parameter \"{}\" not \"start\" or \"stop\"", startStopValue[0], startStopPar);
return null;
}
*/
public static long getLong(final Map<String, String[]> parameterMap, final String longName) {
if (!parameterMap.containsKey(longName)) {
- LOGGER.warn("parameter \"" + longName + "\" not found");
+ LOGGER.warn("parameter \"{}\" not found", longName);
return -1;
}
final String[] longValue = parameterMap.get(longName);
if (longValue.length == 0 || longValue[0].trim().length() == 0) {
- LOGGER.warn("value of parameter \"" + longName + "\" not found");
+ LOGGER.warn("value of parameter \"{}\" not found", longName);
return -1;
}
try {
return Long.parseLong(longValue[0]);
} catch (final Exception e) {
- LOGGER.warn("value \"" + longValue[0] + "\"of parameter \"" + longName + "\" not a valid long", e);
+ LOGGER.warn("value \"{}\"of parameter \"{}\" not a valid long", longValue[0], longName, e);
return -1;
}
}
parameters = parser.parse(args);
} catch (final ApexMonitoringRestParameterException e) {
throw new ApexMonitoringRestParameterException(
- REST_ENDPOINT_PREFIX + this.toString() + ") parameter error, " + e.getMessage() + '\n'
- + parser.getHelp(ApexMonitoringRestMain.class.getCanonicalName()));
+ REST_ENDPOINT_PREFIX + this.toString() + ") parameter error, " + e.getMessage() + '\n'
+ + parser.getHelp(ApexMonitoringRestMain.class.getCanonicalName()), e);
}
if (parameters.isHelpSet()) {
throw new ApexMonitoringRestParameterException(
- parser.getHelp(ApexMonitoringRestMain.class.getCanonicalName()));
+ parser.getHelp(ApexMonitoringRestMain.class.getCanonicalName()));
}
// Validate the parameters
final String validationMessage = parameters.validate();
if (validationMessage.length() > 0) {
throw new ApexMonitoringRestParameterException(
- REST_ENDPOINT_PREFIX + this.toString() + ") parameters invalid, " + validationMessage
- + '\n' + parser.getHelp(ApexMonitoringRestMain.class.getCanonicalName()));
+ REST_ENDPOINT_PREFIX + this.toString() + ") parameters invalid, " + validationMessage + '\n'
+ + parser.getHelp(ApexMonitoringRestMain.class.getCanonicalName()));
}
state = ServicesState.READY;
* Initialize the rest service.
*/
public void init() {
- outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") starting at "
- + parameters.getBaseUri().toString() + " . . .");
+ outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") starting at " + parameters.getBaseUri().toString()
+ + " . . .");
try {
state = ServicesState.INITIALIZING;
if (parameters.getTimeToLive() == ApexMonitoringRestParameters.INFINITY_TIME_TO_LIVE) {
outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") started at "
- + parameters.getBaseUri().toString());
+ + parameters.getBaseUri().toString());
} else {
outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") started");
}
Thread.sleep(1000);
}
} catch (final Exception e) {
- outStream.println(
- REST_ENDPOINT_PREFIX + this.toString() + ") failed at with error: " + e.getMessage());
+ String message = REST_ENDPOINT_PREFIX + this.toString() + ") failed at with error: " + e.getMessage();
+ outStream.println(message);
+ LOGGER.warn(message, e);
} finally {
if (apexMonitoringRest != null) {
apexMonitoringRest.shutdown();
public String toString() {
final StringBuilder ret = new StringBuilder();
ret.append(this.getClass().getSimpleName()).append(": Config=[").append(this.parameters).append("], State=")
- .append(this.getState());
+ .append(this.getState());
return ret.toString();
}
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
public final class ParameterCheck {
+ // Recurring string constants
+ private static final String PARAMETER = "parameter \"";
+ private static final String NOT_FOUND = "\" not found";
+
private static final int MAX_PORT = 65535;
/**
* private constructor to prevent subclassing of this utility class.
*/
- private ParameterCheck() {}
+ private ParameterCheck() {
+ }
/**
* The Enum StartStop is used to hold .
*/
public static String getHostName(final Map<String, String[]> parameterMap) {
if (!parameterMap.containsKey(HOSTNAME_PAR)) {
- LOGGER.warn("parameter \"" + HOSTNAME_PAR + "\" not found");
+ LOGGER.warn(PARAMETER + HOSTNAME_PAR + NOT_FOUND);
return null;
}
final String[] hostNameValue = parameterMap.get(HOSTNAME_PAR);
if (hostNameValue.length == 0 || hostNameValue[0].trim().length() == 0) {
- LOGGER.warn("value of parameter \"" + HOSTNAME_PAR + "\" not found");
+ LOGGER.warn("value of parameter \"" + HOSTNAME_PAR + NOT_FOUND);
return null;
}
*/
public static int getPort(final Map<String, String[]> parameterMap) {
if (!parameterMap.containsKey(PORT_PAR)) {
- LOGGER.warn("parameter \"" + PORT_PAR + "\" not found");
+ LOGGER.warn(PARAMETER + PORT_PAR + NOT_FOUND);
return -1;
}
final String[] portValue = parameterMap.get(PORT_PAR);
if (portValue.length == 0 || portValue[0].trim().length() == 0) {
- LOGGER.warn("value of parameter \"" + PORT_PAR + "\" not found");
+ LOGGER.warn("value of parameter \"" + PORT_PAR + NOT_FOUND);
return -1;
}
try {
port = Integer.parseInt(portValue[0]);
} catch (final Exception e) {
- LOGGER.warn("value \"" + portValue[0] + "\"of parameter \"" + PORT_PAR + "\" not a valid integer", e);
+ LOGGER.warn("value \"{}\"of parameter \"" + PORT_PAR + "\" not a valid integer", portValue[0], e);
return -1;
}
if (port <= 0 || port > MAX_PORT) {
- LOGGER.warn("value \"" + portValue[0] + "\"of parameter \"" + PORT_PAR
- + "\" not a valid port between 0 and 65535");
+ LOGGER.warn("value \"{}\"of parameter \"" + PORT_PAR + "\" not a valid port between 0 and 65535",
+ portValue[0]);
return -1;
}
}
}
if (artifactKeyParameter == null) {
- LOGGER.warn("parameter \"" + AXARTIFACTKEY_PAR + "\" not found");
+ LOGGER.warn(PARAMETER + AXARTIFACTKEY_PAR + NOT_FOUND);
return null;
}
final String[] axArtifactKeyArray = artifactKeyParameter.split("#");
if (axArtifactKeyArray.length != 2) {
- LOGGER.warn("value \"" + artifactKeyParameter + "\" of parameter \"" + AXARTIFACTKEY_PAR + "\" not valid");
+ LOGGER.warn("value \"{}\" of parameter \"" + AXARTIFACTKEY_PAR + "\" not valid", artifactKeyParameter);
return null;
}
* @return the start stop
*/
public static ParameterCheck.StartStop getStartStop(final Map<String, String[]> parameterMap,
- final AxArtifactKey engineKey) {
+ final AxArtifactKey engineKey) {
final String startStopPar = AXARTIFACTKEY_PAR + '#' + engineKey.getId();
if (!parameterMap.containsKey(startStopPar)) {
- LOGGER.warn("parameter \"" + startStopPar + "\" not found");
+ LOGGER.warn("parameter \"{}\" not found", startStopPar);
return null;
}
final String[] startStopValue = parameterMap.get(startStopPar);
if (startStopValue.length == 0 || startStopValue[0].trim().length() == 0) {
- LOGGER.warn("value of parameter \"" + startStopPar + "\" not found");
+ LOGGER.warn("value of parameter \"{}\" not found", startStopPar);
return null;
}
} else if (startStopValue[0].equalsIgnoreCase("stop")) {
startStop = ParameterCheck.StartStop.STOP;
} else {
- LOGGER.warn("value \"" + startStopValue[0] + "\"of parameter \"" + startStopPar
- + "\" not \"start\" or \"stop\"");
+ LOGGER.warn("value \"{}\"of parameter \"{}\" not \"start\" or \"stop\"", startStopValue[0], startStopPar);
return null;
}
*/
public static long getLong(final Map<String, String[]> parameterMap, final String longName) {
if (!parameterMap.containsKey(longName)) {
- LOGGER.warn("parameter \"" + longName + "\" not found");
+ LOGGER.warn("parameter \"{}\" not found", longName);
return -1;
}
final String[] longValue = parameterMap.get(longName);
if (longValue.length == 0 || longValue[0].trim().length() == 0) {
- LOGGER.warn("value of parameter \"" + longName + "\" not found");
+ LOGGER.warn("value of parameter \"{}\" not found", longName);
return -1;
}
try {
return Long.parseLong(longValue[0]);
} catch (final Exception e) {
- LOGGER.warn("value \"" + longValue[0] + "\"of parameter \"" + longName + "\" not a valid long", e);
+ LOGGER.warn("value \"{}\"of parameter \"{}\" not a valid long", longValue[0], longName, e);
return -1;
}
}
final String returnString = getUserKey().getId() + ": object \"" + object.toString() + "\" of class \""
+ object.getClass().getCanonicalName() + "\" not compatible with class \""
+ getSchemaClass().getCanonicalName() + "\"";
- LOGGER.warn(returnString);
+ LOGGER.warn(returnString, e);
throw new ContextRuntimeException(returnString);
}
}
schemaHelper.unmarshal(value);
return true;
} catch (final Exception e) {
+ if (LOGGER.isTraceEnabled()) {
+ LOGGER.trace("value {} is not assignable to this field", value, e);
+ }
return false;
}
}
xpath = XPathFactory.newInstance().newXPath();
LOGGER.info("Initialized XPath reader");
} catch (final Exception ex) {
- LOGGER.error("Error parsing XML file/stream from XPath reading, reason :\n" + ex.getMessage());
+ LOGGER.error("Error parsing XML file/stream from XPath reading, reason :\n" + ex.getMessage(), ex);
}
}
final XPathExpression xPathExpression = xpath.compile(expression);
return xPathExpression.evaluate(xmlDocument, returnType);
} catch (final XPathExpressionException ex) {
- LOGGER.error("Failed to read XML file for XPath processing, reason:\n" + ex.getMessage());
+ LOGGER.error("Failed to read XML file for XPath processing, reason:\n" + ex.getMessage(), ex);
return null;
}
}
*/
@Override
public void onEnEvent(final EnEvent actionEvent) {
- try {
- Thread.sleep(100);
- } catch (final InterruptedException e) {
- e.printStackTrace();
- }
+ ThreadUtilities.sleep(100);
+
if (actionEvent != null) {
System.out.println("Action event from engine:" + actionEvent.getName());
resultEvents.add(actionEvent);
public class AutoLearn implements Serializable {
private static final long serialVersionUID = 3825970380434170754L;
- private List<Double> avDiffs = null;
+ private transient List<Double> avDiffs = null;
- private List<Long> counts = null;
+ private transient List<Long> counts = null;
/**
* Checks if the Autolearn instance is initialized.
import org.onap.policy.apex.core.engine.engine.ApexEngine;
import org.onap.policy.apex.core.engine.engine.impl.ApexEngineFactory;
import org.onap.policy.apex.core.engine.event.EnEvent;
+import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
import org.onap.policy.apex.examples.adaptive.model.AdaptiveDomainModelFactory;
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
assertEquals("ExecutionIDs are different", triggerEvent.getExecutionId(), result.getExecutionId());
triggerEvent.clear();
result.clear();
- Thread.sleep(1);
+ ThreadUtilities.sleep(1);
apexEngine1.stop();
}
result.clear();
}
apexEngine1.stop();
- Thread.sleep(1000);
+ ThreadUtilities.sleep(1000);
}
/**
*/
@Override
public void onEnEvent(final EnEvent actionEvent) {
- try {
- Thread.sleep(100);
- } catch (final InterruptedException e) {
- e.printStackTrace();
- }
+ ThreadUtilities.sleep(100);
+
if (actionEvent != null) {
System.out.println("Action event from engine:" + actionEvent.getName());
resultEvents.add(actionEvent);
import org.onap.policy.apex.core.engine.engine.ApexEngine;
import org.onap.policy.apex.core.engine.engine.impl.ApexEngineFactory;
import org.onap.policy.apex.core.engine.event.EnEvent;
+import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
import org.onap.policy.apex.examples.adaptive.model.AdaptiveDomainModelFactory;
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
assertEquals("ExecutionIDs are different", triggerEvent.getExecutionId(), result.getExecutionId());
triggerEvent.clear();
result.clear();
- Thread.sleep(1);
+ ThreadUtilities.sleep(10);
apexEngine1.stop();
}
LOGGER.info("Iteration " + iteration + ": \tpreval\t" + prevval + "\tval\t" + val + "\tavval\t" + avval);
result.clear();
- Thread.sleep(1);
+ ThreadUtilities.sleep(10);
}
apexEngine1.stop();
- Thread.sleep(1000);
-
+ ThreadUtilities.sleep(1000);
}
/**
*/
@Override
public void onEnEvent(final EnEvent saleauthEvent) {
- try {
- Thread.sleep(100);
- } catch (final InterruptedException e) {
- e.printStackTrace();
- }
+ ThreadUtilities.sleep(100);
+
if (saleauthEvent != null) {
System.out.println("SaleAuth event from engine:" + saleauthEvent.getName());
resultEvents.add(saleauthEvent);
*/
public class AaiAndGuardSim {
private static final String BASE_URI = "http://localhost:54321/AAIAndGuardSim";
+ private static final int MAX_LOOPS = 100000;
private HttpServer server;
/**
public static void main(final String[] args) throws Exception {
final AaiAndGuardSim sim = new AaiAndGuardSim();
- while (true) {
- try {
- Thread.sleep(100);
- } catch (final InterruptedException e) {
- break;
- }
+ for (int index = 0; index < MAX_LOOPS; index++) {
+ ThreadUtilities.sleep(100);
}
+
sim.tearDown();
}
}
final String configFileName = servletContextEvent.getServletContext().getInitParameter("config-file");
final String modelFileName = servletContextEvent.getServletContext().getInitParameter("model-file");
- LOGGER.info("Apex Servliet has been started, config-file= " + configFileName + ", model-file=" + modelFileName);
+ LOGGER.info("Apex Servliet has been started, config-file={}, model-file={}", configFileName, modelFileName);
// Check that a configuration file have been specified
if (servletContextEvent.getServletContext().getInitParameter("config-file") == null) {
}
// Construct the Apex command line arguments
- final List<String> argsList = new ArrayList<String>();
+ final List<String> argsList = new ArrayList<>();
argsList.add("-config-file");
argsList.add(configFileName);
"scope is not defined"));
}
- try {
- Assertions.validateStringParameter(SCOPE_STRING, scope, SCOPE_REGEXP);
- } catch (final IllegalArgumentException e) {
+ String stringCheckResult = Assertions.getStringParameterValidationMessage(SCOPE_STRING, scope, SCOPE_REGEXP);
+ if (stringCheckResult != null) {
result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "scope invalid-" + e.getMessage()));
+ "scope invalid-" + stringCheckResult));
}
if (itemSchema.equals(AxArtifactKey.getNullKey())) {
"schema flavour is not defined"));
}
- try {
- Assertions.validateStringParameter(SCHEMA_FLAVOUR, schemaFlavour, SCHEMA_FLAVOUR_REGEXP);
- } catch (final IllegalArgumentException e) {
+ String flavourValidationResult = Assertions.getStringParameterValidationMessage(SCHEMA_FLAVOUR, schemaFlavour,
+ SCHEMA_FLAVOUR_REGEXP);
+ if (flavourValidationResult != null) {
result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "schema flavour invalid-" + e.getMessage()));
+ "schema flavour invalid-" + flavourValidationResult));
}
if (schemaDefinition.replaceAll(WHITESPACE_REGEXP, "").length() == 0) {
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
public class TestEngineStats {
+ private static final Object WAIT_LOCK = new Object();
@Test
public void testEngineStats() {
stats.engineStart();
stats.setEventCount(4);
stats.executionEnter(new AxArtifactKey());
- try {
- Thread.sleep(10);
- } catch (final Exception e) {
- fail("test should not throw an exeption");
+
+ synchronized (WAIT_LOCK) {
+ try {
+ WAIT_LOCK.wait(10);
+ } catch (InterruptedException e) {
+ fail("test should not throw an exception");
+ }
}
+
stats.executionExit();
final double avExecutionTime = stats.getAverageExecutionTime();
assertTrue(avExecutionTime >= 2.0 && avExecutionTime < 10.0);
"logic flavour is not defined"));
}
- try {
- Assertions.validateStringParameter(LOGIC_FLAVOUR_TOKEN, logicFlavour, LOGIC_FLAVOUR_REGEXP);
- } catch (final IllegalArgumentException e) {
+ String flavourValidationString = Assertions.getStringParameterValidationMessage(LOGIC_FLAVOUR_TOKEN,
+ logicFlavour, LOGIC_FLAVOUR_REGEXP);
+ if (flavourValidationString != null) {
result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "logic flavour invalid-" + e.getMessage()));
+ "logic flavour invalid-" + flavourValidationString));
}
if (logic.replaceAll(WHITESPACE_REGEXP, "").length() == 0) {
import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult;
import org.onap.policy.apex.model.utilities.Assertions;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
/**
* This class holds the definition of an Apex policy. A policy is made up of a tree of states, each represented by an
public class AxPolicy extends AxConcept {
private static final long serialVersionUID = -1775614096390365941L;
+ // Logger for this class
+ private static final XLogger LOGGER = XLoggerFactory.getXLogger(AxPolicy.class);
+
@EmbeddedId
@XmlElement(name = "policyKey", required = true)
private AxArtifactKey key;
*/
private AxValidationResult validateStateTree(AxValidationResult result) {
try {
- // Cpnstructor validates policy state tree
+ // Constructor validates policy state tree
AxStateTree policyStateTree = getStateTree();
// Check for unused states
+ " is not referenced in the policy execution tree"));
}
} catch (PolicyRuntimeException pre) {
- result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.WARNING,
- "state tree in policy is invalid"));
+ AxValidationMessage validationMessage = new AxValidationMessage(key, this.getClass(),
+ ValidationResult.WARNING, "state tree in policy is invalid");
+ LOGGER.trace(validationMessage.getMessage(), pre);
+ result.addValidationMessage(validationMessage);
}
return result;
package org.onap.policy.apex.model.utilities;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+
/**
* The Class Assertions is a template class that is used as a shorthand for assertions in the source code.
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
public final class Assertions {
+ // Logger for this class
+ private static final XLogger LOGGER = XLoggerFactory.getXLogger(Assertions.class);
+
/**
* Private constructor used to prevent sub class instantiation.
*/
try {
validateStringParameter(parameterName, parameterValue, pattern);
} catch (IllegalArgumentException e) {
- // This will cause a SONAR error but eliminates all SONAR messages in callers
- return e.getMessage();
+ String message = "parameter " + parameterName + " with value " + parameterValue
+ + " does not match regular expression " + pattern;
+ if (LOGGER.isTraceEnabled()) {
+ LOGGER.trace(message, e);
+ }
+
+ return message;
}
return null;
import java.util.ArrayList;
import java.util.List;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+
//CHECKSTYLE:OFF: checkstyle:IllegalImport
import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl;
//CHECKSTYLE:ON: checkstyle:IllegalImport
*/
@SuppressWarnings("restriction")
public class ClassBuilder {
+ // Logger for this class
+ private static final XLogger LOGGER = XLoggerFactory.getXLogger(ClassBuilder.class);
+
private final Class<?> clazz;
private final List<ClassBuilder> parameters = new ArrayList<>();
} catch (ClassNotFoundException e) {
try {
return new ClassBuilder(Class.forName("java.lang." + className));
- } catch (Exception ignore) {
+ } catch (Exception classFindException) {
+ LOGGER.warn("class nout found", classFindException);
throw new IllegalArgumentException("Class '" + className
+ "' not found. Also looked for a class called 'java.lang." + className + "'", e);
}
} catch (final Exception e) {
final String resultSting = userKey.getId() + ": avro context schema \"" + schema.getId()
+ "\" schema is invalid: " + e.getMessage() + ", schema: " + schema.getSchema();
- LOGGER.warn(resultSting);
+ LOGGER.warn(resultSting, e);
throw new ContextRuntimeException(resultSting);
}
+ (object != null ? object.getClass().getCanonicalName() : "null")
+ "\" must be assignable to \"" + getSchemaClass().getCanonicalName()
+ "\" or be a Json string representation of it for Avro unmarshalling";
- LOGGER.warn(returnString);
+ LOGGER.warn(returnString, e);
throw new ContextRuntimeException(returnString);
}
}
} catch (final Exception e) {
final String errorMessage = COULD_NOT_SEND_PREFIX + eventname + JMS_MESSAGE_PRODUCER_TAG
+ this.name + ", could not create JMS Object Message for object \"" + eventObject;
- LOGGER.warn(errorMessage);
+ LOGGER.warn(errorMessage, e);
throw new ApexEventRuntimeException(errorMessage);
}
} else {
} catch (final Exception e) {
final String errorMessage = COULD_NOT_SEND_PREFIX + eventname + JMS_MESSAGE_PRODUCER_TAG
+ this.name + ", could not create JMS Text Message for object \"" + eventObject;
- LOGGER.warn(errorMessage);
+ LOGGER.warn(errorMessage, e);
throw new ApexEventRuntimeException(errorMessage);
}
}
} catch (final Exception e) {
final String errorMessage = COULD_NOT_SEND_PREFIX + eventname + JMS_MESSAGE_PRODUCER_TAG + this.name
+ ", send failed for object \"" + eventObject;
- LOGGER.warn(errorMessage);
+ LOGGER.warn(errorMessage, e);
throw new ApexEventRuntimeException(errorMessage);
}
}
} catch (final Exception e) {
final String errorMessage = "could not queue request \"" + restRequest + "\" on REST Requestor consumer ("
+ this.name + ")";
- LOGGER.warn(errorMessage);
+ LOGGER.warn(errorMessage, e);
throw new ApexEventRuntimeException(errorMessage);
}
}
eventReceiver.receiveEvent(executionId, event);
} catch (final Exception e) {
final String errorMessage = "error receiving events on event consumer " + name + ", " + e.getMessage();
- LOGGER.warn(errorMessage);
+ LOGGER.warn(errorMessage, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode())
.entity("{'errorMessage', '" + errorMessage + "'}").build();
}
try {
wsStringMessager.start(this);
} catch (final MessagingException e) {
- LOGGER.warn("could not start web socket consumer");
+ LOGGER.warn("could not start web socket consumer", e);
}
}
} catch (final Exception e) {
final String errorMessage = "Error sending event " + name + '_' + eventsRead + ", " + e.getMessage()
+ ", event:\n" + eventString;
- LOGGER.warn(errorMessage);
+ LOGGER.warn(errorMessage, e);
}
}
}
wsStringMessager.start(this);
} catch (final MessagingException e) {
String message = "could not start web socket producer (" + this.name + ")";
- LOGGER.warn(message);
+ LOGGER.warn(message, e);
}
}
} catch (Exception e) {
final String errorMessage = "message \"" + eventObject
+ "\" received from JMS does not have a \"getObject()\" method";
- LOGGER.warn(errorMessage);
+ LOGGER.warn(errorMessage, e);
throw new ApexEventRuntimeException(errorMessage);
}
} catch (Exception e) {
final String errorMessage = "message \"" + eventObject
+ "\" received from JMS does not have a \"getText()\" method";
- LOGGER.warn(errorMessage);
+ LOGGER.warn(errorMessage, e);
throw new ApexEventRuntimeException(errorMessage);
}
import java.util.concurrent.atomic.AtomicLong;
import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
-import org.slf4j.ext.XLogger;
-import org.slf4j.ext.XLoggerFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* The Class ApexEvent is an event class that external systems use to send events to and receive
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
public class ApexEvent extends HashMap<String, Object> implements Serializable {
- // Recurring string constants
- private static final String EVENT_PREAMBLE = "event \"";
+ private static final long serialVersionUID = -4451918242101961685L;
- private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexEvent.class);
+ // Get a reference to the logger
+ private static final Logger LOGGER = LoggerFactory.getLogger(ApexEvent.class);
- private static final long serialVersionUID = -4451918242101961685L;
+ // Recurring string constants
+ private static final String EVENT_PREAMBLE = "event \"";
// Holds the next identifier for event execution.
private static AtomicLong nextExecutionID = new AtomicLong(0L);
try {
return super.put(validKey(key), value);
} catch (final ApexEventException e) {
+ if (LOGGER.isTraceEnabled()) {
+ LOGGER.trace("put failed", e);
+ }
return null;
}
}
validKey(key);
}
} catch (final ApexEventException e) {
+ if (LOGGER.isTraceEnabled()) {
+ LOGGER.trace("putAll failed", e);
+ }
+
// One of the keys is invalid
return;
}
} catch (final Exception e) {
final String errorMessage =
"could not queue request \"" + eventObject + "\" on event Requestor consumer (" + this.name + ")";
- LOGGER.warn(errorMessage);
+ LOGGER.warn(errorMessage, e);
throw new ApexEventRuntimeException(errorMessage);
}
}
} catch (final Exception e) {
// The element is not a string so throw an error
throw new ApexEventRuntimeException("field \"" + fieldName + "\" with type \""
- + jsonField.getClass().getCanonicalName() + "\" is not a string value");
+ + jsonField.getClass().getCanonicalName() + "\" is not a string value", e);
}
// Is regular expression checking required
try {
parse(args);
} catch (final ApexException e) {
- throw new ApexRuntimeException("parse error on Apex parameters");
+ throw new ApexRuntimeException("parse error on Apex parameters", e);
}
}
import org.onap.policy.common.parameters.GroupValidationResult;
import org.onap.policy.common.parameters.ParameterGroup;
import org.onap.policy.common.parameters.ValidationStatus;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* The parameters for a single event producer, event consumer or synchronous event handler.
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
public class EventHandlerParameters implements ParameterGroup {
+ // Get a reference to the logger
+ private static final Logger LOGGER = LoggerFactory.getLogger(EventHandlerParameters.class);
+
private String name = null;
private CarrierTechnologyParameters carrierTechnologyParameters = null;
private EventProtocolParameters eventProtocolParameters = null;
try {
Pattern.compile(eventNameFilter);
} catch (final PatternSyntaxException pse) {
- result.setResult("eventNameFilter", ValidationStatus.INVALID,
- "event handler eventNameFilter is not a valid regular expression: " + pse.getMessage());
+ String message = "event handler eventNameFilter is not a valid regular expression: " + pse.getMessage();
+ LOGGER.trace(message, pse);
+ result.setResult("eventNameFilter", ValidationStatus.INVALID, message);
}
}
/**
* Get the requestor timeout.
+ *
* @return the requestorTimeout.
*/
public long getRequestorTimeout() {
* @return the sample policy model
*/
public AxPolicyModel getOodaPolicyModel() {
- final AxTasks tasks = new AxTasks(new AxArtifactKey("Tasks", "0.0.1"));
+ final AxTasks tasks = new AxTasks(new AxArtifactKey("Tasks", DEFAULT_VERSION));
final AxLogicReader logicReader = new PolicyLogicReader().setLogicPackage(PACKAGE)
.setDefaultLogic("EvalTask_Logic");
import org.onap.policy.apex.tools.common.CliOptions;
import org.onap.policy.apex.tools.common.CliParser;
import org.onap.policy.apex.tools.common.OutputFile;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Process an Apex Policy Model file to generate the CLI commands to generate an equivalent Apex Policy Model.
* @author Sven van der Meer <sven.van.der.meer@ericsson.com>
*/
public final class Application {
+ // Get a reference to the logger
+ private static final Logger LOGGER = LoggerFactory.getLogger(Application.class);
/** The name of the application. */
public static final String APP_NAME = "gen-model2cli";
final Model2Cli app = new Model2Cli(modelFile, outfile, !cmd.hasOption("sv"), APP_NAME);
app.runApp();
} catch (final ApexException aex) {
- System.err.println(APP_NAME + ": caught APEX exception with message: " + aex.getMessage());
+ String message = APP_NAME + ": caught APEX exception with message: " + aex.getMessage();
+ System.err.println(message);
+ LOGGER.warn(message, aex);
}
}
}
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
import org.onap.policy.apex.tools.common.CliOptions;
import org.onap.policy.apex.tools.common.CliParser;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Model 2 event generator with main method.
* @author Sven van der Meer (sven.van.der.meer@ericsson.com)
*/
public final class Application {
+ // Get a reference to the logger
+ private static final Logger LOGGER = LoggerFactory.getLogger(Application.class);
/** The name of the application. */
public static final String APP_NAME = "gen-model2event";
final Model2JsonEventSchema app = new Model2JsonEventSchema(modelFile, type, APP_NAME);
app.runApp();
} catch (final ApexException aex) {
- System.err.println(APP_NAME + ": caught APEX exception with message: " + aex.getMessage());
+ String message = APP_NAME + ": caught APEX exception with message: " + aex.getMessage();
+ System.err.println(message);
+ LOGGER.warn(message, aex);
}
}
}
import org.apache.commons.lang3.Validate;
import org.onap.policy.apex.tools.common.CliOptions;
import org.onap.policy.apex.tools.common.CliParser;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Simple console application with main method.
* @author Sven van der Meer (sven.van.der.meer@ericsson.com)
*/
public final class Application {
+ // Get a reference to the logger
+ private static final Logger LOGGER = LoggerFactory.getLogger(Application.class);
/**
* Private constructor prevents subclassing.
final SimpleEcho simpleEcho = new SimpleEcho(server, port, appName);
simpleEcho.connect();
} catch (final URISyntaxException uex) {
- System.err.println(appName + ": URI exception, could not create URI from server and port settings");
+ String message = appName + ": URI exception, could not create URI from server and port settings";
+ System.err.println(message);
+ LOGGER.warn(message, uex);
} catch (final NullPointerException nex) {
- System.err.println(appName + ": null pointer, server or port were null");
+ String message = appName + ": null pointer, server or port were null";
+ System.err.println(message);
+ LOGGER.warn(message, nex);
} catch (final IllegalArgumentException iex) {
- System.err.println(appName + ": illegal argument, server or port were blank");
+ String message = appName + ": illegal argument, server or port were blank";
+ System.err.println(message);
+ LOGGER.warn(message, iex);
}
}
final SimpleConsole simpleConsole = new SimpleConsole(server, port, appName);
simpleConsole.runClient();
} catch (final URISyntaxException uex) {
- System.err.println(appName + ": URI exception, could not create URI from server and port settings");
+ String message = appName + ": URI exception, could not create URI from server and port settings";
+ System.err.println(message);
+ LOGGER.warn(message, uex);
} catch (final NullPointerException nex) {
- System.err.println(appName + ": null pointer, server or port were null");
+ String message = appName + ": null pointer, server or port were null";
+ System.err.println(message);
+ LOGGER.warn(message, nex);
} catch (final IllegalArgumentException iex) {
- System.err.println(appName + ": illegal argument, server or port were blank");
+ String message = appName + ": illegal argument, server or port were blank";
+ System.err.println(message);
+ LOGGER.warn(message, iex);
} catch (final NotYetConnectedException nex) {
- System.err.println(appName + ": not yet connected, connection to server took too long");
+ String message = appName + ": not yet connected, connection to server took too long";
+ System.err.println(message);
+ LOGGER.warn(message, nex);
} catch (final IOException ioe) {
- System.err.println(appName + ": IO exception, something went wrong on the standard input");
+ String message = appName + ": IO exception, something went wrong on the standard input";
+ System.err.println(message);
+ LOGGER.warn(message, ioe);
}
}
}
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.StrBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.slf4j.ext.XLoggerFactory;
import org.slf4j.helpers.MessageFormatter;
* @author Sven van der Meer (sven.van.der.meer@ericsson.com)
*/
public final class Console {
-
/** The console as static object. */
public static final Console CONSOLE = new Console();
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Standard output file handling and tests.
* @author Sven van der Meer (sven.van.der.meer@ericsson.com)
*/
public class OutputFile {
+ // Get a reference to the logger
+ private static final Logger LOGGER = LoggerFactory.getLogger(OutputFile.class);
/** The output file name. */
private final String fileName;
try {
return new BufferedWriter(new FileWriter(toFile()));
} catch (final IOException e) {
+ LOGGER.warn("write error", e);
return null;
}
}
try {
return new FileOutputStream(toFile());
} catch (final IOException e) {
+ LOGGER.warn("stream creation error", e);
return null;
}
}
try {
file.createNewFile();
} catch (final IOException e) {
- return "could not create output file: " + e.getMessage();
+ String message = "could not create output file: " + e.getMessage();
+ LOGGER.warn(message, e);
+ return message;
}
}