Skip to content

Commit

Permalink
Add license headers and plugin to check always on tests. Minor format…
Browse files Browse the repository at this point in the history
…ing changes.
  • Loading branch information
jordeu committed Oct 28, 2021
1 parent 895da68 commit 1555f33
Show file tree
Hide file tree
Showing 17 changed files with 190 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ jobs:
release:
name: Release
if: "contains(github.event.head_commit.message, '[release]') && github.event.ref=='refs/heads/master'"
needs: [linux-image, mac-image, windows-image]
needs: [ linux-image, mac-image, windows-image ]
runs-on: ubuntu-latest
steps:
- name: Checkout repository
Expand Down
8 changes: 8 additions & 0 deletions HEADER.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Copyright (c) ${year}, ${name}.

This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.

This Source Code Form is "Incompatible With Secondary Licenses", as
defined by the Mozilla Public License, v. 2.0.
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
# Tower Agent

Tower Agent allows Tower to launch pipelines on HPC clusters that do not allow
direct access throw an SSH client.
Tower Agent allows Tower to launch pipelines on HPC clusters that do not allow direct access throw an SSH client.

Tower Agent it's a standalone process that when executed in a node that can submit
jobs to the cluster (i.e. the login node) it establishes an authenticated secure
reverse connection with Tower, allowing Tower to submit and monitor new jobs. The
jobs are submitted on behalf of the same user that it's running the agent process.
Tower Agent it's a standalone process that when executed in a node that can submit jobs to the cluster (i.e. the login node) it establishes an authenticated secure reverse connection with Tower, allowing Tower to submit and monitor new
jobs. The jobs are submitted on behalf of the same user that it's running the agent process.

## Build binary version

Expand Down
24 changes: 24 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
/*
* Copyright (c) 2021, Seqera Labs.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This Source Code Form is "Incompatible With Secondary Licenses", as
* defined by the Mozilla Public License, v. 2.0.
*/

import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform

plugins {
id 'org.cadixdev.licenser' version '0.6.1'
id 'org.graalvm.buildtools.native'
id("io.micronaut.application") version "2.0.6"
}
Expand Down Expand Up @@ -47,6 +59,16 @@ dependencies {
testImplementation('org.junit.jupiter:junit-jupiter')
}

license {
header = project.file('HEADER.txt')
properties {
name = 'Seqera Labs'
year = 2021
}
exclude '**/*.properties'
exclude 'gradlew'
}

application {
mainClass.set("io.seqera.tower.agent.Agent")
}
Expand Down Expand Up @@ -82,6 +104,7 @@ compileJava {

test {
useJUnitPlatform()
dependsOn checkLicenses
}


Expand All @@ -102,3 +125,4 @@ graalvmNative {




2 changes: 1 addition & 1 deletion micronaut-cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ defaultPackage: io.seqera.tower.agent
testFramework: junit
sourceLanguage: java
buildTool: gradle
features: [annotation-api, app-name, graalvm, gradle, http-client, java, java-application, junit, logback, netty-server, picocli, picocli-java-application, picocli-junit, readme, shade, yaml]
features: [ annotation-api, app-name, graalvm, gradle, http-client, java, java-application, junit, logback, netty-server, picocli, picocli-java-application, picocli-junit, readme, shade, yaml ]
13 changes: 12 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
* Copyright (c) 2021, Seqera Labs.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This Source Code Form is "Incompatible With Secondary Licenses", as
* defined by the Mozilla Public License, v. 2.0.
*/

pluginManagement {
plugins {
id 'org.graalvm.buildtools.native' version getProperty('native.gradle.plugin.version')
Expand All @@ -8,4 +19,4 @@ pluginManagement {
}
}

rootProject.name="tower-agent"
rootProject.name = "tower-agent"
34 changes: 22 additions & 12 deletions src/main/java/io/seqera/tower/agent/Agent.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
* Copyright (c) 2021, Seqera Labs.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This Source Code Form is "Incompatible With Secondary Licenses", as
* defined by the Mozilla Public License, v. 2.0.
*/

package io.seqera.tower.agent;

import io.micronaut.configuration.picocli.PicocliRunner;
Expand All @@ -7,18 +18,17 @@
import io.micronaut.rxjava2.http.client.websockets.RxWebSocketClient;
import io.micronaut.scheduling.TaskScheduler;
import io.micronaut.websocket.exceptions.WebSocketClientException;

import java.net.URI;
import java.net.URISyntaxException;
import java.time.Duration;

import io.seqera.tower.agent.exchange.HeartbeatMessage;
import io.seqera.tower.agent.utils.VersionProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
import picocli.CommandLine.Parameters;
import picocli.CommandLine.Command;

import java.net.URI;
import java.net.URISyntaxException;
import java.time.Duration;

@Command(
name = "tw-agent",
Expand All @@ -37,7 +47,6 @@
)
public class Agent implements Runnable {
private static Logger logger = LoggerFactory.getLogger(Agent.class);
private ApplicationContext ctx;

@Parameters(index = "0", paramLabel = "AGENT_CONNECTION_ID", description = "Agent connection ID to identify this agent", arity = "1")
String agentKey;
Expand All @@ -46,14 +55,19 @@ public class Agent implements Runnable {
String token;

@Option(names = {"-u", "--url"}, description = "Tower server API endpoint URL. Defaults to tower.nf (TOWER_API_ENDPOINT)", defaultValue = "${TOWER_API_ENDPOINT:-https://api.tower.nf}", required = true)
public String url;
String url;

private ApplicationContext ctx;
private AgentClientSocket agentClient;

Agent() {
ctx = ApplicationContext.run();
}

public static void main(String[] args) throws Exception {
PicocliRunner.run(Agent.class, args);
}

@Override
public void run() {

Expand Down Expand Up @@ -89,8 +103,4 @@ private void sendPeriodicHeartbeat() {
agentClient.send(new HeartbeatMessage());
});
}

public static void main(String[] args) throws Exception {
PicocliRunner.run(Agent.class, args);
}
}
20 changes: 15 additions & 5 deletions src/main/java/io/seqera/tower/agent/AgentClientSocket.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
* Copyright (c) 2021, Seqera Labs.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This Source Code Form is "Incompatible With Secondary Licenses", as
* defined by the Mozilla Public License, v. 2.0.
*/

package io.seqera.tower.agent;

import io.micronaut.http.HttpRequest;
Expand Down Expand Up @@ -58,13 +69,13 @@ void onClose() {
private void execCommand(CommandRequest message) {
try {
System.out.println("Execute command: " + message.getCommand());
Process process = new ProcessBuilder().command("sh","-c", message.getCommand()).start();
Process process = new ProcessBuilder().command("sh", "-c", message.getCommand()).start();
int exitStatus = process.waitFor();
// read the stdout
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
StringBuilder builder = new StringBuilder();
String line=null;
while ( (line = reader.readLine()) != null) {
String line = null;
while ((line = reader.readLine()) != null) {
builder.append(line);
builder.append("\n");
}
Expand All @@ -75,8 +86,7 @@ private void execCommand(CommandRequest message) {
System.out.println("Sending response --> " + response);
session.sendSync(response);
System.out.println("Response sent");
}
catch ( Throwable e ){
} catch (Throwable e) {
// send result
CommandResponse response = new CommandResponse(message.getId(), e.getMessage().getBytes(), -1);
session.sendSync(response);
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/io/seqera/tower/agent/exchange/AgentMessage.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
* Copyright (c) 2021, Seqera Labs.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This Source Code Form is "Incompatible With Secondary Licenses", as
* defined by the Mozilla Public License, v. 2.0.
*/

package io.seqera.tower.agent.exchange;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
Expand All @@ -13,4 +24,5 @@
@JsonSubTypes.Type(value = CommandResponse.class, name = "command-response"),
@JsonSubTypes.Type(value = HeartbeatMessage.class, name = "heartbeat")
})
public abstract class AgentMessage implements Serializable {}
public abstract class AgentMessage implements Serializable {
}
11 changes: 11 additions & 0 deletions src/main/java/io/seqera/tower/agent/exchange/CommandRequest.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
* Copyright (c) 2021, Seqera Labs.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This Source Code Form is "Incompatible With Secondary Licenses", as
* defined by the Mozilla Public License, v. 2.0.
*/

package io.seqera.tower.agent.exchange;

import io.micronaut.core.annotation.ReflectiveAccess;
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/io/seqera/tower/agent/exchange/CommandResponse.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
* Copyright (c) 2021, Seqera Labs.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This Source Code Form is "Incompatible With Secondary Licenses", as
* defined by the Mozilla Public License, v. 2.0.
*/

package io.seqera.tower.agent.exchange;

import io.micronaut.core.annotation.ReflectiveAccess;
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/io/seqera/tower/agent/exchange/HeartbeatMessage.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
* Copyright (c) 2021, Seqera Labs.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This Source Code Form is "Incompatible With Secondary Licenses", as
* defined by the Mozilla Public License, v. 2.0.
*/

package io.seqera.tower.agent.exchange;

import io.micronaut.core.annotation.ReflectiveAccess;
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/io/seqera/tower/agent/utils/VersionProvider.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
* Copyright (c) 2021, Seqera Labs.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This Source Code Form is "Incompatible With Secondary Licenses", as
* defined by the Mozilla Public License, v. 2.0.
*/

package io.seqera.tower.agent.utils;

import picocli.CommandLine;
Expand Down
11 changes: 11 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
#
# Copyright (c) 2021, Seqera Labs.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.
#

micronaut:
application:
name: towerAgent
13 changes: 12 additions & 1 deletion src/main/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
<!--
Copyright (c) 2021, Seqera Labs.
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
This Source Code Form is "Incompatible With Secondary Licenses", as
defined by the Mozilla Public License, v. 2.0.
-->

<configuration>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
Expand All @@ -10,6 +21,6 @@
</appender>

<root level="info">
<appender-ref ref="STDOUT" />
<appender-ref ref="STDOUT"/>
</root>
</configuration>
16 changes: 13 additions & 3 deletions src/test/java/io/seqera/tower/agent/AgentTest.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
/*
* Copyright (c) 2021, Seqera Labs.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This Source Code Form is "Incompatible With Secondary Licenses", as
* defined by the Mozilla Public License, v. 2.0.
*/

package io.seqera.tower.agent;

import io.micronaut.runtime.EmbeddedApplication;
import io.micronaut.test.extensions.junit5.annotation.MicronautTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;

import jakarta.inject.Inject;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

@MicronautTest
class AgentTest {
Expand Down
11 changes: 11 additions & 0 deletions tw-agent
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
#!/bin/bash


#
# Copyright (c) 2021, Seqera Labs.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.
#

bash -c "./gradlew run -q --args=\"${*@Q}\""

0 comments on commit 1555f33

Please sign in to comment.