Skip to content

Commit

Permalink
Merging build #225
Browse files Browse the repository at this point in the history
  • Loading branch information
axiomatics-andreas authored Apr 29, 2024
2 parents 0c7c415 + 114b277 commit abc4d12
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 29 deletions.
74 changes: 63 additions & 11 deletions buildSrc/src/main/groovy/tasks/RunSpawnedAds.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ class RunSpawnedAds extends DefaultTask {
cmds << java
cmds << "-cp"
cmds << joinedClasspath

if (System.getProperty("javax.net.ssl.trustStore") != null) {
cmds << "-Djavax.net.ssl.trustStore=" + System.getProperty("javax.net.ssl.trustStore")
}
if (System.getProperty("javax.net.ssl.trustStorePassword") != null) {
cmds << "-Djavax.net.ssl.trustStorePassword=" + System.getProperty("javax.net.ssl.trustStorePassword")
}
if (System.getProperty("javax.net.ssl.trustStoreType") != null) {
cmds << "-Djavax.net.ssl.trustStoreType=" + System.getProperty("javax.net.ssl.trustStoreType")
}
cmds << "com.axiomatics.ads.App"
cmds << "server"

Expand Down Expand Up @@ -82,25 +92,26 @@ class RunSpawnedAds extends DefaultTask {

}
def result = adm.host + String.format(template,adm.alfa.namespace,adm.domainName)
logger.lifecycle("Location of domain.yaml is ${result}" )

return result
}

private String getAuthenticationYaml() {
boolean isBasic = adm.basicCredentials != null
if (isBasic) {
return getBasicAuthenticationYaml()
} else {
return getOidcAuthenticationYaml()
}

return getBasicAuthenticationYaml() +
getOidcAuthenticationYaml()


}

@Internal
String getDeploymentTemplate() { """
String getDeploymentTemplate() {
def url = getDomainUrl();
logger.lifecycle("Location of domain.yaml is ${url}" )
return """
license: ${adm.project.getProjectDir()}/${config.licenseFile}
domain: ${getDomainUrl()}
domain: ${url}
audit:
mode: verbose
Expand All @@ -122,7 +133,7 @@ server:
appenders:
- type: console
logging:
level: \${LOGLEVEL:-${logger.isInfoEnabled()?"DEBUG":"WARN"}}
level: WARN
loggers:
"org.apache.jcs": \${LOGLEVEL:-${logger.isInfoEnabled()?"WARN":"INFO"}}
"com.axiomatics": \${LOGLEVEL:-${logger.isInfoEnabled()?"DEBUG":"INFO"}}
Expand All @@ -136,19 +147,60 @@ logging:
String getBasicAuthenticationYaml() {
"""
httpClientConfiguration:
${getBasicCredentials()}
${getTlsConfig()}
"""
}

@Internal getBasicCredentials() {
boolean isBasic = adm.basicCredentials != null
if (isBasic) {

return """
domainUser: ${adm.basicCredentials.username}
domainPassword: ${adm.basicCredentials.password}
timeout: 30 seconds
"""
} else {return ""}

}
@Internal
String getOidcAuthenticationYaml() {
"""
boolean isBasic = adm.basicCredentials != null
if (isBasic) {
return ""
} else {
"""
authHttpClientConfiguration:
clientId: ${adm.oidcCredentials.client_id}
clientSecret: ${adm.oidcCredentials.client_secret}
tokenUri: ${adm.host}${adm.oidcCredentials.token_uri}
timeout: 30 seconds
${getTlsConfig()}
"""
}
}

private String getTlsConfig() {
String file = System.getProperty("javax.net.ssl.trustStore")
if (file == null) {
if (getDomainUrl().startsWith("https")) {
println "No explicit truststore to ADM set, using implicit from JAVA or OS. Specify with javax.net.ssl.keyStoreType system properties."
}
return "";
}

println (" Truststore for ADS to ADM set: " + file)
String password = System.getProperty("javax.net.ssl.trustStorePassword")
String type = System.getProperty("javax.net.ssl.trustStoreType", "JKS")
return """
tls:
trustStorePath: ${file}
trustStorePassword: ${password}
trustStoreType: ${type}
""";
}

}
68 changes: 50 additions & 18 deletions buildSrc/src/main/groovy/tasks/WaitAdsStartedTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.TaskAction

import java.util.concurrent.atomic.AtomicBoolean

class WaitAdsStartedTask extends DefaultTask {

@Internal
String START_CONDITION = "Application command 'server' was executed successfully."
String START_CONDITION_REGEXP = "^.*Domain with id.*was loaded\$" //TODO, ADS2.0

@Input
AdmExtension adm
Expand All @@ -19,29 +21,59 @@ class WaitAdsStartedTask extends DefaultTask {

@TaskAction
public execute() {
def process = adm.process
logger.info("Waiting for ADS start... ")

BufferedReader reader =
new BufferedReader(new InputStreamReader(process.getInputStream()));
def Process process = adm.process

BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
AtomicBoolean match = new AtomicBoolean(false)
ArrayList<String> adsOutput = new ArrayList<>();

List<String> text = new ArrayList<>();
String line;
while (process.isAlive() && (line = reader.readLine()) != null) {
logger.info(line)
text.add(line)
if (line.contains(START_CONDITION)) {
break
}
Runnable waitForAdsStarted = () -> {

logger.info("Waiting for ADS start... ")
String line;
line = reader.readLine();

while (line != null) {
logger.info(" ADS : " + line);
adsOutput.add(line);
if (line.matches(START_CONDITION_REGEXP)) {
logger.info(" Start condition met")
match.set(true)
break;
} else {
//logger.info("Start condition NOT met for line")
}
line = reader.readLine();
}
}

if (process.isAlive()) {
logger.info("ADS started!")

Thread t = new Thread(waitForAdsStarted);
t.start();


int c = 0;
while (c++ < 120 *2 && !match.get() && t.isAlive()) {
Thread.sleep(500)

logger.info(" Waiting for condition ADS have started, match=" + match.get() +", alive="+t.isAlive())
}
logger.info("Out of waiting loop, match=" + match.get() +", alive="+t.isAlive())
boolean wasAlive = process.isAlive()
t.interrupt();

if (!match.get() && wasAlive) {
process.destroy()
adsOutput.forEach {it->logger.error(it)}
throw new RuntimeException("ADS failed to start within time, giving up! See debug output.")
} else if (!wasAlive) {
adsOutput.forEach {it->logger.error(it)}
throw new RuntimeException("ADS failed to start because of an error! See debug output.")
} else {
logger.warn( "ADS failed to start!")
text.stream().forEach(System.err::println)
throw new RuntimeException("ADS failed to start, see output above")
println " ADS successfully started!"
}
}
}


0 comments on commit abc4d12

Please sign in to comment.