Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(release): 0.0.5 #15

Merged
merged 3 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,28 @@ on:
jobs:
coverage:
runs-on: ubuntu-latest
env:
VOLUME_BASE_PATH: "/tmp/capy"
AVAILABLE_VOLUMES: "1,2,3"
steps:
- uses: actions/checkout@v3
with:
submodules: true

- uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '11'

- name: Create dir structure
run: chmod +x ./.setup-vol-dir && ./.setup-vol-dir $VOLUME_BASE_PATH

- name: Start services
run: docker-compose up -d

- name: Test
run: chmod +x ./gradlew && ./gradlew testCodeCoverageReport

- uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
Expand Down
15 changes: 14 additions & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,35 @@ jobs:
- uses: actions/checkout@v3
with:
submodules: true

- uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '11'

- name: Build
run: chmod +x ./gradlew && ./gradlew build
run: chmod +x ./gradlew && ./gradlew build -x test

test:
runs-on: ubuntu-latest
env:
VOLUME_BASE_PATH: "/tmp/capy"
AVAILABLE_VOLUMES: "1,2,3"
steps:
- uses: actions/checkout@v3
with:
submodules: true

- uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '11'

- name: Create dir structure
run: chmod +x ./.setup-vol-dir && ./.setup-vol-dir $VOLUME_BASE_PATH

- name: Start services
run: docker-compose up -d

- name: Test
run: chmod +x ./gradlew && ./gradlew test
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,13 @@
# Ignore Gradle build output directory
build

# npm
node_modules

# JDTLS
bin
.settings
.classpath
.project
/workspace
/*/workspace
11 changes: 11 additions & 0 deletions .setup-vol-dir
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env sh
#
# Helper to create the directory structure required for Worker service
# $1 -> Base Path

mkdir -p $1/files/volume1
mkdir -p $1/files/volume2
mkdir -p $1/files/volume3
mkdir -p $1/backups/volume1
mkdir -p $1/backups/volume2
mkdir -p $1/backups/volume3
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### 0.0.5 (2023-09-27)


### Features

* Upload file & Testing ([#14](https://github.com/hawks-atlanta/worker-java/issues/14)) ([757794b](https://github.com/hawks-atlanta/worker-java/commit/757794bf7f570ab425b775f3c8c3f0e165642524))

### 0.0.4 (2023-09-13)

### 0.0.3 (2023-09-11)

### 0.0.2 (2023-08-29)
Expand Down
11 changes: 11 additions & 0 deletions CLI.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# CLI

This document describes how to use the service as a CLI tool.

## Environment variables

| Variable | Description | Example |
|--------------------|-----------------------------------------------|-------------------------|
| `METADATA_BASEURL` | Metadata service host | `http://127.0.0.1:8082` |
| `VOLUME_BASE_PATH` | The path where file and backup volumes lie in | `/tmp/store` |
| `VOLUME_COUNT` | How many volumes there is | `3` |
14 changes: 12 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,23 @@ FROM adoptopenjdk/openjdk11:x86_64-alpine-jdk-11.0.20_8-slim as builder
COPY . /src
WORKDIR /src

RUN ./gradlew build
RUN ./gradlew build -x test

# runner

FROM adoptopenjdk/openjdk11:x86_64-alpine-jre-11.0.20_8

COPY --from=builder /src/app/build/libs/app-all.jar /opt/app.jar
EXPOSE 8080/tcp

# create directory structure

COPY --from=builder /src/.setup-vol-dir /opt/.setup-vol-dir
RUN /opt/.setup-vol-dir /var/capy/store
RUN rm /opt/.setup-vol-dir

EXPOSE 1099/tcp
ENV METADATA_BASEURL "http://127.0.0.1:8082/api/v1"
ENV VOLUME_BASE_PATH "/var/capy/store"
ENV AVAILABLE_VOLUMES "1,2,3"

CMD ["java", "-jar", "/opt/app.jar"]
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ git submodule update --init
- (Optional) Use the **gradle wrapper script** (`./gradlew`) for all `gradle` commands. For example:

```sh
./gradlew build
./gradlew run
```

- (Optional) Use the provided `nix-shell` to get into a shell with all required dependecies [[install Nix](https://nixos.org/download)].
Expand All @@ -41,7 +41,18 @@ gradle run
### Run tests

```sh
gradle test
gradle test # only run tests
gradle testCodeCoverageReport # run tests & generate coverage

# rerun tests
gradle cleanTest test
gradle cleanTest testCodeCoverageReport
```

See test results
```sh
app/build/reports/tests/test/index.html # general
app/build/reports/jacoco/testCodeCoverageReport/html/index.html # coverage
```

### Format
Expand Down
36 changes: 34 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent

plugins {
// Apply the application plugin to add support for building a CLI application in Java.
id 'application'
Expand Down Expand Up @@ -25,7 +28,11 @@ dependencies {
implementation 'com.google.guava:guava:31.1-jre'

// Use subproject
implementation project(':capyfile.rmi.interfaces')
implementation project(':capyfile.rmi')

// JSON library
// https://mvnrepository.com/artifact/org.json/json
implementation 'org.json:json:20230618'
}

// Apply a specific Java toolchain to ease working on different environments.
Expand All @@ -41,6 +48,31 @@ application {
}

tasks.named('test') {
// Use JUnit Platform for unit tests.
useJUnitPlatform()

testLogging {
// set options for log level LIFECYCLE
events TestLogEvent.FAILED,
TestLogEvent.PASSED,
TestLogEvent.SKIPPED,
TestLogEvent.STANDARD_ERROR
TestLogEvent.STANDARD_OUT
exceptionFormat TestExceptionFormat.FULL
showExceptions true
showCauses true
showStackTraces true

// set options for log level DEBUG and INFO
debug {
events TestLogEvent.STARTED,
TestLogEvent.FAILED,
TestLogEvent.PASSED,
TestLogEvent.SKIPPED,
TestLogEvent.STANDARD_ERROR,
TestLogEvent.STANDARD_OUT
exceptionFormat TestExceptionFormat.FULL
}
info.events = debug.events
info.exceptionFormat = debug.exceptionFormat
}
}
10 changes: 3 additions & 7 deletions app/src/main/java/worker/App.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package worker;

import capyfile.rmi.*;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import worker.config.Config;

public class App
{
public static void main (String[] args)
{
Config.initializeFromEnv ();
System.out.println ("Worker: Serving RMI");

try {
Expand All @@ -19,7 +15,7 @@ public static void main (String[] args)
server.createStubAndBind ();

} catch (Exception e) {
System.out.println (e);
e.printStackTrace ();
}
}
}
24 changes: 17 additions & 7 deletions app/src/main/java/worker/WorkerServiceImpl.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package capyfile.rmi;
package worker;

import capyfile.rmi.interfaces.File;
import capyfile.rmi.interfaces.FileDownload;
import capyfile.rmi.interfaces.IWorkerService;
import capyfile.rmi.DownloadFileArgs;
import capyfile.rmi.File;
import capyfile.rmi.IWorkerService;
import capyfile.rmi.UploadFileArgs;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import worker.file.ThreadUploadFile;

public class WorkerServiceImpl implements IWorkerService
{
Expand All @@ -18,15 +20,23 @@ public void createStubAndBind () throws RemoteException
(IWorkerService)UnicastRemoteObject.exportObject ((IWorkerService)this, 0);

// RMI registry
Registry registry = LocateRegistry.createRegistry (1900);
Registry registry = LocateRegistry.createRegistry (1099);

// bind remote object
registry.rebind ("WorkerService", stub);
}

public void uploadFile (File upload) throws RemoteException { return; }
public void uploadFile (UploadFileArgs args) throws RemoteException
{
// delegate to thread

ThreadUploadFile thread = new ThreadUploadFile (args.uuid, args.contents);
thread.start ();

return;
}

public File downloadFile (FileDownload download) throws RemoteException
public File downloadFile (DownloadFileArgs args) throws RemoteException
{
File file = new File ("----", null);
return file;
Expand Down
35 changes: 35 additions & 0 deletions app/src/main/java/worker/config/Config.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package worker.config;

import java.util.Arrays;

public class Config
{
private static String metadataBaseUrl = "";
private static String volumeBasePath = "";
private static int[] availableVolumes = {};

public static String getMetadataBaseUrl () { return metadataBaseUrl; }
public static String getVolumeBasePath () { return volumeBasePath; }
public static int[] getAvailableVolumes () { return availableVolumes; }
private static String getEnv (String env, String def)
{
return System.getenv ().getOrDefault (env, def);
}

public static void initializeFromEnv ()
{
Config.metadataBaseUrl = getEnv ("METADATA_BASEURL", "http://127.0.0.1:8082/api/v1");
Config.volumeBasePath = getEnv ("VOLUME_BASE_PATH", "/var/capy/store");
String aVols = getEnv ("AVAILABLE_VOLUMES", "");

try {
Config.availableVolumes =
Arrays.stream (aVols.split (",")).mapToInt (Integer::parseInt).toArray ();
if (availableVolumes.length == 0) {
throw new RuntimeException ("Invalid var AVAILABLE_VOLUMES: No volumes specified");
}
} catch (Exception e) {
throw new RuntimeException ("Invalid var AVAILABLE_VOLUMES: Couldn't parse");
}
}
}
Loading