-
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
8 changed files
with
142 additions
and
11 deletions.
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
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
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
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
60 changes: 60 additions & 0 deletions
60
...g/src/main/java/edu/internet2/tap/beacon/configuration/BeaconPublishingConfiguration.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,60 @@ | ||
| package edu.internet2.tap.beacon.configuration; | ||
|
|
||
| import edu.internet2.tap.beacon.BeaconPublisher; | ||
| import edu.internet2.tap.beacon.DefaultBeaconPublisher; | ||
| import edu.internet2.tap.beacon.configuration.condition.ConditionalOnBeaconEnvironmentVariablesPresent; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.core.env.Environment; | ||
| import org.springframework.scheduling.annotation.Async; | ||
| import org.springframework.scheduling.annotation.Scheduled; | ||
|
|
||
| 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; | ||
|
|
||
| @Configuration | ||
| @ConditionalOnProperty(name = "shibui.beacon-enabled", havingValue = "true") | ||
| public class BeaconPublishingConfiguration { | ||
|
|
||
| private static final Logger logger = LoggerFactory.getLogger(BeaconPublishingConfiguration.class); | ||
|
|
||
| @Bean | ||
| @ConditionalOnBeaconEnvironmentVariablesPresent | ||
| public BeaconPublishingTask beaconPublisher(Environment env) { | ||
| logger.debug("Creating BeaconPublishingTask..."); | ||
| Map<String, String> beaconData = new HashMap<>(); | ||
| beaconData.put(LOG_HOST, env.getProperty(LOG_HOST)); | ||
| beaconData.put(LOG_PORT, env.getProperty(LOG_PORT)); | ||
| beaconData.put(IMAGE, env.getProperty(IMAGE)); | ||
| beaconData.put(VERSION, env.getProperty(VERSION)); | ||
| beaconData.put(TIERVERSION, env.getProperty(TIERVERSION)); | ||
| beaconData.put(MAINTAINER, env.getProperty(MAINTAINER)); | ||
| return new BeaconPublishingTask(new DefaultBeaconPublisher(beaconData)); | ||
| } | ||
|
|
||
| public static class BeaconPublishingTask { | ||
|
|
||
| private BeaconPublisher beaconPublisher; | ||
|
|
||
| public BeaconPublishingTask(BeaconPublisher beaconPublisher) { | ||
| this.beaconPublisher = beaconPublisher; | ||
| } | ||
|
|
||
| //Cron is based on the spec defined here: https://spaces.at.internet2.edu/display/TWGH/TIER+Instrumentation+-+The+TIER+Beacon | ||
| @Scheduled(cron = "0 ${random.int[0,59]} ${random.int[0,3]} ? * *}") | ||
| @Async | ||
| void publish() { | ||
| beaconPublisher.run(); | ||
| } | ||
| } | ||
| } |
48 changes: 48 additions & 0 deletions
48
...edu/internet2/tap/beacon/configuration/condition/BeaconEnvironmentVariablesCondition.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,48 @@ | ||
| package edu.internet2.tap.beacon.configuration.condition; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import org.springframework.boot.autoconfigure.condition.ConditionOutcome; | ||
| import org.springframework.boot.autoconfigure.condition.SpringBootCondition; | ||
| import org.springframework.context.annotation.Condition; | ||
| import org.springframework.context.annotation.ConditionContext; | ||
| import org.springframework.core.env.Environment; | ||
| import org.springframework.core.type.AnnotatedTypeMetadata; | ||
|
|
||
| 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; | ||
|
|
||
| /** | ||
| * {@link Condition} that checks for required beacon environment variables. | ||
| * | ||
| * @author Dmitriy Kopylenko | ||
| * @see ConditionalOnBeaconEnvironmentVariablesPresent | ||
| */ | ||
| public class BeaconEnvironmentVariablesCondition extends SpringBootCondition { | ||
|
|
||
| private static final String MATCHED_MSG = "Beacon properties are present. Beacon activation condition is matched."; | ||
|
|
||
| private static final String NOT_MATCHED_MSG = "Beacon properties are not present. Beacon activation condition is not matched."; | ||
|
|
||
| private static final Logger logger = LoggerFactory.getLogger(BeaconEnvironmentVariablesCondition.class); | ||
|
|
||
| @Override | ||
| public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { | ||
| Environment env = context.getEnvironment(); | ||
| if (env.containsProperty(LOG_HOST) | ||
| && env.containsProperty(LOG_PORT) | ||
| && env.containsProperty(IMAGE) | ||
| && env.containsProperty(VERSION) | ||
| && env.containsProperty(TIERVERSION) | ||
| && env.containsProperty(MAINTAINER)) { | ||
| logger.debug(MATCHED_MSG); | ||
| return ConditionOutcome.match(MATCHED_MSG); | ||
| } | ||
| logger.debug(NOT_MATCHED_MSG); | ||
| return ConditionOutcome.noMatch(NOT_MATCHED_MSG); | ||
| } | ||
| } |
21 changes: 21 additions & 0 deletions
21
...t2/tap/beacon/configuration/condition/ConditionalOnBeaconEnvironmentVariablesPresent.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,21 @@ | ||
| package edu.internet2.tap.beacon.configuration.condition; | ||
|
|
||
| import org.springframework.context.annotation.Conditional; | ||
|
|
||
| import java.lang.annotation.Documented; | ||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| /** | ||
| * {@link Conditional} that matches specific beacon environment variables are all present. | ||
| * | ||
| * @author Dmitriy Kopylenko | ||
| */ | ||
| @Target({ ElementType.TYPE, ElementType.METHOD }) | ||
| @Retention(RetentionPolicy.RUNTIME) | ||
| @Documented | ||
| @Conditional(BeaconEnvironmentVariablesCondition.class) | ||
| public @interface ConditionalOnBeaconEnvironmentVariablesPresent { | ||
| } |
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 @@ | ||
| org.springframework.boot.autoconfigure.EnableAutoConfiguration=edu.internet2.tap.beacon.configuration.BeaconPublishingConfiguration |