-
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.
Merge pull request #5 from Kowalski-IO/2.4.0
2.4.0
- Loading branch information
Showing
60 changed files
with
5,785 additions
and
802 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,12 +61,12 @@ public void allEmails() throws EmailException, ClaptrapException { | |
} | ||
|
||
@Test | ||
public void allEmailsForServer() throws ClaptrapException, EmailException { | ||
seedForServerEmails(); | ||
public void allEmailsForEnvironment() throws ClaptrapException, EmailException { | ||
seedForEnvironmentEmails(); | ||
|
||
final Collection<Email> fetchedEmails = mailbox.fetchAllForServer("test.claptrap.kowalski.io"); | ||
final Collection<Email> fetchedEmails = mailbox.fetchAllForEnvironment("test.claptrap.kowalski.io"); | ||
|
||
assertEquals("seedForServerEmails sends 2 emails total for server forServer", 2, fetchedEmails.size()); | ||
assertEquals("seedForEnvironmentEmails sends 2 emails total for server forEnvironment", 2, fetchedEmails.size()); | ||
|
||
} | ||
|
||
|
@@ -80,7 +80,7 @@ public void allEmailsForCriteria() throws EmailException, ClaptrapException { | |
|
||
final List<Email> fetchedEmails = Lists.newArrayList(mailbox.fetchForCriteria(filter)); | ||
|
||
assertEquals("seedForServerEmails sends 1 emails total to Nugget", 1, fetchedEmails.size()); | ||
assertEquals("seedForEnvironmentEmails sends 1 emails total to Nugget", 1, fetchedEmails.size()); | ||
|
||
assertEquals("[email protected]", fetchedEmails.get(0).getRecipient()); | ||
} | ||
|
@@ -96,20 +96,20 @@ private void seedAllEmails() throws EmailException { | |
email.setFrom("[email protected]", "Claptrap"); | ||
email.setSubject("Test simple email"); | ||
|
||
email.setMsg("This is a simple email test to see if Claptrap actually works!"); | ||
email.setMsg("This is a simple email test to see if Claptrap actually works! Here is a link to see if linkify is working: https://kowalski.io"); | ||
|
||
email.send(); | ||
|
||
} | ||
|
||
private void seedForServerEmails() throws EmailException { | ||
private void seedForEnvironmentEmails() throws EmailException { | ||
final SimpleEmail email = new SimpleEmail(); | ||
email.setHostName(hostname); | ||
email.setSmtpPort(smtpPort); | ||
|
||
email.addTo("[email protected]", "John Johnson"); | ||
email.addTo("[email protected]", "Frank Underwood"); | ||
email.setFrom("forServer@test.claptrap.kowalski.io", "Claptrap"); | ||
email.setFrom("forEnvironment@test.claptrap.kowalski.io", "Claptrap"); | ||
email.setSubject("Test simple email"); | ||
|
||
email.setMsg("This is a simple email test to see if Claptrap actually works!"); | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,7 +83,7 @@ public List<Email> parseMessages() throws Exception { | |
for (final String recipient : recipients) { | ||
final Email email = new Email(); | ||
|
||
email.setServerName(retrieveServerName(from)); | ||
email.setEnvironment(retrieveServerName(from)); | ||
email.setSender(from); | ||
email.setSubject(messageParser.getSubject()); | ||
|
||
|
@@ -108,7 +108,7 @@ public List<Email> parseMessages() throws Exception { | |
private Email createExceptionEmail(final Exception e) { | ||
final Email email = new Email(); | ||
|
||
email.setServerName("Claptrap.error"); | ||
email.setEnvironment("Claptrap.error"); | ||
email.setSender("[email protected]"); | ||
email.setSubject("Exception occurred processing email"); | ||
email.setPlainBody(e.getMessage()); | ||
|
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
70 changes: 70 additions & 0 deletions
70
claptrap-core/src/main/java/io/kowalski/claptrap/storage/logs/LogBroadcastService.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,70 @@ | ||
package io.kowalski.claptrap.storage.logs; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Named; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
import org.glassfish.jersey.media.sse.EventOutput; | ||
import org.glassfish.jersey.media.sse.OutboundEvent; | ||
import org.glassfish.jersey.media.sse.SseBroadcaster; | ||
|
||
import io.kowalski.claptrap.models.Log; | ||
import io.kowalski.claptrap.storage.BroadcastService; | ||
|
||
public class LogBroadcastService implements BroadcastService<Log, String> { | ||
|
||
private final ConcurrentHashMap<String, SseBroadcaster> broadcasterMap; | ||
|
||
@Inject | ||
public LogBroadcastService(@Named("logBroadcastMap") final ConcurrentHashMap<String, SseBroadcaster> broadcasterMap) { | ||
this.broadcasterMap = broadcasterMap; | ||
} | ||
|
||
@Override | ||
public void broadcast(final Log log) { | ||
final SseBroadcaster broadcaster = fetchBroadcaster(log.getEnvironment()); | ||
|
||
final OutboundEvent.Builder eventBuilder = new OutboundEvent.Builder(); | ||
final OutboundEvent event = eventBuilder.name("message").mediaType(MediaType.APPLICATION_JSON_TYPE) | ||
.data(Log.class, log).build(); | ||
|
||
broadcaster.broadcast(event); | ||
} | ||
|
||
@Override | ||
public void broadcast(final List<Log> logs) { | ||
for (final Log log : logs) { | ||
broadcast(log); | ||
} | ||
} | ||
|
||
@Override | ||
public EventOutput generateEventOutput(final String environmentName) { | ||
final SseBroadcaster broadcaster = fetchBroadcaster(environmentName); | ||
final EventOutput eventOutput = new EventOutput(); | ||
broadcaster.add(eventOutput); | ||
return eventOutput; | ||
} | ||
|
||
@Override | ||
public SseBroadcaster fetchBroadcaster(final String environmentName) { | ||
final Optional<SseBroadcaster> optionalBroadcaster = | ||
Optional.ofNullable(broadcasterMap.get(environmentName)); | ||
|
||
SseBroadcaster broadcaster; | ||
|
||
if (!optionalBroadcaster.isPresent()) { | ||
broadcaster = new SseBroadcaster(); | ||
broadcasterMap.put(environmentName, broadcaster); | ||
} else { | ||
broadcaster = optionalBroadcaster.get(); | ||
} | ||
|
||
return broadcaster; | ||
} | ||
|
||
} |
Oops, something went wrong.