Skip to content
This repository has been archived by the owner on Sep 1, 2023. It is now read-only.

Commit

Permalink
Several non-breaking development improvements:
Browse files Browse the repository at this point in the history
- Jobson releases now automatically build & deploys from via Travis CI

- Various system tests have been created for the Jobson CLI. Tests
  will now run various jobson commands (e.g. `jobson new --demo`) to
  ensure they behave as expected.

- All dependencies have been updated to their latest versions

- Redundant dependencies were removed
  • Loading branch information
adamkewley committed Dec 16, 2017
2 parents de27f63 + a1b2f58 commit 8e77644
Show file tree
Hide file tree
Showing 30 changed files with 471 additions and 115 deletions.
23 changes: 23 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
language: java

branches:
only:
- master
- dev
- /\d+.\d+.\d+/ # tagged versions
- /\d+.\d+.\d+-staging/ # staging area for tagged releases

before_deploy:
- gem install fpm # install gem for creating OS packages
- bash packaging/make-deb-pkg.sh $TRAVIS_TAG # build OS packages

deploy:
provider: releases
api_key:
secure: SI69iJp/8r8DhGxHmh7rqCpqDPbtPfQr26Zvk9cDDswVgIcziwUAD1M0oBCFT7TxERupg5N7Nf11vYN5g7TXPhIP6UXwGNnM2nGqTQp6K4vnvgrJk5ZdtKti97eVTDYlxZj363sZ9Mmn+pPYiiuQzqk7NzfjW2f0P2DXhWgIjgAioMopYF1cMxUN2pQ6NEH6UzNK0sT064A0JpYulIOi9EWhWgAiagsvk2mxvjcvQfyvJooSYU+DPEoDQN8Ly7Xe2PXXNnDeWFgTczcEoIGaAzJtVK6DFfbGq17BIcHh3e8Dy5Qjf4mAWUxY0BmVV4ZIDR5/v08rSGS4Su/vlg/LxNt0cWj1KPXPlWSqzyVGSZV1qDfXGqf7/KE8xM+WQpZLZUSgV3LNsitAjJ3X/0wepdPHniwJXj+vcCfoRd4KZcsKT5wLkSAQwh3smxZ6qEBIumFp6WHNs2nEL/T0cCx9Uw7hFSAMIe9ObSaEK3WecMF9rbX1opYqdPveQsNM4SSQ6k2f4lGOjX0bOWcBZlnkcrXOkEHxP/G40ng/V75wQEP9N2r4EMgcLMp+64pG2zg8suDZtx0nXxWQfD9PRcvuFtgpxNQ80DxgLkq53ju/afVsepeAInPL+NcFJPZPYgTjhBf4GIjuCTZFXk2rpraueYGk++brCPvJtnehdQjIkio=

skip_cleanup: true

file:
- target/jobson_${TRAVIS_TAG}_amd64.deb
- target/jobson-${TRAVIS_TAG}-bin.tar.gz

on:
tags: true

46 changes: 17 additions & 29 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

<groupId>com.github.jobson</groupId>
<artifactId>jobson</artifactId>
<version>0.0.3</version>
<version>0.0.4</version>
<name>jobson</name>
<description>Webify command-line applications</description>
<description>
A web server that can turn command-line applications into a job system.
</description>
<url>https://github.com/adamkewley/jobson</url>
<inceptionYear>2017</inceptionYear>

Expand Down Expand Up @@ -48,7 +50,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<dropwizard.version>1.1.1</dropwizard.version>
<dropwizard.version>1.2.2</dropwizard.version>
<mainClass>com.github.jobson.App</mainClass>
</properties>

Expand Down Expand Up @@ -78,33 +80,33 @@
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
<version>2.5</version>
</dependency>

<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.9</version>
<version>1.11</version>
</dependency>

<dependency>
<groupId>io.reactivex.rxjava2</groupId>
<artifactId>rxjava</artifactId>
<version>2.1.0</version>
<version>2.1.7</version>
</dependency>

<!-- Basic websocket support for Jetty (the core HTTP server) -->
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>javax-websocket-server-impl</artifactId>
<version>9.4.2.v20170220</version>
<version>9.4.8.v20171121</version>
</dependency>

<!-- Generating Lorem-Ipsum etc. for generator commands -->
<dependency>
<groupId>com.github.javafaker</groupId>
<artifactId>javafaker</artifactId>
<version>0.13</version>
<version>0.14</version>
</dependency>

<!-- For automatically detecting MIME types from filenames/data -->
Expand All @@ -118,33 +120,26 @@
<dependency>
<groupId>com.github.jsqlparser</groupId>
<artifactId>jsqlparser</artifactId>
<version>1.0</version>
<version>1.1</version>
</dependency>

<!-- To document the HTTP API -->
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.5.12</version>
<version>1.5.17</version>
<scope>compile</scope>
</dependency>

<!-- To generate a parser for the template expressions used in job arguments etc. -->
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
<version>4.7</version>
<version>4.7.1</version>
<scope>compile</scope>
</dependency>


<!-- For building dummy ContainerRequestContexts -->
<dependency>
<groupId>org.glassfish.jersey.test-framework</groupId>
<artifactId>jersey-test-framework-util</artifactId>
<scope>test</scope>
<version>2.24</version>
</dependency>

<dependency>
<groupId>junit</groupId>
Expand All @@ -156,7 +151,7 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<version>1.10.19</version>
<scope>test</scope>
</dependency>

Expand All @@ -166,13 +161,6 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.java-websocket</groupId>
<artifactId>Java-WebSocket</artifactId>
<version>1.3.4</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand All @@ -181,7 +169,7 @@
<!-- java 1.8 -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
Expand All @@ -192,7 +180,7 @@
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>4.7</version>
<version>4.7.1</version>

<executions>
<execution>
Expand All @@ -211,7 +199,7 @@
<!-- Bundle the entire application into a fat JAR -->
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.1</version>
<version>3.1.0</version>
<executions>
<execution>
<phase>package</phase>
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/github/jobson/Helpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,16 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.*;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
Expand Down
12 changes: 1 addition & 11 deletions src/main/java/com/github/jobson/commands/RunCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,17 +197,7 @@ private EitherVisitor<ValidJobRequest, List<ValidationError>> createResultVisito
public void whenLeft(ValidJobRequest left) {
try {
final FinalizedJob f = jobManager.submit(left, listeners).getRight().get();

switch (f.getFinalStatus()) {
case ABORTED:
System.exit(112);
case FATAL_ERROR:
System.exit(1);
case FINISHED:
System.exit(0);
default:
System.exit(1);
}
System.exit(f.getFinalStatus().toExitCode());
} catch (Exception ex) {
System.err.println("Error encountered: " + ex.toString());
System.exit(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.github.jobson.api.v1.APIJobRequest;
import com.github.jobson.commands.DefaultedConfiguredCommand;
import com.github.jobson.config.ApplicationConfig;
import com.github.jobson.jobinputs.JobExpectedInput;
import com.github.jobson.jobinputs.JobExpectedInputId;
import com.github.jobson.jobinputs.JobInput;
import com.github.jobson.specs.JobSpec;
Expand All @@ -34,7 +35,6 @@

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.AbstractMap;
import java.util.Map;

import static com.github.jobson.Constants.SPEC_DIR_SPEC_FILENAME;
Expand Down Expand Up @@ -82,12 +82,15 @@ protected void run(Bootstrap<ApplicationConfig> bootstrap, Namespace namespace,
}

private Map<JobExpectedInputId, JsonNode> generateInputs(JobSpec jobSpec) {
return jobSpec.getExpectedInputs().stream().map(expectedInput -> {
final JobExpectedInputId id = expectedInput.getId();
final JobInput generatedInput = expectedInput.getDefault().isPresent() ?
expectedInput.getDefault().get() : expectedInput.generateExampleInput();
final JsonNode inputAsNode = toJSONNode(generatedInput);
return new AbstractMap.SimpleEntry<>(id, inputAsNode);
}).collect(toMap(e -> e.getKey(), e -> e.getValue()));
return jobSpec
.getExpectedInputs()
.stream()
.collect(toMap(JobExpectedInput::getId, this::generateInput));
}

private JsonNode generateInput(JobExpectedInput<?> expectedInput) {
final JobInput generatedInput = expectedInput.getDefault().isPresent() ?
expectedInput.getDefault().get() : expectedInput.generateExampleInput();
return toJSONNode(generatedInput);
}
}
32 changes: 18 additions & 14 deletions src/main/java/com/github/jobson/commands/users/UseraddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public final class UseraddCommand extends DefaultedConfiguredCommand<Application
private static String PASSWORD_ARG = "-p";

public UseraddCommand() {
super("add", "create a new user with a random password");
super("add", "create a new user with a random password. Assumes basic auth.");
}

@Override
Expand All @@ -67,22 +67,26 @@ protected void run(Bootstrap<ApplicationConfig> bootstrap, Namespace namespace,
final boolean userExists = dao.getUserCredentialsById(login).isPresent();

if (!userExists) {
final String password = namespace.getString(PASSWORD_ARG) == null ?
generateRandomBase36String(30) :
namespace.getString(PASSWORD_ARG);

final boolean userAdded =
dao.addNewUser(login, BASIC_AUTH_NAME, BasicAuthenticator.createAuthField(password));

if (userAdded) {
System.exit(0);
} else {
System.err.println("encountered an error adding a new user (this shouldn't happen)");
System.exit(1);
}
addNewUser(namespace, dao, login);
} else {
System.err.println(format("user '%s' already exists, you can set this user's password with `passwd`.", login));
System.exit(1);
}
}

private void addNewUser(Namespace namespace, FilesystemUserDAO dao, UserId login) {
final String password = namespace.getString(PASSWORD_ARG) == null ?
generateRandomBase36String(30) :
namespace.getString(PASSWORD_ARG);

final boolean userAdded =
dao.addNewUser(login, BASIC_AUTH_NAME, BasicAuthenticator.createAuthField(password));

if (userAdded) {
System.exit(0);
} else {
System.err.println("encountered an error adding a new user (this shouldn't happen)");
System.exit(1);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static com.github.jobson.Constants.SPEC_DIR_SPEC_FILENAME;
import static com.github.jobson.Helpers.readYAML;
import static java.util.Collections.singletonList;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toMap;

public final class ValidateSpecCommand extends DefaultedConfiguredCommand<ApplicationConfig> {

Expand Down Expand Up @@ -77,7 +77,7 @@ protected void run(Bootstrap<ApplicationConfig> bootstrap, Namespace namespace,
specIds.stream()
.map(specId -> getSpecErrors(jobSpecsDir, specId))
.filter(entry -> entry.getValue().size() > 0)
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
.collect(toMap(e -> e.getKey(), e -> e.getValue()));

if (allErrors.size() > 0) {
allErrors.forEach(this::printErrors);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.NotDirectoryException;
import java.nio.file.Path;
import java.util.List;
Expand All @@ -55,8 +54,7 @@ private static Optional<JobSpec> loadJobSpec(Path jobSpecDir) {

try {
if (jobSpecPath.toFile().exists()) {
final String jobSpecYAML = new String(Files.readAllBytes(jobSpecPath));
final JobSpec jobSpec = readYAML(jobSpecYAML, JobSpec.class);
final JobSpec jobSpec = readYAML(jobSpecPath.toFile(), JobSpec.class);
jobSpec.setId(new JobSpecId(jobSpecDir.toFile().getName()));

final JobSpec resolvedJobSpec = jobSpec.withDependenciesResolvedRelativeTo(jobSpecDir);
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/github/jobson/jobs/JobStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,17 @@ public static Set<JobStatus> getAbortableStatuses() {
public boolean isAbortable() {
return getAbortableStatuses().contains(this);
}

public int toExitCode() {
switch (this) {
case ABORTED:
return 112;
case FATAL_ERROR:
return 1;
case FINISHED:
return 0;
default:
return 1;
}
}
}
Loading

0 comments on commit 8e77644

Please sign in to comment.