-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
26 changed files
with
487 additions
and
287 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
56 changes: 51 additions & 5 deletions
56
...larmsender/src/main/java/com/navercorp/pinpoint/batch/alarm/AlarmSenderConfiguration.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 |
---|---|---|
@@ -1,17 +1,63 @@ | ||
package com.navercorp.pinpoint.batch.alarm; | ||
|
||
import com.navercorp.pinpoint.batch.alarm.sender.MailSender; | ||
import com.navercorp.pinpoint.batch.alarm.sender.SpringSmtpMailSender; | ||
import com.navercorp.pinpoint.batch.alarm.sender.WebhookPayloadFactory; | ||
import com.navercorp.pinpoint.batch.alarm.sender.WebhookSender; | ||
import com.navercorp.pinpoint.batch.alarm.sender.WebhookSenderEmptyImpl; | ||
import com.navercorp.pinpoint.batch.alarm.sender.WebhookSenderImpl; | ||
import com.navercorp.pinpoint.web.service.UserGroupService; | ||
import com.navercorp.pinpoint.web.service.UserService; | ||
import com.navercorp.pinpoint.web.webhook.WebhookModule; | ||
import com.navercorp.pinpoint.web.webhook.service.WebhookService; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.boot.autoconfigure.mail.MailSenderAutoConfiguration; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.ImportResource; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.mail.javamail.JavaMailSenderImpl; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
import javax.mail.MessagingException; | ||
|
||
/** | ||
* JavaMailSenderImpl Properties | ||
* <a href="https://javaee.github.io/javamail/docs/api/com/sun/mail/smtp/package-summary.html">...</a> | ||
*/ | ||
@Configuration | ||
@ImportResource({ | ||
"classpath:applicationContext-batch-sender.xml" | ||
@Import({ | ||
AlarmSenderProperties.class, | ||
MailSenderAutoConfiguration.class | ||
}) | ||
public class AlarmSenderConfiguration { | ||
|
||
|
||
@Bean | ||
public AlarmSenderProperties alarmSenderProperties() { | ||
return new AlarmSenderProperties(); | ||
public MailSender springMailSender(AlarmSenderProperties alarmSenderProperties, | ||
UserGroupService userGroupService, | ||
JavaMailSenderImpl mailSender) throws MessagingException { | ||
return new SpringSmtpMailSender(alarmSenderProperties, userGroupService, mailSender); | ||
} | ||
|
||
|
||
@Bean | ||
@ConditionalOnProperty(name = WebhookModule.NAME, havingValue = "true", matchIfMissing = true) | ||
public WebhookSender webhookSender(AlarmSenderProperties alarmSenderProperties, | ||
UserService userService, | ||
RestTemplate restTemplate, | ||
WebhookService webhookService) { | ||
String pinpointUrl = alarmSenderProperties.getPinpointUrl(); | ||
String batchEnv = alarmSenderProperties.getBatchEnv(); | ||
|
||
WebhookPayloadFactory webhookPayloadFactory = new WebhookPayloadFactory(pinpointUrl, batchEnv); | ||
return new WebhookSenderImpl(webhookPayloadFactory, userService, restTemplate, webhookService); | ||
} | ||
|
||
@Bean("webhookSender") | ||
@ConditionalOnProperty(name = WebhookModule.NAME, havingValue = "false") | ||
public WebhookSender webhookSenderEmpty() { | ||
return new WebhookSenderEmptyImpl(); | ||
} | ||
|
||
|
||
} |
41 changes: 22 additions & 19 deletions
41
...h-alarmsender/src/main/java/com/navercorp/pinpoint/batch/alarm/AlarmSenderProperties.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 |
---|---|---|
@@ -1,51 +1,54 @@ | ||
package com.navercorp.pinpoint.batch.alarm; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.mail.MailParseException; | ||
|
||
import javax.mail.internet.AddressException; | ||
import javax.mail.internet.InternetAddress; | ||
import java.util.Objects; | ||
|
||
public class AlarmSenderProperties { | ||
@Value("${webhook.enable}") | ||
private boolean webhookEnable; | ||
|
||
@Value("${alarm.mail.server.url}") | ||
private String emailServerUrl; | ||
private final InternetAddress senderEmailAddress; | ||
|
||
@Value("${alarm.mail.sender.address}") | ||
private String senderEmailAddress; | ||
private final String pinpointUrl; | ||
|
||
@Value("${pinpoint.url}") | ||
private String pinpointUrl; | ||
private final String batchEnv; | ||
|
||
@Value("${batch.server.env}") | ||
private String batchEnv; | ||
public AlarmSenderProperties(@Value("${spring.mail.properties.mail.smtp.from}") String senderEmailAddress, | ||
@Value("${pinpoint.url}") String pinpointUrl, | ||
@Value("${batch.server.env}") String batchEnv) { | ||
Objects.requireNonNull(senderEmailAddress, "senderEmailAddress"); | ||
try { | ||
this.senderEmailAddress = new InternetAddress(senderEmailAddress); | ||
} catch (AddressException e) { | ||
throw new MailParseException(e); | ||
} | ||
|
||
public boolean isWebhookEnable() { | ||
return webhookEnable; | ||
this.pinpointUrl = Objects.requireNonNull(pinpointUrl, "pinpointUrl"); | ||
this.batchEnv = Objects.requireNonNull(batchEnv, "batchEnv"); | ||
} | ||
|
||
public String getPinpointUrl() { | ||
return pinpointUrl; | ||
} | ||
|
||
public String getEmailServerUrl() { | ||
return emailServerUrl; | ||
} | ||
|
||
public String getSenderEmailAddress() { | ||
public InternetAddress getSenderEmailAddress() { | ||
return senderEmailAddress; | ||
} | ||
|
||
|
||
public String getBatchEnv() { | ||
return batchEnv; | ||
} | ||
|
||
|
||
@Override | ||
public String toString() { | ||
return "AlarmSenderProperties{" + | ||
"emailServerUrl='" + emailServerUrl + '\'' + | ||
", batchEnv='" + batchEnv + '\'' + | ||
", senderEmailAddress='" + senderEmailAddress + '\'' + | ||
", pinpointUrl='" + pinpointUrl + '\'' + | ||
", webhookEnable=" + webhookEnable + | ||
'}'; | ||
} | ||
} |
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
48 changes: 0 additions & 48 deletions
48
...der/src/main/java/com/navercorp/pinpoint/batch/alarm/sender/WebhookSenderFactoryBean.java
This file was deleted.
Oops, something went wrong.
38 changes: 0 additions & 38 deletions
38
batch-alarmsender/src/main/resources/applicationContext-batch-sender.xml
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.