Skip to content

Commit

Permalink
SHIBUI-2584
Browse files Browse the repository at this point in the history
Correcting/updating the scheduler. Additional debug logging setup when data is sent.
  • Loading branch information
chasegawa committed Jul 7, 2023
1 parent 17736d8 commit 03ae6af
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,16 @@
import edu.internet2.tier.shibboleth.admin.util.LuceneUtility;
import edu.internet2.tier.shibboleth.admin.util.ModelRepresentationConversions;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import net.javacrumbs.shedlock.core.LockProvider;
import net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider;
import org.apache.lucene.analysis.Analyzer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.actuate.health.HealthEndpoint;
import org.springframework.boot.actuate.info.InfoEndpoint;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.client.RestTemplateBuilder;
Expand Down Expand Up @@ -82,11 +83,13 @@
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.Random;

@SpringBootConfiguration
@Import(SearchConfiguration.class)
@ComponentScan(basePackages = "{ edu.internet2.tier.shibboleth.admin.ui.service }")
@EnableConfigurationProperties({CustomPropertiesConfiguration.class, ShibUIConfiguration.class})
@Slf4j
public class CoreShibUiConfiguration {
@Bean
public OpenSamlObjects openSamlObjects() {
Expand Down Expand Up @@ -276,8 +279,21 @@ public LockProvider lockProvider(DataSource dataSource) {
@Bean
public String getBeaconCronValue(BeaconConfigurationRepository repo)
{
Optional<BeaconConfiguration> bc = repo.findById(1);
return bc.isPresent() ? bc.get().getSendCron() : "0 3 * * * *";
Optional<BeaconConfiguration> obc = repo.findById(1);
BeaconConfiguration bc;
if (obc.isEmpty()) {
//set random cron in db
BeaconConfiguration newbc = new BeaconConfiguration();
Random rand = new Random();
String cron = "0 " + rand.nextInt(60) + " " + rand.nextInt(4) + " * * ?";
newbc.setSendCron(cron);
repo.save(newbc);
bc = repo.findById(1).get();
} else {
bc = obc.get();
}
log.info("Scheduling beacon cron: {}", bc.getSendCron());
return bc.getSendCron();
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public ResponseEntity<?> getDetail() throws JsonProcessingException {
return ResponseEntity.ok(service.getBeaconData());
}

@PostMapping("/send")
// This should be a POST, but to make it easier to hit, this is a GET
@GetMapping("/send")
public ResponseEntity<?> forceSendBeaconData() {
beaconReporter.sendBeaconData();
return ResponseEntity.ok("Manual push of beacon data completed");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,18 @@ public class BeaconReportingTask {
public void sendBeaconData() {
endpointUrls.forEach(url -> {
try {
String dataOutput = dataService.getBeaconData();
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json; utf-8");
con.setRequestProperty("Accept", "application/json");
con.setDoOutput(true);
try (OutputStream os = con.getOutputStream()) {
byte[] input = dataService.getBeaconData().getBytes(StandardCharsets.UTF_8);
byte[] input = dataOutput.getBytes(StandardCharsets.UTF_8);
os.write(input, 0, input.length);
}
log.info("TIER Beacon data sent to {} with response code: {}", url, con.getResponseCode());
log.debug("TIER Beacon data load: {}", dataOutput);
}
catch (IOException e) {
e.printStackTrace();
Expand Down

0 comments on commit 03ae6af

Please sign in to comment.