Skip to content
This repository has been archived by the owner on Oct 12, 2021. It is now read-only.

Commit

Permalink
Fix codenarc issues
Browse files Browse the repository at this point in the history
  • Loading branch information
johndevs committed Jan 13, 2019
1 parent 971a7ca commit abfaf9b
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 40 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -230,7 +230,7 @@ pluginBundle {
*
**********************************************************************************************************************/
wrapper {
gradleVersion = '4.10.2'
gradleVersion = '5.0'
distributionUrl = distributionUrl.replace('bin', 'all') // Download sources
}

Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.0-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion gradlew
Expand Up @@ -28,7 +28,7 @@ APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
DEFAULT_JVM_OPTS='"-Xmx64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
Expand Down
2 changes: 1 addition & 1 deletion gradlew.bat
Expand Up @@ -14,7 +14,7 @@ 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=
set DEFAULT_JVM_OPTS="-Xmx64m"

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
Expand Down
3 changes: 2 additions & 1 deletion src/main/groovy/com/devsoap/fn/tasks/FnDeployTask.groovy
Expand Up @@ -109,7 +109,8 @@ class FnDeployTask extends Exec {
if (isLocal()) {

// Configure completer base url for Flow
String baseUrl = "http://${DockerUtil.resolveContainerAddress(project, 'flowserver')}:${FnStartFlowServerTask.FN_FLOW_SERVER_PORT}"
String address = DockerUtil.resolveContainerAddress(project, 'flowserver')
String baseUrl = "http://${address}:${FnStartFlowServerTask.FN_FLOW_SERVER_PORT}"
logger.info("Setting COMPLETER_BASE_URL=$baseUrl")
project.exec {
workingDir(dockerImageDir)
Expand Down
68 changes: 49 additions & 19 deletions src/main/groovy/com/devsoap/fn/tasks/FnStartFlowServerTask.groovy
@@ -1,3 +1,18 @@
/*
* Copyright 2018-2019 Devsoap Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.devsoap.fn.tasks

import com.devsoap.fn.util.DockerUtil
Expand All @@ -9,6 +24,12 @@ import org.gradle.api.tasks.TaskAction

import java.util.logging.Level

/**
* Starts the FN Flow servers
*
* @author John Ahlroos
* @since 1.0
*/
@Log
class FnStartFlowServerTask extends DefaultTask {

Expand All @@ -18,6 +39,15 @@ class FnStartFlowServerTask extends DefaultTask {
static final int FN_FLOW_SERVER_PORT = 8081
static final int FN_FLOW_UI_PORT = 3002

private static final String FLOWSERVER = 'flowserver'
private static final String ENV = '-e'
private static final String DOCKER = 'docker'
private static final String RUN = 'run'
private static final String DEAMON = '-d'
private static final String REMOVE_OLD = '--rm'
private static final String FLOW_UI = 'flowui'
private static final String PORT = '-p'
private static final String NAME_PARAMETER = '--name'

FnStartFlowServerTask() {
dependsOn FnStartServerTask.NAME
Expand All @@ -27,44 +57,44 @@ class FnStartFlowServerTask extends DefaultTask {

@TaskAction
void execute() {
String fnServerAddress = DockerUtil.resolveContainerAddress(project,'fnserver')
if(!fnServerAddress) {
String fnServerAddress = DockerUtil.resolveContainerAddress(project, 'fnserver')
if (!fnServerAddress) {
throw new GradleException('FN Server is not running, aborting starting FN Flow server')
}

println "FN server is listening on http://localhost:$FN_SERVER_PORT"
log.info "FN server listening on internal $fnServerAddress:$FN_SERVER_PORT"

if(!DockerUtil.isContainerRunning(project, 'flowserver')) {
if (!DockerUtil.isContainerRunning(project, FLOWSERVER)) {
startFlowServer(fnServerAddress)
}

String fnFlowServerAddress = DockerUtil.resolveContainerAddress(project, 'flowserver')
if(!fnFlowServerAddress) {
String fnFlowServerAddress = DockerUtil.resolveContainerAddress(project, FLOWSERVER)
if (!fnFlowServerAddress) {
throw new GradleException('FN Flow server failed to start, aborting')
}

println "FN Flow server is listening on http://localhost:$FN_FLOW_SERVER_PORT"
log.info "FN Flow server listening on internal $fnFlowServerAddress:$FN_FLOW_SERVER_PORT"

if(!DockerUtil.isContainerRunning(project, 'flowui')) {
if (!DockerUtil.isContainerRunning(project, FLOW_UI)) {
startFlowServerUI(fnServerAddress, fnFlowServerAddress)
}

String fnFlowUIServerAddress = DockerUtil.resolveContainerAddress(project, 'flowui')
String fnFlowUIServerAddress = DockerUtil.resolveContainerAddress(project, FLOW_UI)

println "FN Flow UI server is listening on http://localhost:$FN_FLOW_UI_PORT"
log.info "FN Flow UI server listening on internal $fnFlowUIServerAddress:$FN_FLOW_UI_PORT"
}

private void startFlowServer(String fnServerAddress) {
project.exec {
commandLine 'docker'
args 'run', '--rm', '-d',
'-p', "${FnStartFlowServerTask.FN_FLOW_SERVER_PORT}:8081",
'-e', "API_URL=http://$fnServerAddress:${FnStartFlowServerTask.FN_SERVER_PORT}/invoke",
'-e', "no_proxy=${fnServerAddress}",
'--name', 'flowserver',
commandLine DOCKER
args RUN, REMOVE_OLD, DEAMON,
PORT, "${FnStartFlowServerTask.FN_FLOW_SERVER_PORT}:8081",
ENV, "API_URL=http://$fnServerAddress:${FnStartFlowServerTask.FN_SERVER_PORT}/invoke",
ENV, "no_proxy=${fnServerAddress}",
NAME_PARAMETER, FLOWSERVER,
'fnproject/flow:latest'
standardOutput = LogUtils.getLogOutputStream(Level.INFO)
errorOutput = LogUtils.getLogOutputStream(Level.SEVERE)
Expand All @@ -73,12 +103,12 @@ class FnStartFlowServerTask extends DefaultTask {

private void startFlowServerUI(String fnServerAddress, String fnFlowServerAddress) {
project.exec {
commandLine 'docker'
args 'run', '--rm', '-d',
'-p', "${FnStartFlowServerTask.FN_FLOW_UI_PORT}:3000",
'--name', 'flowui',
'-e', "API_URL=http://${fnServerAddress}:${FnStartFlowServerTask.FN_SERVER_PORT}",
'-e', "COMPLETER_BASE_URL=http://$fnFlowServerAddress:${FnStartFlowServerTask.FN_FLOW_SERVER_PORT}",
commandLine DOCKER
args RUN, REMOVE_OLD, DEAMON,
PORT, "${FnStartFlowServerTask.FN_FLOW_UI_PORT}:3000",
NAME_PARAMETER, FLOW_UI,
ENV, "API_URL=http://${fnServerAddress}:${FnStartFlowServerTask.FN_SERVER_PORT}",
ENV, "COMPLETER_BASE_URL=http://$fnFlowServerAddress:${FnStartFlowServerTask.FN_FLOW_SERVER_PORT}",
'fnproject/flow:ui'
standardOutput = LogUtils.getLogOutputStream(Level.INFO)
errorOutput = LogUtils.getLogOutputStream(Level.SEVERE)
Expand Down
Expand Up @@ -35,7 +35,7 @@ class FnStartServerTask extends Exec {
FnStartServerTask() {
dependsOn FnInstallCliTask.NAME
onlyIf {
!DockerUtil.isContainerRunning(project,'fnserver')
!DockerUtil.isContainerRunning(project, 'fnserver')
}
description = 'Starts the local FN Server'
group = 'fn'
Expand Down
16 changes: 10 additions & 6 deletions src/main/groovy/com/devsoap/fn/tasks/FnStopFlowServerTask.groovy
Expand Up @@ -31,6 +31,10 @@ import java.util.logging.Level
class FnStopFlowServerTask extends DefaultTask {

static String NAME = 'fnFlowStop'
public static final String FLOW_SERVER = 'flowserver'
public static final String DOCKER = 'docker'
public static final String STOP = 'stop'
public static final String FLOW_UI = 'flowui'

FnStopFlowServerTask() {
dependsOn FnStopServerTask.NAME
Expand All @@ -40,27 +44,27 @@ class FnStopFlowServerTask extends DefaultTask {

@TaskAction
void execute() {
if(DockerUtil.isContainerRunning(project, 'flowserver')) {
if (DockerUtil.isContainerRunning(project, FLOW_SERVER)) {
stopFlowServer()
}
if(DockerUtil.isContainerRunning(project, 'flowui')) {
if (DockerUtil.isContainerRunning(project, FLOW_UI)) {
stopFlowUIServer()
}
}

private void stopFlowServer() {
project.exec {
commandLine 'docker'
args 'stop', 'flowserver'
commandLine DOCKER
args STOP, FLOW_SERVER
standardOutput = LogUtils.getLogOutputStream(Level.INFO)
errorOutput = LogUtils.getLogOutputStream(Level.SEVERE)
}
}

private void stopFlowUIServer() {
project.exec {
commandLine 'docker'
args 'stop', 'flowui'
commandLine DOCKER
args STOP, FLOW_UI
standardOutput = LogUtils.getLogOutputStream(Level.INFO)
errorOutput = LogUtils.getLogOutputStream(Level.SEVERE)
}
Expand Down
Expand Up @@ -35,7 +35,7 @@ class FnStopServerTask extends Exec {
FnStopServerTask() {
dependsOn FnInstallCliTask.NAME
onlyIf {
DockerUtil.isContainerRunning(project,'fnserver')
DockerUtil.isContainerRunning(project, 'fnserver')
}
description = 'Stops the local FN Server'
group = 'fn'
Expand Down
33 changes: 25 additions & 8 deletions src/main/groovy/com/devsoap/fn/util/DockerUtil.groovy
@@ -1,25 +1,42 @@
/*
* Copyright 2018-2019 Devsoap Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.devsoap.fn.util

import org.gradle.api.Project

import java.nio.charset.StandardCharsets

/**
* Utilities for executing Docker commands
*
* @author John Ahlroos
* @since 1.0
*/
class DockerUtil {

static String resolveContainerAddress(Project project, String container) {
inspectContainerProperty(project, container, 'NetworkSettings.IPAddress')
inspectContainerProperty(project, container, 'NetworkSettings.IPAddress')
}

static boolean isContainerRunning(Project project, String container) {
try {
inspectContainerProperty(project, container, 'State.Running').toBoolean()
} catch(Exception e) {
false
}
inspectContainerProperty(project, container, 'State.Running').toBoolean()
}

private static String inspectContainerProperty(Project project, String container, String property) {
final ByteArrayOutputStream propertyStream = new ByteArrayOutputStream()
ByteArrayOutputStream propertyStream = new ByteArrayOutputStream()
propertyStream.withStream {
project.exec {
commandLine 'docker'
Expand All @@ -28,6 +45,6 @@ class DockerUtil {
}.rethrowFailure()
}
String out = new String(propertyStream.toByteArray(), StandardCharsets.UTF_8)
out.substring(1, out.length()-2) // Unquote
out[1..-2] // Unquote
}
}

0 comments on commit abfaf9b

Please sign in to comment.