import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
-import org.onap.dmaap.datarouter.node.eelf.EelfMsgs;
-
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.Properties;
import java.util.Timer;
+import org.onap.dmaap.datarouter.node.eelf.EelfMsgs;
/**
* Maintain the configuration of a Data Router node
- * <p>
- * The NodeConfigManager is the single point of contact for servlet, delivery, event logging, and log retention
+ *
+ * <p>The NodeConfigManager is the single point of contact for servlet, delivery, event logging, and log retention
* subsystems to access configuration information.
- * <p>
- * There are two basic sets of configuration data. The static local configuration data, stored in a local configuration
- * file (created as part of installation by SWM), and the dynamic global configuration data fetched from the data router
- * provisioning server.
+ *
+ * <p>There are two basic sets of configuration data. The static local configuration data, stored in a local
+ * configuration file (created as part of installation by SWM), and the dynamic global configuration data fetched from
+ * the data router provisioning server.
*/
public class NodeConfigManager implements DeliveryQueueHelper {
- private static EELFLogger eelfLogger = EELFManager.getInstance()
- .getLogger(NodeConfigManager.class);
+ private static final String CHANGE_ME = "changeme";
+ private static final String NODE_CONFIG_MANAGER = "NodeConfigManager";
+ private static EELFLogger eelfLogger = EELFManager.getInstance().getLogger(NodeConfigManager.class);
private static NodeConfigManager base = new NodeConfigManager();
private Timer timer = new Timer("Node Configuration Timer", true);
private String eventlogsuffix;
private String eventloginterval;
private boolean followredirects;
- private String [] enabledprotocols;
+ private String[] enabledprotocols;
private String aafType;
private String aafInstance;
private String aafAction;
/**
- * Get the default node configuration manager
- */
- public static NodeConfigManager getInstance() {
- return base;
- }
-
- /**
- * Initialize the configuration of a Data Router node
+ * Initialize the configuration of a Data Router node.
*/
private NodeConfigManager() {
drNodeProperties.load(new FileInputStream(System
.getProperty("org.onap.dmaap.datarouter.node.properties", "/opt/app/datartr/etc/node.properties")));
} catch (Exception e) {
- NodeUtils.setIpAndFqdnForEelf("NodeConfigManager");
- eelfLogger.error(EelfMsgs.MESSAGE_PROPERTIES_LOAD_ERROR, System.getProperty("org.onap.dmaap.datarouter.node.properties", "/opt/app/datartr/etc/node.properties"));
+ NodeUtils.setIpAndFqdnForEelf(NODE_CONFIG_MANAGER);
+ eelfLogger.error(EelfMsgs.MESSAGE_PROPERTIES_LOAD_ERROR, e,
+ System.getProperty("org.onap.dmaap.datarouter.node.properties",
+ "/opt/app/datartr/etc/node.properties"));
}
provurl = drNodeProperties.getProperty("ProvisioningURL", "https://dmaap-dr-prov:8443/internal/prov");
/*
try {
provhost = (new URL(provurl)).getHost();
} catch (Exception e) {
- NodeUtils.setIpAndFqdnForEelf("NodeConfigManager");
- eelfLogger.error(EelfMsgs.MESSAGE_BAD_PROV_URL, provurl);
+ NodeUtils.setIpAndFqdnForEelf(NODE_CONFIG_MANAGER);
+ eelfLogger.error(EelfMsgs.MESSAGE_BAD_PROV_URL, e, provurl);
System.exit(1);
}
eelfLogger.info("NODE0303 Provisioning server is " + provhost);
gfport = Integer.parseInt(drNodeProperties.getProperty("IntHttpPort", "8080"));
svcport = Integer.parseInt(drNodeProperties.getProperty("IntHttpsPort", "8443"));
port = Integer.parseInt(drNodeProperties.getProperty("ExtHttpsPort", "443"));
- long minpfinterval = Long.parseLong(drNodeProperties.getProperty("MinProvFetchInterval", "10000"));
- long minrsinterval = Long.parseLong(drNodeProperties.getProperty("MinRedirSaveInterval", "10000"));
spooldir = drNodeProperties.getProperty("SpoolDir", "spool");
File fdir = new File(spooldir + "/f");
fdir.mkdirs();
logretention = Long.parseLong(drNodeProperties.getProperty("LogRetention", "30")) * 86400000L;
eventlogprefix = logdir + "/events";
eventlogsuffix = ".log";
- String redirfile = drNodeProperties.getProperty("RedirectionFile", "etc/redirections.dat");
+ redirfile = drNodeProperties.getProperty("RedirectionFile", "etc/redirections.dat");
kstype = drNodeProperties.getProperty("KeyStoreType", "jks");
ksfile = drNodeProperties.getProperty("KeyStoreFile", "etc/keystore");
- kspass = drNodeProperties.getProperty("KeyStorePassword", "changeme");
- kpass = drNodeProperties.getProperty("KeyPassword", "changeme");
+ kspass = drNodeProperties.getProperty("KeyStorePassword", CHANGE_ME);
+ kpass = drNodeProperties.getProperty("KeyPassword", CHANGE_ME);
tstype = drNodeProperties.getProperty("TrustStoreType", "jks");
tsfile = drNodeProperties.getProperty("TrustStoreFile");
- tspass = drNodeProperties.getProperty("TrustStorePassword", "changeme");
+ tspass = drNodeProperties.getProperty("TrustStorePassword", CHANGE_ME);
if (tsfile != null && tsfile.length() > 0) {
System.setProperty("javax.net.ssl.trustStoreType", tstype);
System.setProperty("javax.net.ssl.trustStore", tsfile);
quiesce = new File(drNodeProperties.getProperty("QuiesceFile", "etc/SHUTDOWN"));
myname = NodeUtils.getCanonicalName(kstype, ksfile, kspass);
if (myname == null) {
- NodeUtils.setIpAndFqdnForEelf("NodeConfigManager");
+ NodeUtils.setIpAndFqdnForEelf(NODE_CONFIG_MANAGER);
eelfLogger.error(EelfMsgs.MESSAGE_KEYSTORE_FETCH_ERROR, ksfile);
eelfLogger.error("NODE0309 Unable to fetch canonical name from keystore file " + ksfile);
System.exit(1);
}
eelfLogger.info("NODE0304 My certificate says my name is " + myname);
pid = new PublishId(myname);
+ long minrsinterval = Long.parseLong(drNodeProperties.getProperty("MinRedirSaveInterval", "10000"));
+ long minpfinterval = Long.parseLong(drNodeProperties.getProperty("MinProvFetchInterval", "10000"));
rdmgr = new RedirManager(redirfile, minrsinterval, timer);
pfetcher = new RateLimitedOperation(minpfinterval, timer) {
public void run() {
pfetcher.request();
}
+ /**
+ * Get the default node configuration manager.
+ */
+ public static NodeConfigManager getInstance() {
+ return base;
+ }
+
private void localconfig() {
followredirects = Boolean.parseBoolean(getProvParam("FOLLOW_REDIRECTS", "false"));
eventloginterval = getProvParam("LOGROLL_INTERVAL", "30s");
try {
initfailuretimer = (long) (Double.parseDouble(getProvParam("DELIVERY_INIT_RETRY_INTERVAL")) * 1000);
} catch (Exception e) {
+ eelfLogger.trace("Error parsing DELIVERY_INIT_RETRY_INTERVAL", e);
}
try {
- waitForFileProcessFailureTimer = (long) (Double.parseDouble(getProvParam("DELIVERY_FILE_PROCESS_INTERVAL")) * 1000);
+ waitForFileProcessFailureTimer = (long) (Double.parseDouble(getProvParam("DELIVERY_FILE_PROCESS_INTERVAL"))
+ * 1000);
} catch (Exception e) {
+ eelfLogger.trace("Error parsing DELIVERY_FILE_PROCESS_INTERVAL", e);
}
try {
maxfailuretimer = (long) (Double.parseDouble(getProvParam("DELIVERY_MAX_RETRY_INTERVAL")) * 1000);
} catch (Exception e) {
+ eelfLogger.trace("Error parsing DELIVERY_MAX_RETRY_INTERVAL", e);
}
try {
expirationtimer = (long) (Double.parseDouble(getProvParam("DELIVERY_MAX_AGE")) * 1000);
} catch (Exception e) {
+ eelfLogger.trace("Error parsing DELIVERY_MAX_AGE", e);
}
try {
failurebackoff = Double.parseDouble(getProvParam("DELIVERY_RETRY_RATIO"));
} catch (Exception e) {
+ eelfLogger.trace("Error parsing DELIVERY_RETRY_RATIO", e);
}
try {
deliverythreads = Integer.parseInt(getProvParam("DELIVERY_THREADS"));
} catch (Exception e) {
+ eelfLogger.trace("Error parsing DELIVERY_THREADS", e);
}
try {
fairfilelimit = Integer.parseInt(getProvParam("FAIR_FILE_LIMIT"));
} catch (Exception e) {
+ eelfLogger.trace("Error parsing FAIR_FILE_LIMIT", e);
}
try {
fairtimelimit = (long) (Double.parseDouble(getProvParam("FAIR_TIME_LIMIT")) * 1000);
} catch (Exception e) {
+ eelfLogger.trace("Error parsing FAIR_TIME_LIMIT", e);
}
try {
fdpstart = Double.parseDouble(getProvParam("FREE_DISK_RED_PERCENT")) / 100.0;
} catch (Exception e) {
+ eelfLogger.trace("Error parsing FREE_DISK_RED_PERCENT", e);
}
try {
fdpstop = Double.parseDouble(getProvParam("FREE_DISK_YELLOW_PERCENT")) / 100.0;
} catch (Exception e) {
+ eelfLogger.trace("Error parsing FREE_DISK_YELLOW_PERCENT", e);
}
if (fdpstart < 0.01) {
fdpstart = 0.01;
private void fetchconfig() {
try {
eelfLogger.info("NodeConfigMan.fetchConfig: provurl:: " + provurl);
- Reader r = new InputStreamReader((new URL(provurl)).openStream());
- config = new NodeConfig(new ProvData(r), myname, spooldir, port, nak);
+ Reader reader = new InputStreamReader((new URL(provurl)).openStream());
+ config = new NodeConfig(new ProvData(reader), myname, spooldir, port, nak);
localconfig();
configtasks.startRun();
- Runnable rr;
- while ((rr = configtasks.next()) != null) {
- try {
- rr.run();
- } catch (Exception e) {
- eelfLogger.error("NODE0518 Exception fetchconfig: " + e);
- }
- }
+ runTasks();
} catch (Exception e) {
NodeUtils.setIpAndFqdnForEelf("fetchconfigs");
eelfLogger.error(EelfMsgs.MESSAGE_CONF_FAILED, e.toString());
- eelfLogger.error("NODE0306 Configuration failed " + e.toString() + " - try again later", e.getMessage());
+ eelfLogger.error("NODE0306 Configuration failed " + e.toString() + " - try again later", e);
pfetcher.request();
}
}
+ private void runTasks() {
+ Runnable rr;
+ while ((rr = configtasks.next()) != null) {
+ try {
+ rr.run();
+ } catch (Exception e) {
+ eelfLogger.error("NODE0518 Exception fetchconfig: " + e);
+ }
+ }
+ }
+
/**
* Process a gofetch request from a particular IP address. If the IP address is not an IP address we would go to to
* fetch the provisioning data, ignore the request. If the data has been fetched very recently (default 10
}
/**
- * Am I configured?
+ * Am I configured.
*/
public boolean isConfigured() {
return (config != null);
}
/**
- * Am I shut down?
+ * Am I shut down.
*/
public boolean isShutdown() {
return (quiesce.exists());
}
/**
- * Given a set of credentials and an IP address, is this request from another node?
+ * Given a set of credentials and an IP address, is this request from another node.
*
* @param credentials Credentials offered by the supposed node
* @param ip IP address the request came from
return (config.isPublishPermitted(feedid, credentials, ip));
}
- /**
- * Check whether delete file is allowed.
- *
- * @param subId The ID of the subscription being requested
- * @return True if the delete file is permitted for the subscriber.
- */
- public boolean isDeletePermitted(String subId) {
- return (config.isDeletePermitted(subId));
- }
-
/**
* Check whether publication is allowed for AAF Feed.
*
* @return True if the IP and credentials are valid for the specified feed.
*/
public String isPublishPermitted(String feedid, String ip) {
- return(config.isPublishPermitted(feedid, ip));
+ return (config.isPublishPermitted(feedid, ip));
+ }
+
+ /**
+ * Check whether delete file is allowed.
+ *
+ * @param subId The ID of the subscription being requested
+ * @return True if the delete file is permitted for the subscriber.
+ */
+ public boolean isDeletePermitted(String subId) {
+ return (config.isDeletePermitted(subId));
}
/**
}
/**
- * AAF changes: TDP EPIC US# 307413
- * Check AAF_instance for feed ID in NodeConfig
+ * AAF changes: TDP EPIC US# 307413 Check AAF_instance for feed ID in NodeConfig.
+ *
* @param feedid The ID of the feed specified
*/
public String getAafInstance(String feedid) {
- return(config.getAafInstance(feedid));
+ return (config.getAafInstance(feedid));
+ }
+
+ public String getAafInstance() {
+ return aafInstance;
}
/**
}
/**
- * Get a provisioned configuration parameter (from the provisioning server configuration)
+ * Get a provisioned configuration parameter (from the provisioning server configuration).
*
* @param name The name of the parameter
* @return The value of the parameter or null if it is not defined.
}
/**
- * Get a provisioned configuration parameter (from the provisioning server configuration)
+ * Get a provisioned configuration parameter (from the provisioning server configuration).
*
* @param name The name of the parameter
* @param defaultValue The value to use if the parameter is not defined
}
/**
- * Generate a publish ID
+ * Generate a publish ID.
*/
public String getPublishId() {
return (pid.next());
}
/**
- * Register a task to run whenever the configuration changes
+ * Register a task to run whenever the configuration changes.
*/
public void registerConfigTask(Runnable task) {
configtasks.addTask(task);
}
/**
- * Deregister a task to run whenever the configuration changes
+ * Deregister a task to run whenever the configuration changes.
*/
public void deregisterConfigTask(Runnable task) {
configtasks.removeTask(task);
}
/**
- * Is a destination redirected?
+ * Is a destination redirected.
*/
public boolean isDestRedirected(DestInfo destinfo) {
return (followredirects && rdmgr.isRedirected(destinfo.getSubId()));
}
/**
- * Set up redirection on receipt of a 3XX from a target URL
+ * Set up redirection on receipt of a 3XX from a target URL.
*/
public boolean handleRedirection(DestInfo destinationInfo, String redirto, String fileid) {
fileid = "/" + fileid;
}
/**
- * Set up redirection on receipt of a 3XX from a target URL
+ * Set up redirection on receipt of a 3XX from a target URL.
*/
public boolean handleRedirectionSubLevel(DeliveryTask task, DestInfo destinfo, String redirto, String fileid) {
fileid = "/" + fileid;
}
/**
- * Handle unreachable target URL
+ * Handle unreachable target URL.
*/
public void handleUnreachable(DestInfo destinationInfo) {
String subid = destinationInfo.getSubId();
}
/**
- * Get the timeout before retrying after an initial delivery failure
+ * Get the timeout before retrying after an initial delivery failure.
*/
public long getInitFailureTimer() {
return (initfailuretimer);
}
/**
- * Get the timeout before retrying after delivery and wait for file processing
+ * Get the timeout before retrying after delivery and wait for file processing.
*/
public long getWaitForFileProcessFailureTimer() {
return (waitForFileProcessFailureTimer);
}
/**
- * Get the maximum timeout between delivery attempts
+ * Get the maximum timeout between delivery attempts.
*/
public long getMaxFailureTimer() {
return (maxfailuretimer);
}
/**
- * Get the ratio between consecutive delivery attempts
+ * Get the ratio between consecutive delivery attempts.
*/
public double getFailureBackoff() {
return (failurebackoff);
}
/**
- * Get the expiration timer for deliveries
+ * Get the expiration timer for deliveries.
*/
public long getExpirationTimer() {
return (expirationtimer);
}
/**
- * Get the targets for a feed
+ * Get the targets for a feed.
*
* @param feedid The feed ID
* @return The targets this feed should be delivered to
}
/**
- * Get the creation date for a feed
+ * Get the creation date for a feed.
+ *
* @param feedid The feed ID
* @return the timestamp of creation date of feed id passed
*/
public String getCreatedDate(String feedid) {
- return(config.getCreatedDate(feedid));
+ return (config.getCreatedDate(feedid));
}
/**
- * Get the spool directory for temporary files
+ * Get the spool directory for temporary files.
*/
public String getSpoolDir() {
return (spooldir + "/f");
}
/**
- * Get the base directory for spool directories
+ * Get the spool directory for a subscription.
+ */
+ public String getSpoolDir(String subid, String remoteaddr) {
+ if (provcheck.isFrom(remoteaddr)) {
+ String sdir = config.getSpoolDir(subid);
+ if (sdir != null) {
+ eelfLogger.info("NODE0310 Received subscription reset request for subscription " + subid
+ + " from provisioning server " + remoteaddr);
+ } else {
+ eelfLogger.info("NODE0311 Received subscription reset request for unknown subscription " + subid
+ + " from provisioning server " + remoteaddr);
+ }
+ return (sdir);
+ } else {
+ eelfLogger.info("NODE0312 Received subscription reset request from unexpected server " + remoteaddr);
+ return (null);
+ }
+ }
+
+ /**
+ * Get the base directory for spool directories.
*/
public String getSpoolBase() {
return (spooldir);
}
/**
- * Get the key store type
+ * Get the key store type.
*/
public String getKSType() {
return (kstype);
}
/**
- * Get the key store file
+ * Get the key store file.
*/
public String getKSFile() {
return (ksfile);
}
/**
- * Get the key store password
+ * Get the key store password.
*/
public String getKSPass() {
return (kspass);
}
/**
- * Get the key password
+ * Get the key password.
*/
public String getKPass() {
return (kpass);
}
/**
- * Get the http port
+ * Get the http port.
*/
public int getHttpPort() {
return (gfport);
}
/**
- * Get the https port
+ * Get the https port.
*/
public int getHttpsPort() {
return (svcport);
}
/**
- * Get the externally visible https port
+ * Get the externally visible https port.
*/
public int getExtHttpsPort() {
return (port);
}
/**
- * Get the external name of this machine
+ * Get the external name of this machine.
*/
public String getMyName() {
return (myname);
}
/**
- * Get the number of threads to use for delivery
+ * Get the number of threads to use for delivery.
*/
public int getDeliveryThreads() {
return (deliverythreads);
}
/**
- * Get the URL for uploading the event log data
+ * Get the URL for uploading the event log data.
*/
public String getEventLogUrl() {
return (eventlogurl);
}
/**
- * Get the prefix for the names of event log files
+ * Get the prefix for the names of event log files.
*/
public String getEventLogPrefix() {
return (eventlogprefix);
}
/**
- * Get the suffix for the names of the event log files
+ * Get the suffix for the names of the event log files.
*/
public String getEventLogSuffix() {
return (eventlogsuffix);
}
/**
- * Get the interval between event log file rollovers
+ * Get the interval between event log file rollovers.
*/
public String getEventLogInterval() {
return (eventloginterval);
}
/**
- * Should I follow redirects from subscribers?
+ * Should I follow redirects from subscribers.
*/
public boolean isFollowRedirects() {
return (followredirects);
}
/**
- * Get the directory where the event and node log files live
+ * Get the directory where the event and node log files live.
*/
public String getLogDir() {
return (logdir);
}
/**
- * How long do I keep log files (in milliseconds)
+ * How long do I keep log files (in milliseconds).
*/
public long getLogRetention() {
return (logretention);
}
/**
- * Get the timer
+ * Get the timer.
*/
public Timer getTimer() {
return (timer);
}
/**
- * Get the feed ID for a subscription
+ * Get the feed ID for a subscription.
*
* @param subid The subscription ID
* @return The feed ID
}
/**
- * Get the authorization string this node uses
+ * Get the authorization string this node uses.
*
* @return The Authorization string for this node
*/
}
/**
- * Disable and enable protocols
- * */
+ * Disable and enable protocols.
+ */
public String[] getEnabledprotocols() {
return enabledprotocols;
}
+
public void setEnabledprotocols(String[] enabledprotocols) {
this.enabledprotocols = enabledprotocols.clone();
}
- /**
- * Get the spool directory for a subscription
- */
- public String getSpoolDir(String subid, String remoteaddr) {
- if (provcheck.isFrom(remoteaddr)) {
- String sdir = config.getSpoolDir(subid);
- if (sdir != null) {
- eelfLogger.info("NODE0310 Received subscription reset request for subscription " + subid
- + " from provisioning server " + remoteaddr);
- } else {
- eelfLogger.info("NODE0311 Received subscription reset request for unknown subscription " + subid
- + " from provisioning server " + remoteaddr);
- }
- return (sdir);
- } else {
- eelfLogger.info("NODE0312 Received subscription reset request from unexpected server " + remoteaddr);
- return (null);
- }
- }
-
public String getAafType() {
return aafType;
}
+
public void setAafType(String aafType) {
this.aafType = aafType;
}
- public String getAafInstance() {
- return aafInstance;
- }
+
public void setAafInstance(String aafInstance) {
this.aafInstance = aafInstance;
}
+
public String getAafAction() {
return aafAction;
}
+
public void setAafAction(String aafAction) {
this.aafAction = aafAction;
}
+
/*
* Get aafURL from SWM variable
* */
public String getAafURL() {
return aafURL;
}
+
public void setAafURL(String aafURL) {
this.aafURL = aafURL;
}
- public boolean getCadiEnabeld() {
+ public boolean getCadiEnabled() {
return cadiEnabled;
}
+
public void setCadiEnabled(boolean cadiEnabled) {
this.cadiEnabled = cadiEnabled;
}
/**
- * Builds the permissions string to be verified
+ * Builds the permissions string to be verified.
*
* @param aafInstance The aaf instance
* @return The permissions
try {
String type = getAafType();
String action = getAafAction();
- if (aafInstance == null || aafInstance.equals("")) {
+ if ("".equals(aafInstance)) {
aafInstance = getAafInstance();
}
return type + "|" + aafInstance + "|" + action;
} catch (Exception e) {
- eelfLogger.error("NODE0543 NodeConfigManager.getPermission: ", e.getMessage());
+ eelfLogger.error("NODE0543 NodeConfigManager.getPermission: ", e);
}
return null;
}