Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions src/main/java/com/openlattice/launchpad/LaunchPad.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,33 @@
import com.fasterxml.jackson.datatype.guava.GuavaModule;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
import com.fasterxml.jackson.module.afterburner.AfterburnerModule;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.openlattice.launchpad.configuration.Integration;
import com.openlattice.launchpad.configuration.IntegrationConfiguration;
import com.openlattice.launchpad.configuration.IntegrationRunner;
import com.openlattice.launchpad.configuration.LaunchpadDatasource;
import com.openlattice.launchpad.configuration.LaunchpadDestination;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.ParseException;
import org.apache.commons.lang.StringUtils;
import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.SaveMode;
import org.apache.spark.sql.SparkSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;

/**
* Main class for running launchpad.
*/
@SuppressFBWarnings(value = "SECPTI", justification = "User input for file is considered trusted.")
public class LaunchPad {
public static final String CSV_DRIVER = "com.openlattice.launchpad.Csv";
private static final ObjectMapper mapper = createYamlMapper();
public static CommandLine cl;


private static final Logger logger = LoggerFactory.getLogger( LaunchPad.class );

public static void main( String[] args ) throws ParseException, IOException {
CommandLine cl = LaunchPadCli.parseCommandLine( args );
cl = LaunchPadCli.parseCommandLine( args );

Preconditions.checkArgument( cl.hasOption( LaunchPadCli.FILE ), "Integration file must be specified!" );

Expand Down
20 changes: 18 additions & 2 deletions src/main/java/com/openlattice/launchpad/LaunchPadCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@
* @author Matthew Tamayo-Rios <matthew@openlattice.com>
*/
public class LaunchPadCli {
public static final String HELP = "help";
public static final String FILE = "file";
public static final String HELP = "help";
public static final String FILE = "file";
public static final String CLIENT_USERNAME = "client-username";
public static final String CLIENT_PASSWORD = "client-password";
public static final String OL_USERNAME = "ol-username";
public static final String OL_PASSWORD = "ol-password";

private static Options options = new Options();
private static CommandLineParser clp = new DefaultParser();
Expand All @@ -23,6 +27,18 @@ public class LaunchPadCli {
options.addOption( FILE,
true,
"File in which the final model will be saved. Also used as prefix for intermediate saves of the model." );
options.addOption( CLIENT_USERNAME,
true,
"Username for connection to the client database" );
options.addOption( CLIENT_PASSWORD,
true,
"Password for connection to the client database" );
options.addOption( OL_USERNAME,
true,
"Username for connection to the openlattice database" );
options.addOption( OL_PASSWORD,
true,
"Password for connection to the openlattice database" );

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
import java.util.Objects;
import java.util.Optional;
import java.util.Properties;

import com.openlattice.launchpad.LaunchPad;
import com.openlattice.launchpad.LaunchPadCli;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.core.tools.picocli.CommandLine.MissingParameterException;

Expand Down Expand Up @@ -66,16 +69,23 @@ public LaunchpadDatasource(
this.name = name;
this.url = url;
this.driver = driver;
if ( !StringUtils.equals( CSV_DRIVER, driver ) ) {
if ( LaunchPad.cl.hasOption( LaunchPadCli.CLIENT_USERNAME )) {
this.user = LaunchPad.cl.getOptionValue( LaunchPadCli.CLIENT_USERNAME );
} else if ( !StringUtils.equals( CSV_DRIVER, driver ) && !LaunchPad.cl.hasOption( LaunchPadCli.CLIENT_USERNAME )) {
this.user = user.orElseThrow( () -> new MissingParameterException(
"A username must be specified for database connections." ) );
} else {
//User can be blank for CSV.
this.user = "";
}
//Depending on server configuration a password may not be required to establish a connection.
this.password = password.orElse( "" );
this.fetchSize = fetchSize.orElse( 20000 );

if ( LaunchPad.cl.hasOption( LaunchPadCli.CLIENT_PASSWORD )) {
this.password = LaunchPad.cl.getOptionValue( LaunchPadCli.CLIENT_PASSWORD );
} else {
//Depending on server configuration a password may not be required to establish a connection.
this.password = password.orElse( "" );
}
this.fetchSize = fetchSize.orElse( 20_000 );

properties = new Properties();
properties.setProperty( "user", this.user );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,19 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Preconditions;
import com.openlattice.launchpad.LaunchPad;
import com.openlattice.launchpad.LaunchPadCli;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import java.util.Objects;
import java.util.Optional;
import java.util.Properties;
import org.apache.commons.lang.StringUtils;
import org.apache.spark.sql.SaveMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Objects;
import java.util.Optional;
import java.util.Properties;

/**
* @author Matthew Tamayo-Rios <matthew@openlattice.com>
*/
Expand Down Expand Up @@ -81,6 +84,14 @@ public LaunchpadDestination(
this.properties.put(JDBC_URL, writeUrl);
this.properties.put(MAXIMUM_POOL_SIZE, "1");
this.properties.put(CONNECTION_TIMEOUT, "120000"); //2-minute connection timeout
if ( username.isEmpty() && LaunchPad.cl.hasOption( LaunchPadCli.OL_USERNAME ) ){
String user = LaunchPad.cl.getOptionValue( LaunchPadCli.OL_USERNAME );
this.properties.setProperty( "user", user );
this.properties.setProperty( "username",user );
}
if ( password.isEmpty() && LaunchPad.cl.hasOption( LaunchPadCli.OL_PASSWORD ) ){
this.properties.setProperty( PASSWORD, LaunchPad.cl.getOptionValue( LaunchPadCli.OL_PASSWORD ) );
}
username.ifPresent( u -> this.properties.setProperty( "user", u ) );
username.ifPresent( u -> this.properties.setProperty( "username", u ) );
password.ifPresent( p -> this.properties.setProperty( PASSWORD, p ) );
Expand Down