-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
168 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| apply plugin: 'java' | ||
| sourceCompatibility = 1.8 | ||
| targetCompatibility = 1.8 | ||
|
|
||
| repositories { | ||
| jcenter() | ||
| } | ||
|
|
||
| dependencies { | ||
| testImplementation 'org.junit.jupiter:junit-jupiter-api:5.5.2' | ||
| testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.5.2' | ||
| } | ||
|
|
||
| test { | ||
| useJUnitPlatform() | ||
| } |
22 changes: 22 additions & 0 deletions
22
beacon/beacon-core/src/main/java/edu/internet2/tap/beacon/Beacon.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package edu.internet2.tap.beacon; | ||
|
|
||
| /** | ||
| * Exposes expected names of environment variables holding beacon config data. | ||
| */ | ||
| public final class Beacon { | ||
|
|
||
| private Beacon() { | ||
| } | ||
|
|
||
| public static final String LOG_HOST = "LOGHOST"; | ||
|
|
||
| public static final String LOG_PORT = "LOGPORT"; | ||
|
|
||
| public static final String IMAGE = "IMAGE"; | ||
|
|
||
| public static final String VERSION = "VERSION"; | ||
|
|
||
| public static final String TIERVERSION = "TIERVERSION"; | ||
|
|
||
| public static final String MAINTAINER = "MAINTAINER"; | ||
| } |
10 changes: 10 additions & 0 deletions
10
beacon/beacon-core/src/main/java/edu/internet2/tap/beacon/BeaconPublisher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package edu.internet2.tap.beacon; | ||
|
|
||
| /** | ||
| * Simple SPI allowing implementations to publish to beacon service utilizing Runnable API | ||
| * so that publishing code could run in separate threads of execution. | ||
| * | ||
| * @author Dmitriy Kopylenko | ||
| */ | ||
| public interface BeaconPublisher extends Runnable { | ||
| } |
65 changes: 65 additions & 0 deletions
65
beacon/beacon-core/src/main/java/edu/internet2/tap/beacon/DefaultBeaconPublisher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| package edu.internet2.tap.beacon; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| import static edu.internet2.tap.beacon.Beacon.IMAGE; | ||
| import static edu.internet2.tap.beacon.Beacon.LOG_HOST; | ||
| import static edu.internet2.tap.beacon.Beacon.LOG_PORT; | ||
| import static edu.internet2.tap.beacon.Beacon.MAINTAINER; | ||
| import static edu.internet2.tap.beacon.Beacon.TIERVERSION; | ||
| import static edu.internet2.tap.beacon.Beacon.VERSION; | ||
|
|
||
| /** | ||
| * Default implementation that knows the details about payload structure with its data and beacon endpoint details | ||
| * gathered by upstream components and passed to this implementation at object construction site. | ||
| * | ||
| * @author Dmitriy Kopylenko | ||
| */ | ||
| public class DefaultBeaconPublisher implements BeaconPublisher { | ||
|
|
||
| private String endpointUri; | ||
|
|
||
| private Map<String, String> dataToPublish; | ||
|
|
||
| public DefaultBeaconPublisher(Map<String, String> beaconDetails) { | ||
|
|
||
|
|
||
| //Do data validation checks here. If any of the necessary beacon data not available here, throw a Runtime exception | ||
| if (beaconDetails == null) { | ||
| throw new IllegalArgumentException("beaconDetails Map must not be null"); | ||
| } | ||
| if (beaconDetails.get(LOG_HOST) == null | ||
| || beaconDetails.get(LOG_PORT) == null | ||
| || beaconDetails.get(IMAGE) == null | ||
| || beaconDetails.get(VERSION) == null | ||
| || beaconDetails.get(TIERVERSION) == null | ||
| || beaconDetails.get(MAINTAINER) == null) { | ||
| throw new IllegalArgumentException("Not all the necessary beacon data is available to be able to publish to beacon"); | ||
| } | ||
| this.endpointUri = String.format("http://%s:%s", beaconDetails.get(LOG_HOST), beaconDetails.get(LOG_PORT)); | ||
|
|
||
| this.dataToPublish = new HashMap<>(); | ||
| this.dataToPublish.put("msgType", "TIERBEACON"); | ||
| this.dataToPublish.put("msgName", "TIER"); | ||
| this.dataToPublish.put("msgVersion", "1.0"); | ||
| this.dataToPublish.put("tbProduct", beaconDetails.get(IMAGE)); | ||
| this.dataToPublish.put("tbProductVersion", beaconDetails.get(VERSION)); | ||
| this.dataToPublish.put("tbTIERRelease", beaconDetails.get(TIERVERSION)); | ||
| this.dataToPublish.put("tbMaintainer", beaconDetails.get(MAINTAINER)); | ||
| } | ||
|
|
||
| @Override | ||
| public void run() { | ||
| //log.debug("Posting data {} to beacon endpoint {}", dataToPublish, endpointUri); | ||
| } | ||
|
|
||
| //Below are package-private getters used in unit tests | ||
| String getEndpointUri() { | ||
| return this.endpointUri; | ||
| } | ||
|
|
||
| Map<String, String> getDataToPublish() { | ||
| return this.dataToPublish; | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
beacon/beacon-core/src/test/java/edu/internet2/tap/beacon/DefaultBeaconPublisherTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package edu.internet2.tap.beacon; | ||
|
|
||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| public class DefaultBeaconPublisherTests { | ||
|
|
||
| @Test | ||
| public void checkCorrectInvariantsWithBeaconDataNull() { | ||
| Assertions.assertTrue(true); | ||
| //new DefaultBeaconPublisher(null); | ||
| } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /*plugins { | ||
| id 'groovy' | ||
| id 'jacoco' | ||
| id 'org.springframework.boot' version '2.0.0.RELEASE' apply false | ||
| id 'io.spring.dependency-management' version '1.0.6.RELEASE' | ||
| id 'io.franzbecker.gradle-lombok' version '1.13' | ||
| }*/ | ||
|
|
||
| apply plugin: 'java' | ||
| sourceCompatibility = 1.8 | ||
| targetCompatibility = 1.8 | ||
|
|
||
| repositories { | ||
| jcenter() | ||
| } | ||
|
|
||
| /*dependencyManagement { | ||
| imports { | ||
| mavenBom org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES | ||
| } | ||
| }*/ | ||
|
|
||
| /*lombok { | ||
| version = "1.18.4" | ||
| //TODO: get new sha256 | ||
| sha256 = "" | ||
| }*/ | ||
|
|
||
| /*dependencies { | ||
| compileOnly project(':backend') | ||
| testCompile project(':backend') | ||
| testCompile "org.springframework.boot:spring-boot-starter-test" | ||
| testCompile "org.spockframework:spock-core:1.1-groovy-2.4" | ||
| testCompile "org.spockframework:spock-spring:1.1-groovy-2.4" | ||
| //annotationProcessor "org.springframework.boot:spring-boot-configuration-processor" | ||
| }*/ | ||
|
|
||
| dependencies { | ||
| testImplementation 'org.junit.jupiter:junit-jupiter-api:5.5.2' | ||
| testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.5.2' | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| include 'backend', 'ui', 'pac4j-module', 'beacon', 'beacon:core', 'beacon:spring' | ||
| include 'backend', 'ui', 'pac4j-module', 'beacon', 'beacon:beacon-core', 'beacon:beacon-spring' |