Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/user pass on cli #34

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
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
12 changes: 4 additions & 8 deletions src/main/java/com/openlattice/launchpad/Launchpad.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.ParseException;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
Expand All @@ -26,10 +24,6 @@
*/
@SuppressFBWarnings(value = "SECPTI", justification = "User input for file is considered trusted.")
public class Launchpad {
private static final ObjectMapper mapper = JacksonSerializationConfiguration.yamlMapper;

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


public static void main( String[] args ) throws ParseException, IOException {
CommandLine cl = LaunchpadCli.parseCommandLine( args );
Expand All @@ -39,12 +33,12 @@ public static void main( String[] args ) throws ParseException, IOException {
System.exit(0);
}

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

final String integrationFilePath = cl.getOptionValue( LaunchpadCli.FILE );
Preconditions.checkState( StringUtils.isNotBlank( integrationFilePath ) );
File integrationFile = new File( integrationFilePath );

ObjectMapper mapper = JacksonSerializationConfiguration.yamlMapper;

IntegrationConfiguration config = mapper.readValue(
integrationFile,
IntegrationConfiguration.class );
Expand All @@ -59,6 +53,8 @@ public static void main( String[] args ) throws ParseException, IOException {
System.exit( -1 );
}

config = LaunchpadCli.readUsernamesPasswordsAndUpdateConfiguration( config, cl );

IntegrationRunner.runIntegrations( config );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ public LaunchpadDatasource(
}

public DataLake asDataLake() {
String lakeDataFormat = "";
String lakeDriver = "";
String lakeDataFormat;
String lakeDriver;
switch ( driver ){
case S3_DRIVER:
lakeDriver = S3_DRIVER;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ public LaunchpadDestination(
}

public DataLake asDataLake() {
String lakeDataFormat = "";
String lakeDriver = "";
String lakeDataFormat;
String lakeDriver;
switch ( writeDriver ){
case S3_DRIVER:
lakeDriver = S3_DRIVER;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ public synchronized void close() {
otherStatements.forEach( this::safeTryClose );

final long elapsed = sw.elapsed( TimeUnit.MILLISECONDS );
if ( elapsed > this.longRunningQueryLimit ) {
if ( elapsed > longRunningQueryLimit ) {
logger.warn( "The following statement was involved in a long lived connection that took {} ms: {}",
elapsed,
statement.toString() );
statement );
}

sw.stop();
Expand Down
68 changes: 57 additions & 11 deletions src/main/kotlin/com/openlattice/launchpad/LaunchpadCli.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.openlattice.launchpad

import org.apache.commons.cli.CommandLine
import org.apache.commons.cli.DefaultParser
import org.apache.commons.cli.HelpFormatter
import org.apache.commons.cli.Options
import com.fasterxml.jackson.module.kotlin.readValue
import com.openlattice.launchpad.configuration.DataLake
import com.openlattice.launchpad.configuration.IntegrationConfiguration
import com.openlattice.launchpad.serialization.JacksonSerializationConfiguration
import org.apache.commons.cli.*
import java.util.*

/**
* @author Drew Bailey <[email protected]>
Expand All @@ -13,26 +15,70 @@ class LaunchpadCli {
companion object {
const val HELP = "help"
const val FILE = "file"
const val USERNAMES = "usernames"
const val PASSWORDS = "passwords"

private val options = Options()
private val clp = DefaultParser()
private val hf = HelpFormatter()

init {
options.addOption(HELP, "Print help message." );
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( Option.builder(FILE)
.hasArg()
.required()
.desc("File in which the final model will be saved. Also used as prefix for intermediate saves of the model." )
.build());
options.addOption( Option.builder(USERNAMES)
.hasArg()
.desc("Usernames for connection to the client database. Formatted as a json map {<dataLakeName>:<username>,...}")
.build());
options.addOption( Option.builder(PASSWORDS)
.hasArg()
.desc("Passwords for connection to the client database. Formatted as a json map {<dataLakeName>:<password>,...}")
.build());
}

@JvmStatic
fun parseCommandLine(args: Array<String> ) : CommandLine {
return clp.parse(options, args )
try {
return DefaultParser().parse(options, args )
} catch ( ex: MissingOptionException ) {
println("Integration file must be specified!")
System.exit(-1)
}
return CommandLine.Builder().build()
}

@JvmStatic
fun printHelp(): Unit {
hf.printHelp( "launchpad", options);
HelpFormatter().printHelp( "launchpad", options);
}

@JvmStatic
fun readUsernamesPasswordsAndUpdateConfiguration(config: IntegrationConfiguration, cl: CommandLine ): IntegrationConfiguration {
val mapper = JacksonSerializationConfiguration.jsonMapper
var lakeToUsername: Map<String, String> = mapOf()
if (cl.hasOption(USERNAMES) && cl.getOptionValue(USERNAMES).isNotBlank() ) {
lakeToUsername = mapper.readValue(cl.getOptionValue(USERNAMES))
}

var lakeToPassword: Map<String, String> = mapOf()
if (cl.hasOption(PASSWORDS) && cl.getOptionValue(PASSWORDS).isNotBlank() ) {
lakeToPassword = mapper.readValue(cl.getOptionValue(PASSWORDS))
}
val newLakes = config.datalakes.get().map {
val username = lakeToUsername.get( it.name )
val password = lakeToPassword.get( it.name )
DataLake.withUsernameAndPassword( it, username, password )
}
return IntegrationConfiguration(
config.name,
config.description,
config.awsConfig,
config.datasources,
config.destinations,
Optional.of(newLakes),
config.integrations
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ object Constants {
const val LEGACY_CSV_FORMAT = "com.openlattice.launchpad.csv"
const val CSV_FORMAT = "csv"
const val ORC_FORMAT = "orc"

const val FILESYSTEM_DRIVER = "filesystem"
const val S3_DRIVER = "s3"
const val UNKNOWN = "unknown"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,24 @@ data class DataLake(
) {
companion object {
private val logger = LoggerFactory.getLogger(DataLake::class.java)

@JvmStatic
fun withUsernameAndPassword( dataLake: DataLake, username: String?, password: String? ): DataLake {
return DataLake(
dataLake.name,
dataLake.url,
dataLake.driver,
dataLake.dataFormat,
username?:dataLake.username,
password?:dataLake.password,
dataLake.header,
dataLake.fetchSize,
dataLake.batchSize,
dataLake.writeMode,
dataLake.latticeLogger,
dataLake.properties
)
}
}

init {
Expand Down