Skip to content

Commit

Permalink
WIP2
Browse files Browse the repository at this point in the history
  • Loading branch information
dima767 committed Jan 15, 2020
1 parent d51fca6 commit b9d69f7
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 1 deletion.
16 changes: 16 additions & 0 deletions beacon/beacon-core/build.gradle
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()
}
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";
}
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 {
}
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;
}
}
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);
}
}
41 changes: 41 additions & 0 deletions beacon/beacon-spring/build.gradle
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'
}
2 changes: 1 addition & 1 deletion settings.gradle
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'

0 comments on commit b9d69f7

Please sign in to comment.