public void refresh() { this.hostName = AppUtils.getHostName(); setIpAddress(AppUtils.getIpAddress()); this.osUser = System.getProperty("user.name"); this.osName = System.getProperty("os.name"); this.osArch = System.getProperty("os.arch"); this.osVersion = System.getProperty("os.version"); this.availableProcessors = Runtime.getRuntime().availableProcessors(); this.freeMemoryBytes = Runtime.getRuntime().freeMemory(); this.totalMemoryBytes = Runtime.getRuntime().totalMemory(); this.maxMemoryBytes = Runtime.getRuntime().maxMemory(); this.javaVersion = System.getProperty("java.version"); this.javaVendor = System.getProperty("java.vendor"); this.symmetricVersion = Version.version(); this.timezoneOffset = AppUtils.getTimezoneOffset(); Calendar cal = Calendar.getInstance(); cal.set(Calendar.MILLISECOND, 0); this.heartbeatTime = cal.getTime(); }
private void sleepBeforeRegistrationRetry() { long sleepTimeInMs = DateUtils.MILLIS_PER_SECOND * randomTimeSlot.getRandomValueSeededByExternalId(); log.warn("Could not register. Sleeping for {} ms before attempting again.", sleepTimeInMs); AppUtils.sleep(sleepTimeInMs); }
public boolean inTimeWindow(String timezoneOffset) { return inTimeWindow(AppUtils.getLocalDateForOffset(timezoneOffset)); }
protected String addSecurityToken(String base, String connector, String nodeId, String securityToken) { StringBuilder sb = new StringBuilder(addNodeId(base, nodeId, "?")); sb.append(connector); sb.append(WebConstants.SECURITY_TOKEN); sb.append("="); sb.append(securityToken); append(sb, WebConstants.HOST_NAME, AppUtils.getHostName()); append(sb, WebConstants.IP_ADDRESS, AppUtils.getIpAddress()); return sb.toString(); }
serverId = AppUtils.getHostName(); } catch (Exception ex) { serverId = "unknown";
/** * If {@link NodeGroupChannelWindow}s are defined for this channel, then * check to see if the time (according to the offset passed in) is within on * of the configured windows. */ public boolean inTimeWindow(List<NodeGroupChannelWindow> windows, String targetNodeId) { if (windows != null && windows.size() > 0) { for (NodeGroupChannelWindow window : windows) { String timezoneOffset = null; List<NodeHost> hosts = nodeService.findNodeHosts(targetNodeId); if (hosts.size() > 0) { timezoneOffset = hosts.get(0).getTimezoneOffset(); } else { timezoneOffset = AppUtils.getTimezoneOffset(); } if (window.inTimeWindow(timezoneOffset)) { return true; } } return false; } else { return true; } }
unzipDir.mkdirs(); AppUtils.unzip(is, unzipDir);
protected String substituteVariables(String paramKey) { String value = getString(paramKey); if (!StringUtils.isBlank(value)) { if (value.contains("hostName")) { value = FormatUtils.replace("hostName", AppUtils.getHostName(), value); } if (value.contains("ipAddress")) { value = FormatUtils.replace("ipAddress", AppUtils.getIpAddress(), value); } if (value.contains("engineName")) { value = FormatUtils.replace("engineName", getEngineName(), value); } } return value; }
public X509Certificate generateV1Certificate(String host, KeyPair pair) throws Exception { host = host == null ? AppUtils.getHostName() : host; String certString = String.format( "CN=%s, OU=SymmetricDS, O=JumpMind, L=Unknown, ST=Unknown, C=Unknown", host); log.info("Installing a default SSL certificate: {}", certString); X509V1CertificateGenerator certGen = new X509V1CertificateGenerator(); certGen.setSerialNumber(BigInteger.valueOf(System.currentTimeMillis())); certGen.setIssuerDN(new X500Principal(certString)); certGen.setNotBefore(new Date(System.currentTimeMillis() - 86400000)); certGen.setNotAfter(new Date(System.currentTimeMillis() + 788400000000l)); certGen.setSubjectDN(new X500Principal(certString)); certGen.setPublicKey(pair.getPublic()); certGen.setSignatureAlgorithm("SHA256WithRSAEncryption"); return certGen.generate(pair.getPrivate(), "BC"); }
public boolean updateNode(Node node) { boolean updated = sqlTemplate.update( getSql("updateNodeSql"), new Object[] { node.getNodeGroupId(), node.getExternalId(), node.getDatabaseType(), node.getDatabaseVersion(), node.getSchemaVersion(), node.getSymmetricVersion(), node.getSyncUrl(), new Date(), node.isSyncEnabled() ? 1 : 0, AppUtils.getTimezoneOffset(), node.getBatchToSendCount(), node.getBatchInErrorCount(), node.getCreatedAtNodeId(), node.getDeploymentType(), node.getNodeId() }, new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.TIMESTAMP, Types.INTEGER, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR }) == 1; return updated; }
protected void copyToQueue(Data data) { long ts = System.currentTimeMillis(); while (!dataQueue.offer(data) && reading) { AppUtils.sleep(50); } context.incrementStat(System.currentTimeMillis() - ts, ChannelRouterContext.STAT_ENQUEUE_DATA_MS); }
public static String buildRegistrationUrl(String baseUrl, Node node) throws IOException { if (baseUrl == null) { baseUrl = ""; } StringBuilder builder = new StringBuilder(baseUrl); builder.append("/registration?"); append(builder, WebConstants.NODE_GROUP_ID, node.getNodeGroupId()); append(builder, WebConstants.EXTERNAL_ID, node.getExternalId()); append(builder, WebConstants.SYNC_URL, node.getSyncUrl()); append(builder, WebConstants.SCHEMA_VERSION, node.getSchemaVersion()); append(builder, WebConstants.DATABASE_TYPE, node.getDatabaseType()); append(builder, WebConstants.DATABASE_VERSION, node.getDatabaseVersion()); append(builder, WebConstants.SYMMETRIC_VERSION, node.getSymmetricVersion()); append(builder, WebConstants.HOST_NAME, AppUtils.getHostName()); append(builder, WebConstants.IP_ADDRESS, AppUtils.getIpAddress()); return builder.toString(); }
public void insertDataGap(DataGap gap) { try { sqlTemplate.update(getSql("insertDataGapSql"), new Object[] { DataGap.Status.GP.name(), AppUtils.getHostName(), gap.getStartId(), gap.getEndId() }, new int[] { Types.VARCHAR, Types.VARCHAR, Types.NUMERIC, Types.NUMERIC }); } catch (UniqueKeyException ex) { log.warn("A gap already existed for {} to {}. Updating instead.", gap.getStartId(), gap.getEndId()); updateDataGap(gap, DataGap.Status.GP); } }
public void save(Node node) { if (!updateNode(node)) { sqlTemplate.update( getSql("insertNodeSql"), new Object[] { node.getNodeGroupId(), node.getExternalId(), node.getDatabaseType(), node.getDatabaseVersion(), node.getSchemaVersion(), node.getSymmetricVersion(), node.getSyncUrl(), new Date(), node.isSyncEnabled() ? 1 : 0, AppUtils.getTimezoneOffset(), node.getBatchToSendCount(), node.getBatchInErrorCount(), node.getCreatedAtNodeId(), node.getDeploymentType(), node.getNodeId() }, new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.TIMESTAMP, Types.INTEGER, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR }); } }
public List<String> findOfflineNodeIds(long minutesOffline) { List<String> offlineNodeList = new ArrayList<String>(); Node myNode = findIdentity(); if (myNode != null) { long offlineNodeDetectionMillis = minutesOffline * 60 * 1000; List<Row> list = sqlTemplate.query(getSql("findNodeHeartbeatsSql"), new Object[] { myNode.getNodeId(), myNode.getNodeId()}, (int[])null); for (Row node : list) { String nodeId = node.getString("node_id"); Date time = node.getDateTime("heartbeat_time"); String offset = node.getString("timezone_offset"); // Take the timezone of the client node into account when // checking the hearbeat time. Date clientNodeCurrentTime = null; if (offset != null) { clientNodeCurrentTime = AppUtils .getLocalDateForOffset(offset); } else { clientNodeCurrentTime = new Date(); } long cutOffTimeMillis = clientNodeCurrentTime.getTime() - offlineNodeDetectionMillis; if (time == null || time.getTime() < cutOffTimeMillis) { offlineNodeList.add(nodeId); } } } return offlineNodeList; }
public void waitForComplete(long timeout) { long ts = System.currentTimeMillis(); while (!isComplete() && System.currentTimeMillis() - ts < timeout) { AppUtils.sleep(50); } if (!isComplete()) { throw new InterruptedException(String.format( "Timed out after %sms", timeout)); } } }
public void updateDataGap(DataGap gap, DataGap.Status status) { sqlTemplate.update( getSql("updateDataGapSql"), new Object[] { status.name(), AppUtils.getHostName(), gap.getStartId(), gap.getEndId() }, new int[] { Types.VARCHAR, Types.VARCHAR, symmetricDialect.getSqlTypeForIds(), symmetricDialect.getSqlTypeForIds() }); }
objectValue = String.format("%s %s", FormatUtils.TIMESTAMP_FORMATTER.format(randomDate()), AppUtils.getTimezoneOffset()); } else if (type == Types.DATE) { objectValue = DateUtils.truncate(randomDate(), Calendar.DATE);
public List<Node> findOfflineNodes(long minutesOffline) { List<Node> offlineNodeList = new ArrayList<Node>(); Node myNode = findIdentity(); if (myNode != null) { long offlineNodeDetectionMillis = minutesOffline * 60 * 1000; List<Row> list = sqlTemplate.query(getSql("findNodeHeartbeatsSql"), new Object[] { myNode.getNodeId(), myNode.getNodeId()}, (int[])null); for (Row node : list) { String nodeId = node.getString("node_id"); Date time = node.getDateTime("heartbeat_time"); String offset = node.getString("timezone_offset"); // Take the timezone of the client node into account when // checking the hearbeat time. Date clientNodeCurrentTime = null; if (offset != null) { clientNodeCurrentTime = AppUtils .getLocalDateForOffset(offset); } else { clientNodeCurrentTime = new Date(); } long cutOffTimeMillis = clientNodeCurrentTime.getTime() - offlineNodeDetectionMillis; if (time == null || time.getTime() < cutOffTimeMillis) { offlineNodeList.add(findNode(nodeId)); } } } return offlineNodeList; }
public void aquireInfiniteLock(String action) { if (isClusteringEnabled()) { int tries = 600; Date futureTime = DateUtils.add(new Date(), Calendar.YEAR, 100); while (tries > 0) { if (!lock(action, new Date(), futureTime, Lock.STOPPED)) { AppUtils.sleep(50); tries--; } else { tries = 0; } } } }