Skip to content

Commit

Permalink
Merge pull request #262 from AdaptiveScale/release-2.6.0
Browse files Browse the repository at this point in the history
Release 2.6.0
  • Loading branch information
nbesimi authored Dec 4, 2024
2 parents 7d1c657 + 811b571 commit 5b6ca0c
Show file tree
Hide file tree
Showing 23 changed files with 1,210 additions and 862 deletions.
880 changes: 63 additions & 817 deletions README.md

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions binary/src/main/resources/unix_template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,18 @@ esac

CLASSPATH="\$APP_HOME/lib/*"

DRIVERS_PATH="\${ROSETTA_DRIVERS}"

if [ x"\${ROSETTA_DRIVERS}" = "x" ]; then
DRIVERS_PATH="\${APP_HOME}/drivers/"
mkdir -p \$DRIVERS_PATH
CLASSPATH="\${CLASSPATH}:\${DRIVERS_PATH}*"
else
CLASSPATH="\${CLASSPATH}:\${ROSETTA_DRIVERS}"
mkdir -p \${DRIVERS_PATH}
fi

# Add all .jar files from DRIVERS_PATH and its subdirectories to CLASSPATH
for jar in \$(find "\${DRIVERS_PATH}" -name "*.jar"); do
CLASSPATH="\${CLASSPATH}:\${jar}"
done

JAVA_HOME="\$APP_HOME"
JAVACMD="\$JAVA_HOME/bin/java"

Expand Down
20 changes: 12 additions & 8 deletions binary/src/main/resources/windows_template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,17 @@ set CMD_LINE_ARGS=%*
:execute
@rem Setup the command line

set CLASSPATH=%JAVA_HOME:"=%/lib/*
set CLASSPATH=%APP_HOME:"=%/lib/*

if x%ROSETTA_DRIVERS% == x (
if not exist %APP_HOME%/drivers mkdir "%APP_HOME%/drivers/"
set CLASSPATH=%CLASSPATH%;%APP_HOME%/drivers/*
) else (
set CLASSPATH=%CLASSPATH%;%ROSETTA_DRIVERS%
set DRIVERS_PATH="%ROSETTA_DRIVERS%"

if "x%ROSETTA_DRIVERS%" == "x" (
set DRIVERS_PATH=%APP_HOME%/drivers/
if not exist %DRIVERS_PATH% mkdir "%DRIVERS_PATH%"
)

for /R "%DRIVERS_PATH%" %%f in (*.jar) do (
set CLASSPATH=%CLASSPATH%;%%f
)

<% if ( System.properties['BADASS_CDS_ARCHIVE_FILE_WINDOWS'] ) { %>
Expand All @@ -74,10 +78,10 @@ if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable ${exitEnvironmentVar} if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%${exitEnvironmentVar}%" exit 1
if not "" == "%${exitEnvironmentVar}%" exit 1
exit /b 1

:mainEnd
if "%OS%"=="Windows_NT" endlocal

:omega
:omega
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repositories {

allprojects {
group = 'com.adaptivescale'
version = '2.5.5'
version = '2.6.0'
sourceCompatibility = 11
targetCompatibility = 11
}
Expand Down
4 changes: 2 additions & 2 deletions cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ dependencies {
implementation project(':queryhelper')

implementation group: 'info.picocli', name: 'picocli', version: '4.6.3'
implementation group: 'org.slf4j', name: 'slf4j-simple', version: '2.0.5'
implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.7'
implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.5.6'
implementation group: 'org.slf4j', name: 'slf4j-api', version: '2.0.9'
implementation group: 'commons-io', name: 'commons-io', version: '2.11.0'
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.13.3'
implementation group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: '2.13.3' //debug only
Expand Down
121 changes: 106 additions & 15 deletions cli/src/main/java/com/adaptivescale/rosetta/cli/Cli.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.adaptivescale.rosetta.cli;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import com.adaptivescale.rosetta.cli.helpers.DriverHelper;
import com.adaptivescale.rosetta.cli.model.Config;
import com.adaptivescale.rosetta.cli.outputs.DbtSqlModelOutput;
Expand All @@ -21,49 +23,61 @@
import com.adaptivescale.rosetta.ddl.change.ChangeHandler;
import com.adaptivescale.rosetta.ddl.change.model.Change;
import com.adaptivescale.rosetta.ddl.utils.TemplateEngine;
import com.adaptivescale.rosetta.test.assertion.*;
import com.adaptivescale.rosetta.test.assertion.AssertionSqlGenerator;
import com.adaptivescale.rosetta.test.assertion.generator.AssertionSqlGeneratorFactory;
import com.adaptivescale.rosetta.test.assertion.DefaultAssertTestEngine;
import com.adaptivescale.rosetta.test.assertion.DefaultSqlExecution;
import com.adaptivescale.rosetta.test.assertion.generator.AssertionSqlGeneratorFactory;
import com.adaptivescale.rosetta.diff.DiffFactory;
import com.adaptivescale.rosetta.diff.Diff;
import com.adaptivescale.rosetta.translator.Translator;
import com.adaptivescale.rosetta.translator.TranslatorFactory;
import com.adataptivescale.rosetta.source.core.SourceGeneratorFactory;

import com.adataptivescale.rosetta.source.core.interfaces.Generator;
import com.adataptivescale.rosetta.source.dbt.DbtModelGenerator;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.slf4j.LoggerFactory;
import picocli.CommandLine;
import queryhelper.pojo.GenericResponse;
import queryhelper.service.AIService;

import java.io.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.AbstractMap;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.Callable;

import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static com.adaptivescale.rosetta.cli.Constants.*;
import static com.adaptivescale.rosetta.cli.Constants.CONFIG_NAME;
import static com.adaptivescale.rosetta.cli.Constants.TEMPLATE_CONFIG_NAME;

@Slf4j
@CommandLine.Command(name = "cli",
mixinStandardHelpOptions = true,
version = "2.5.5",
version = "2.6.0",
description = "Declarative Database Management - DDL Transpiler"
)
class Cli implements Callable<Void> {
private static final Logger log = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);

public static final String DEFAULT_MODEL_YAML = "model.yaml";
public static final String DEFAULT_OUTPUT_DIRECTORY = "data";
Expand All @@ -78,6 +92,15 @@ class Cli implements Callable<Void> {
description = "YAML config file. If none is supplied it will use main.conf in the current directory if it exists.")
private Config config;

@CommandLine.Option(names = {"-v", "--verbose"}, scope = CommandLine.ScopeType.INHERIT, description = "Enable Verbose output")
public void setVerbose(boolean verbose) {
if (verbose) {
log.setLevel(Level.DEBUG);
} else {
log.setLevel(Level.INFO);
}
}

@Override
public Void call() {
throw new CommandLine.ParameterException(spec.commandLine(), "Missing required subcommand");
Expand Down Expand Up @@ -282,9 +305,15 @@ private void test(
}
}

@CommandLine.Command(name = "init", description = "Creates a sample config (main.conf) and model directory.", mixinStandardHelpOptions = true)
private void init(@CommandLine.Parameters(index = "0", description = "Project name.", defaultValue = "")
String projectName) throws IOException {
@CommandLine.Command(
name = "init",
description = "Creates a sample config (main.conf) and model directory.",
mixinStandardHelpOptions = true
)
private void init(
@CommandLine.Parameters(index = "0", description = "Project name.", defaultValue = "") String projectName,
@CommandLine.Option(names = "--skip-db-selection", description = "Skip database selection and driver download process.") boolean skipDBSelection
) throws IOException {
Path fileName = Paths.get(projectName, CONFIG_NAME);
InputStream resourceAsStream = getClass().getResourceAsStream("/" + TEMPLATE_CONFIG_NAME);
Path projectDirectory = Path.of(projectName);
Expand All @@ -300,6 +329,58 @@ private void init(@CommandLine.Parameters(index = "0", description = "Project na
if (!projectName.isEmpty()) {
log.info("In order to start using the newly created project please change your working directory.");
}

if (skipDBSelection) {
log.info("Skipping database selection and driver download process.");
return;
}

Path driversPath = Path.of(DEFAULT_DRIVERS_YAML);

DriverHelper.printDrivers(driversPath);
System.out.println("Please select the source database from the list above by typing its number (or press Enter to skip):");
String sourceDB = new BufferedReader(new InputStreamReader(System.in)).readLine().trim();
if (sourceDB.isEmpty()) {
sourceDB = "skip";
}
handleDriverDownload(sourceDB, driversPath, "source");

DriverHelper.printDrivers(driversPath);
System.out.println("Please select the source database from the list above by typing its number (or press Enter to skip):");
String targetDB = new BufferedReader(new InputStreamReader(System.in)).readLine().trim();
if (targetDB.isEmpty()) {
targetDB = "skip";
}
handleDriverDownload(targetDB, driversPath, "target");
}

private void handleDriverDownload(String dbChoice, Path driversPath, String dbType) {
if ("skip".equalsIgnoreCase(dbChoice)) {
log.info("Skipped downloading the {} DB driver.", dbType);
return;
}

Integer driverId = null;

try {
driverId = Integer.parseInt(dbChoice);
} catch (NumberFormatException e) {
System.out.println("Invalid choice. Please select a valid option.");
return;
}

List<DriverInfo> drivers = DriverHelper.getDrivers(driversPath);
if (drivers.isEmpty()) {
System.out.println("No drivers found in the specified YAML file.");
return;
}

if (driverId < 1 || driverId > drivers.size()) {
System.out.println("Invalid choice. Please select a valid option.");
return;
}

DriverHelper.getDriver(driversPath, driverId);
}

@CommandLine.Command(name = "dbt", description = "Extract dbt models chosen from connection config.", mixinStandardHelpOptions = true)
Expand Down Expand Up @@ -430,16 +511,26 @@ private void diff(@CommandLine.Option(names = {"-s", "--source"}) String sourceN
}

@CommandLine.Command(name = "drivers", description = "Show available drivers for download", mixinStandardHelpOptions = true)
private void drivers(@CommandLine.Option(names = {"--list"}, description = "Used to list all available drivers") boolean isList,
@CommandLine.Option(names = {"-dl", "--download"}, description = "Used to download selected driver by index") boolean isDownload,
@CommandLine.Option(names = {"-f", "--file"}, defaultValue = DEFAULT_DRIVERS_YAML) String file,
private void drivers(@CommandLine.Option(names = {"--list"}, description = "Used to list all available drivers.") boolean isList,
@CommandLine.Option(names = {"--show"}, description = "Used to show downloaded drivers.") boolean isShow,
@CommandLine.Option(names = {"-dl", "--download"}, description = "Used to download selected driver by index.") boolean isDownload,
@CommandLine.Option(names = {"-f", "--file"}, description = "Used to change the drivers yaml file.", defaultValue = DEFAULT_DRIVERS_YAML) String file,
@CommandLine.Parameters(index = "0", arity = "0..1") Integer driverId) {
Path driversPath = Path.of(file);

if (isList) {
DriverHelper.printDrivers(driversPath);

System.out.println("To download a driver use: rosetta drivers {index} --download");
System.out.println("To set a custom drivers path use ROSETTA_DRIVERS environment variable.");
return;
}

if (isShow) {
DriverHelper.printDownloadedDrivers();

System.out.println("To download a driver use: rosetta drivers {index} --download");
System.out.println("To set a custom drivers path use ROSETTA_DRIVERS environment variable.");
return;
}

Expand Down
Loading

0 comments on commit 5b6ca0c

Please sign in to comment.