Skip to content

Commit

Permalink
Merge pull request #34 from NASA-AMMOS/decouple-es
Browse files Browse the repository at this point in the history
Decouple Elasticsearch from CWS, make into external dependency
  • Loading branch information
ztaylor54 authored Mar 19, 2021
2 parents 1b467fc + df0ce69 commit f3ed5b4
Show file tree
Hide file tree
Showing 26 changed files with 387 additions and 631 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ creds.txt
cws-test/newCWSDir

.DS_Store
install/logging/logstash-6.4.2.zip
install/logging/logstash-7.9.0.zip
1 change: 0 additions & 1 deletion NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ This software includes third party software subject to the following copyrights:
- The AWS SDK for Java is Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
- The Camunda BPMN Platform is Copyright 2013-2020 Camunda Services GmbH.
- The Camunda Modeler is Copyright (c) Camunda Services GmbH.
- The Elasticsearch software is Copyright 2009-2018 Elasticsearch.
- The Logstash software is Copyright 2009-2018 Elasticsearch.
- The Bootstrap software has the following copyright holders:
- Copyright (c) 2011-2020 Twitter, Inc.
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ See the [wiki](https://github.com/NASA-AMMOS/common-workflow-service/wiki) for m
- A database for CWS to use. `cws` is a good default.
- A database user with full access to the above database.
- [ITerm2](https://iterm2.com/): Currently these build scripts include commands to open new terminal windows using ITerm2, so they are best run from that terminal.
- **Logstash**: You will need to place the logstash 6.4.2 zip in `install/logging/`. This is a temporary workaround while we clean up our installation process. You can find the zip download [here](https://www.elastic.co/downloads/past-releases/logstash-6-4-2).
- **Logstash 7.9+**: You will need to place the logstash 7.9.0 zip in `install/logging/`. This is a temporary workaround while we clean up our installation process. You can find the zip download [here](https://www.elastic.co/downloads/past-releases/logstash-7-9-0).
- **Elasticsearch 7.9+**: CWS requires an externally-configured elasticsearch cluster to be set up. You can use elasticsearch with or without authentication. Please note that CWS currently only supports basic HTTP authentication.
- Tomcat **keystore and truststore files** (needed for CWS web console to work properly):
- You will need to add your own Tomcat keystore file to the `install/` direcotory
- You will need to add your own truststor file to the `install/tomcat_lib/` directory
Expand Down
10 changes: 1 addition & 9 deletions create_server_dist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,10 @@ fi
print 'Copying Logstash zip into place...'
cp ${INSTALL_DIR}/logging/logstash-${LOGSTASH_VER}.zip ${CWS}/server

# -----------------
# ELASTICSEARCH
print 'Copying elasticsearch zip into place...'
cp ${INSTALL_DIR}/elasticsearch/elasticsearch-${ELASTICSEARCH_VER}.zip ${CWS}/server

# MOVE TEMPLATE CONFIG FILES INTO PLACE
print 'Copying configuration templates...'
CONFIG_TEMPLATES_DIR=${CWS}/config/templates
mkdir -p ${CONFIG_TEMPLATES_DIR}/{cws-engine,cws-ui,tomcat_bin,tomcat_lib,tomcat_conf,camunda_mods,engine-rest_mods,elasticsearch,logging}
mkdir -p ${CONFIG_TEMPLATES_DIR}/{cws-engine,cws-ui,tomcat_bin,tomcat_lib,tomcat_conf,camunda_mods,engine-rest_mods,logging}

cp ${INSTALL_DIR}/tomcat_lib/css-jaas.cfg ${CONFIG_TEMPLATES_DIR}/tomcat_lib
cp ${INSTALL_DIR}/tomcat_bin/setenv.sh ${CONFIG_TEMPLATES_DIR}/tomcat_bin
Expand All @@ -85,8 +80,6 @@ cp ${INSTALL_DIR}/cws-ui/*.ftl ${CONFIG_TEMPLATES
cp ${INSTALL_DIR}/cws-ui/sqs_dispatcher_thread_bean.xml ${CONFIG_TEMPLATES_DIR}/cws-ui
cp ${INSTALL_DIR}/camunda_mods/web.xml ${CONFIG_TEMPLATES_DIR}/camunda_mods
cp ${INSTALL_DIR}/engine-rest/web.xml ${CONFIG_TEMPLATES_DIR}/engine-rest_mods
cp ${INSTALL_DIR}/elasticsearch/elasticsearch.yml ${CONFIG_TEMPLATES_DIR}/elasticsearch
cp ${INSTALL_DIR}/elasticsearch/jvm.options ${CONFIG_TEMPLATES_DIR}/elasticsearch
cp ${INSTALL_DIR}/logging/cws-logstash.conf ${CONFIG_TEMPLATES_DIR}/logging
cp ${INSTALL_DIR}/refresh_cws_token.sh ${CONFIG_TEMPLATES_DIR}
cp ${INSTALL_DIR}/stop_cws.sh ${CONFIG_TEMPLATES_DIR}
Expand Down Expand Up @@ -211,7 +204,6 @@ cp ${INSTALL_DIR}/stop_cws.sh ${CWS}
cp ${INSTALL_DIR}/refresh_cws_token.sh ${CWS}
cp ${INSTALL_DIR}/deploy_proc_def.sh ${CWS}
cp ${INSTALL_DIR}/launch_ls.sh ${CWS}
cp ${INSTALL_DIR}/launch_es.sh ${CWS}

print 'Copying Modeller scripts and libraries...'
cp -R ${INSTALL_DIR}/modeler ${CWS}
Expand Down
41 changes: 31 additions & 10 deletions cws-core/src/main/java/jpl/cws/core/web/WebUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Base64;

import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
Expand Down Expand Up @@ -47,16 +48,29 @@ public static RestCallResult restCall(String urlString, String method, String po
return restCall(urlString, method, postData,
null, // cookie
null, // acceptType
null, // contentType
false // allowInsecureRequests
null // contentType
);
}

/**
* Performs an unauthenticated REST call
*/
public static RestCallResult restCall(String urlString, String method, String data, String cookie, String acceptType, String contentType) throws Exception {
return restCall(urlString, method, data, cookie, acceptType, contentType, true, null, null);
}

/**
* Performs an authenticated REST call
*/
public static RestCallResult restCall(String urlString, String method, String data, String cookie, String acceptType, String contentType, String username, String password) throws Exception {
return restCall(urlString, method, data, cookie, acceptType, contentType, false, username, password);
}

/**
* Performs a REST call
*
*/
public static RestCallResult restCall(String urlString, String method, String data, String cookie, String acceptType, String contentType, Boolean allowInsecureRequests) throws Exception {
public static RestCallResult restCall(String urlString, String method, String data, String cookie, String acceptType, String contentType, Boolean allowInsecureRequests, String username, String password) throws Exception {
log.trace("urlString = " + urlString);
HttpURLConnection connection = null;
try {
Expand All @@ -72,7 +86,14 @@ else if (rootAndQueryString.length > 2) {

URL url = new URL(urlString);
connection = (HttpURLConnection) url.openConnection();


// Add authentication to request
if (username != null) {
String userpass = username + ":" + password;
String basicAuth = "Basic " + new String(Base64.getEncoder().encode(userpass.getBytes()));
connection.setRequestProperty ("Authorization", basicAuth);
}

if (allowInsecureRequests) {

log.info("SSL 'insecure' mode activated.");
Expand Down Expand Up @@ -136,10 +157,10 @@ else if (rootAndQueryString.length > 2) {
out.close();
}
}

// Perform the connection
connection.connect();

int responseCode = -1;
try {
responseCode = connection.getResponseCode();
Expand All @@ -149,7 +170,7 @@ else if (rootAndQueryString.length > 2) {
}
if (responseCode == 200) {
log.trace("REST "+method+" for " + url + " was successful (HTTP 200).");

InputStream in = connection.getInputStream();
// FIXME: potential memory suck if response is large
String response = IOUtils.toString(in);
Expand All @@ -158,7 +179,7 @@ else if (rootAndQueryString.length > 2) {
}
else {
log.warn("REST " + method + " FAILED for " + url + ". Response code was " + responseCode);

return new RestCallResult(responseCode, null, connection.getResponseMessage());
}
}
Expand All @@ -179,8 +200,8 @@ else if (rootAndQueryString.length > 2) {
}
}
}


/**
*
*/
Expand Down
Loading

0 comments on commit f3ed5b4

Please sign in to comment.