Permalink
Browse files

update to Gradle 4.0

reactor logging classes
integrate AwsInventory and ManagedAwsInventory with status loggers
  • Loading branch information...
tiurikov committed Jun 30, 2017
1 parent a591f0a commit b20a8830e3a64239e9562748d1344a923cef8bfb
Binary file not shown.
@@ -1,6 +1,6 @@
#Mon Jan 09 22:42:27 CET 2017
#Fri Jun 30 21:37:27 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-bin.zip
View
@@ -33,11 +33,11 @@ DEFAULT_JVM_OPTS=""
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn ( ) {
warn () {
echo "$*"
}
die ( ) {
die () {
echo
echo "$*"
echo
@@ -155,7 +155,7 @@ if $cygwin ; then
fi
# Escape application args
save ( ) {
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
View
@@ -0,0 +1,84 @@
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
@@ -52,12 +52,11 @@ class ProgressLogger {
if (enableDynamics) {
statusLoggers.each {
statusPrinted++
println(Ansi.ansi().cursorToColumn(0).eraseLine(Ansi.Erase.FORWARD).bold().fg(DEFAULT).a(it.status()).reset())
println(Ansi.ansi().cursorToColumn(0).eraseLine(Ansi.Erase.FORWARD).bold().fg(DEFAULT).a(it.statusLine()).reset())
}
}
}
public static void debug(String message) {
if (DEBUG <= logLevel()) {
printLine(yellow(message))
@@ -1,15 +1,16 @@
package io.infrastructor.cli.logging.status
import static io.infrastructor.cli.logging.ProgressLogger.*
class ProgressStatusLogger {
private final char filledChar = '=';
private final char unfilledChar = '-'
private final int progressLineSize = 15;
private String status = "";
def total = 0;
def progress = 0;
def status = "";
def listener = {}
public synchronized int increase() {
@@ -18,12 +19,12 @@ class ProgressStatusLogger {
return progress
}
public def status(def status) {
public def setStatus(def status) {
this.status = status
listener()
}
public String status() {
public String statusLine() {
int filledElements = (int) ((progressLineSize / (double) total) * progress);
final StringBuilder stringBuilder = new StringBuilder("[");
@@ -40,5 +41,15 @@ class ProgressStatusLogger {
return stringBuilder.toString();
}
public static void withProgressStatus(def total, def status, Closure closure) {
def progress = new ProgressStatusLogger(total: total, status: status)
try {
addStatusLogger progress
closure(progress)
} finally {
removeStatusLogger progress
}
}
}
@@ -8,24 +8,20 @@ class TextStatusLogger {
def listener = {}
public String status() {
public String statusLine() {
text
}
public void status(def text) {
public void setStatus(def text) {
this.text = text
listener()
}
public def leftShift(def text) {
status(text)
}
public static void withTextStatus(Closure closure) {
public static def withTextStatus(Closure closure) {
def status = new TextStatusLogger()
try {
addStatusLogger status
closure(status)
return closure(status.&setStatus)
} finally {
removeStatusLogger status
}
@@ -1,7 +1,8 @@
package io.infrastructor.core.inventory
import groovy.transform.ToString
import io.infrastructor.core.processing.SetupExecutionContext
import io.infrastructor.core.processing.ExecutionContext
import io.infrastructor.core.processing.TaskBuilder
import static io.infrastructor.core.validation.ValidationHelper.validate
@@ -15,8 +16,11 @@ public class Inventory {
}
def setup(Closure closure) {
SetupExecutionContext context = new SetupExecutionContext(nodes, closure)
context.execute()
def cloned = closure.clone()
def ctx = new ExecutionContext(parent: cloned.owner)
ctx.handlers << ['nodes': new TaskBuilder(nodes)]
cloned.delegate = ctx
cloned()
this
}
}
@@ -40,7 +40,7 @@ public class Node {
def execute(Map map) {
debug "execute: $map"
debug "ssh execute: $map"
lastResult = new CommandBuilder(map).execute(shell.get())
@@ -5,7 +5,7 @@ import io.infrastructor.core.inventory.Node
import static io.infrastructor.cli.logging.ProgressLogger.*
import static io.infrastructor.core.utils.AmazonEC2Utils.amazonEC2
import io.infrastructor.cli.logging.status.TextStatusLogger
import static io.infrastructor.cli.logging.status.TextStatusLogger.withTextStatus
public class AwsInventory {
@@ -16,30 +16,26 @@ public class AwsInventory {
def usePublicIp = false
public Inventory build(def awsAccessKey, def awsSecretKey, def awsRegion) {
withTextStatus { statusLine ->
statusLine "> initializing aws inventory"
def statusLine = addStatusLogger(new TextStatusLogger())
statusLine.status("> initializing aws inventory")
def amazonEC2 = amazonEC2(awsAccessKey, awsSecretKey, awsRegion)
def amazonEC2 = amazonEC2(awsAccessKey, awsSecretKey, awsRegion)
debug 'AwsInventory :: connecting to AWS to retrieve a list of EC2 instances'
def awsNodes = AwsNodesBuilder.fromEC2(amazonEC2).filterByTags(tags).usePublicHost(usePublicIp)
debug 'AwsInventory :: connecting to AWS to retrieve a list of EC2 instances'
def awsNodes = AwsNodesBuilder.fromEC2(amazonEC2).filterByTags(tags).usePublicHost(usePublicIp)
debug 'AwsInventory :: updating username, keyfile and port information for all inventory nodes'
awsNodes.nodes.each {
it.username = owner.username
it.keyfile = owner.keyfile
it.port = owner.port
}
def inventory = new Inventory(nodes: awsNodes.nodes)
debug "AwsInventory :: inventory is ready [${inventory.nodes.size()} node]: "
inventory.nodes.each { debug( "Node: ${defColor(it.name)}: ${yellow(it as String)}")}
debug 'AwsInventory :: updating username, keyfile and port information for all inventory nodes'
awsNodes.nodes.each {
it.username = owner.username
it.keyfile = owner.keyfile
it.port = owner.port
}
removeStatusLogger(statusLine)
inventory
debug "AwsInventory :: inventory is ready [${awsNodes.nodes.size()} node]: "
awsNodes.nodes.each { debug( "Node: ${defColor(it.name)}: ${yellow(it as String)}")}
return new Inventory(nodes: awsNodes.nodes)
}
}
public static Inventory awsInventory(def awsAccessKey, def awsSecretKey, def awsRegion, Closure definition) {
@@ -6,7 +6,6 @@ import io.infrastructor.core.utils.AmazonRoute53Utils
import static io.infrastructor.cli.logging.ProgressLogger.*
import static io.infrastructor.cli.logging.status.TextStatusLogger.withTextStatus
import io.infrastructor.cli.logging.status.TextStatusLogger
public class ManagedAwsInventory {
@@ -26,13 +25,13 @@ public class ManagedAwsInventory {
}
def ec2(Map params, Closure setup) {
withTextStatus { status ->
status << "> initializing ec2 managed set"
withTextStatus { statusLine ->
statusLine '> initializing ec2 managed set'
def ec2 = new EC2(params)
ec2.with(setup)
ec2.initialize(amazonEC2)
ec2s << ec2
status << "> initializing ec2 managed set done"
statusLine '> initializing ec2 managed set done'
}
}
@@ -58,20 +57,20 @@ public class ManagedAwsInventory {
}
def setup(Closure definition = {}) {
withTextStatus { status ->
status << "> creating aws instances"
withTextStatus { statusLine ->
statusLine '> stage: creating aws instances'
ec2s*.createInstances(amazonEC2)
status << "> updating aws instances"
statusLine '> stage: updating aws instances'
ec2s*.updateInstances(amazonEC2)
status << "> setting up aws instances"
statusLine '> stage: provisioning aws instances'
new Inventory(nodes: getNodes()).setup(definition)
status << "> removing aws instances"
statusLine '> stage: removing aws instances'
ec2s*.removeInstances(amazonEC2)
status << "> updating route53 records"
statusLine '> stage: updating route53 records'
route53s*.apply(amazonEC2, amazonRoute53)
}
}
@@ -82,7 +81,7 @@ public class ManagedAwsInventory {
def dry() {
info "DRY: analyzing changes..."
printf ('%20s %28s %22s %s\n', [defColor('STATE'), defColor('INSTANCE ID'), defColor('PRIVATE IP'), defColor('NAME')])
info sprintf('%20s %28s %22s %s', [defColor('STATE'), defColor('INSTANCE ID'), defColor('PRIVATE IP'), defColor('NAME')])
getNodes().each {
def coloredState
switch (it.state) {
@@ -99,7 +98,7 @@ public class ManagedAwsInventory {
coloredState = blue('UNMODIFIED')
break
}
printf ('%20s %28s %22s %s\n', [coloredState, cyan(it.id ?: ''), cyan(it.privateIp ?: ''), defColor(it.name)])
info sprintf('%20s %28s %22s %s', [coloredState, cyan(it.id ?: ''), cyan(it.privateIp ?: ''), defColor(it.name)])
}
}
}

This file was deleted.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit b20a883

Please sign in to comment.