Skip to content

Commit

Permalink
read client dynamic props from webapp at /vcell_dynamic_properties.csv
Browse files Browse the repository at this point in the history
  • Loading branch information
jcschaff committed May 13, 2024
1 parent f59966b commit 496884e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import javax.swing.*;
import java.io.File;
import java.lang.management.ManagementFactory;
import java.net.URL;
import java.util.Arrays;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Callable;
Expand Down Expand Up @@ -118,7 +119,11 @@ public Integer call() throws Exception {
Injector injector = Guice.createInjector(new VCellClientModule(apihost, apiport, pathPrefixV0));
this.vcellClient = injector.getInstance(VCellClient.class);

Thread dynamicClientPropertiesThread = new Thread(() -> BeanUtils.updateDynamicClientProperties());
// see static-files-config ConfigMap for definitions of dynamic properties as deployed
String url_path = PropertyLoader.getProperty(PropertyLoader.DYNAMIC_PROPERTIES_URL_PATH, "/vcell_dynamic_properties.csv");
String webapp_base_url = "https://" + apihost + ":" + apiport;
URL vcell_dynamic_client_properties_url = new URL(webapp_base_url + url_path);
Thread dynamicClientPropertiesThread = new Thread(() -> BeanUtils.updateDynamicClientProperties(vcell_dynamic_client_properties_url));
dynamicClientPropertiesThread.setDaemon(false); // non-daemon thread to keep JVM running
dynamicClientPropertiesThread.start();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import org.vcell.util.document.VCellSoftwareVersion.VCellSite;

import java.io.IOException;
import java.net.URL;

/**
* Insert the type's description here.
* Creation date: (5/12/2004 4:31:18 PM)
Expand Down Expand Up @@ -373,7 +375,15 @@ public void connectAs(InteractiveContext requester, String user, DigestedPasswor
* Creation date: (5/12/2004 4:48:13 PM)
*/
private VCellConnection connectToServer(InteractiveContext requester,boolean bShowErrors) {
BeanUtils.updateDynamicClientProperties();
try {
// see static-files-config ConfigMap for definitions of dynamic properties as deployed
String url_path = PropertyLoader.getProperty(PropertyLoader.DYNAMIC_PROPERTIES_URL_PATH, "/vcell_dynamic_properties.csv");
String webapp_base_url = "https://" + getClientServerInfo().getApihost() + ":" + getClientServerInfo().getApiport();
URL vcell_dynamic_client_properties_url = new URL(webapp_base_url + url_path);
BeanUtils.updateDynamicClientProperties(vcell_dynamic_client_properties_url);
} catch (Exception e) {
lg.error(e.getMessage(), e);
}
VCellThreadChecker.checkRemoteInvocation();

VCellConnection newVCellConnection = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ public static void setConfigProvider(VCellConfigProvider configProvider) {
public static final String bioformatsJarFileName = record("vcell.bioformatsJarFileName",ValueType.GEN);
public static final String bioformatsJarDownloadURL = record("vcell.bioformatsJarDownloadURL",ValueType.URL);

// VCell special URLs
// VCell special URLs which are loaded from web server at path DYNAMIC_PROPERTIES_URL_PATH (default /vcell_dynamic_properties.csv)
public static final String DYNAMIC_PROPERTIES_URL_PATH = record("vcell.dynamicPropertiesUrlPath",ValueType.GEN);
public static final String COPASI_WEB_URL = record("vcell.COPASI_WEB_URL",ValueType.URL);
public static final String SMOLDYN_WEB_URL = record("vcell.SMOLDYN_WEB_URL",ValueType.URL);
public static final String BIONETGEN_WEB_URL = record("vcell.BIONETGEN_WEB_URL",ValueType.URL);
Expand Down Expand Up @@ -177,7 +178,7 @@ public static void setConfigProvider(VCellConfigProvider configProvider) {
public static final String BIOPAX_RSABIO65_URL = record("vcell.BIOPAX_RSABIO65_URL",ValueType.URL);
public static final String BIOPAX_RKEGGR01026_URL = record("vcell.BIOPAX_RKEGGR01026_URL",ValueType.URL);
public static final String COMSOL_URL = record("vcell.COMSOL_URL",ValueType.URL);

//
public static final String databaseThreadsProperty = record("vcell.databaseThreads",ValueType.GEN);
public static final String exportdataThreadsProperty = record("vcell.exportdataThreads",ValueType.GEN);
Expand Down
54 changes: 20 additions & 34 deletions vcell-util/src/main/java/org/vcell/util/BeanUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,6 @@

package org.vcell.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Serializable;
import java.math.BigDecimal;
import java.net.InetSocketAddress;
import java.net.URL;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.Executors;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.net.ssl.HttpsURLConnection;

import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVRecord;
import org.apache.logging.log4j.LogManager;
Expand All @@ -40,11 +19,24 @@
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelFuture;
import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory;
import org.jboss.netty.handler.codec.http.DefaultHttpRequest;
import org.jboss.netty.handler.codec.http.HttpHeaders;
import org.jboss.netty.handler.codec.http.HttpMethod;
import org.jboss.netty.handler.codec.http.HttpRequest;
import org.jboss.netty.handler.codec.http.HttpVersion;
import org.jboss.netty.handler.codec.http.*;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.net.ssl.HttpsURLConnection;
import java.io.*;
import java.math.BigDecimal;
import java.net.InetSocketAddress;
import java.net.URL;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.Executors;

/**
* Insert the type's description here.
Expand Down Expand Up @@ -82,24 +74,18 @@ public static synchronized VCellDynamicProps getDynamicClientProperties(){
return vcellDynamicProps;
}

public static synchronized void updateDynamicClientProperties(){
public static synchronized void updateDynamicClientProperties(URL vcell_dynamic_properties_url) {
Map<String, String> temp = new TreeMap<>();
HttpsURLConnection conn;
//"https://vcell.org/webstart/dynamicClientProperties.txt"

try {
//HttpURLConnection conn = new HttpURLConnection(new GetMethod(), new URL("http://dockerbuild:8080"));
//https://vcell.org/webstart/vcell_dynamic_properties.csv
// HttpURLConnection conn = (HttpURLConnection)(new URL("http://dockerbuild:8080")).openConnection();
conn = (HttpsURLConnection) (new URL("https://vcell.org/webstart/vcell_dynamic_properties.csv")).openConnection();
conn = (HttpsURLConnection) vcell_dynamic_properties_url.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(5000);
conn.setReadTimeout(5000);

try (BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()))) {
Iterable<CSVRecord> records = CSVFormat.DEFAULT
// .withHeader(HEADERS)
// .withFirstRecordAsHeader()
.withIgnoreSurroundingSpaces()
.withQuote('"')
.parse(br);
Expand Down

0 comments on commit 496884e

Please sign in to comment.