Search in sources :

Example 1 with AlertReceiverFacade

use of io.hops.hopsworks.alert.dao.AlertReceiverFacade in project hopsworks by logicalclocks.

the class TestAlertManagerConfigTimer method setUp.

@Before
public void setUp() throws ServiceDiscoveryException, AlertManagerConfigFileNotFoundException, AlertManagerConfigReadException, JsonProcessingException {
    String alertmanagerConfigPath = TestAlertManagerConfigTimer.class.getResource("/alertmanager.yml").getPath();
    alertManagerConfigDBPath = TestAlertManagerConfigTimer.class.getResource("/alertmanagerDB.yml").getPath();
    client = Mockito.mock(AlertManagerClient.class);
    alertManagerConfigController = new AlertManagerConfigController.Builder().withConfigPath(alertmanagerConfigPath).withClient(client).build();
    alertManagerConfigFacade = Mockito.mock(AlertManagerConfigFacade.class);
    Mockito.doAnswer((Answer<Void>) invocation -> {
        Object[] args = invocation.getArguments();
        LOGGER.log(Level.INFO, "Save to database: {0}.", args);
        return null;
    }).when(alertManagerConfigFacade).save(Mockito.any());
    Mockito.doAnswer((Answer<Void>) invocation -> {
        Object[] args = invocation.getArguments();
        LOGGER.log(Level.INFO, "Update database: {0}.", args);
        return null;
    }).when(alertManagerConfigFacade).update(Mockito.any());
    AlertManagerConfig alertManagerConfig = read(new File(alertManagerConfigDBPath));
    AlertManagerConfigEntity alertManagerConfigEntity = new AlertManagerConfigEntity();
    alertManagerConfigEntity.setId(1);
    alertManagerConfigEntity.setCreated(new Date());
    alertManagerConfigEntity.setContent(toJson(alertManagerConfig));
    Mockito.when(alertManagerConfigFacade.getLatest()).thenReturn(Optional.of(alertManagerConfigEntity));
    alertReceiverFacade = Mockito.mock(AlertReceiverFacade.class);
    List<AlertReceiver> receivers = createReceivers();
    Mockito.when(alertReceiverFacade.findAll()).thenReturn(receivers);
    Mockito.doAnswer((Answer<Optional<AlertReceiver>>) invocation -> {
        Object[] args = invocation.getArguments();
        Optional<AlertReceiver> alertReceiver = receivers.stream().filter(receiver -> receiver.getName().equals(args[0])).findFirst();
        return alertReceiver;
    }).when(alertReceiverFacade).findByName(Mockito.any());
    alertManagerConfiguration = new AlertManagerConfiguration(client, alertManagerConfigController, alertManagerConfigFacade, alertReceiverFacade);
    alertManagerConfigBackup = alertManagerConfigController.read();
    alertManagerConfigBackupDB = read(new File(alertManagerConfigDBPath));
}
Also used : YAMLGenerator(com.fasterxml.jackson.dataformat.yaml.YAMLGenerator) AlertType(io.hops.hopsworks.persistence.entity.alertmanager.AlertType) FeatureGroupAlert(io.hops.hopsworks.persistence.entity.featurestore.featuregroup.datavalidation.alert.FeatureGroupAlert) Date(java.util.Date) Random(java.util.Random) AlertSeverity(io.hops.hopsworks.persistence.entity.alertmanager.AlertSeverity) AlertManagerConfigController(io.hops.hopsworks.alerting.config.AlertManagerConfigController) AlertManagerClient(io.hops.hopsworks.alerting.api.AlertManagerClient) JSONObject(org.json.JSONObject) AlertManagerConfiguration(io.hops.hopsworks.alert.AlertManagerConfiguration) After(org.junit.After) JobAlert(io.hops.hopsworks.persistence.entity.jobs.description.JobAlert) AlertManagerConfigFacade(io.hops.hopsworks.alert.dao.AlertManagerConfigFacade) AlertManagerUnreachableException(io.hops.hopsworks.alert.exception.AlertManagerUnreachableException) ValidationRuleAlertStatus(io.hops.hopsworks.persistence.entity.featurestore.featuregroup.datavalidation.alert.ValidationRuleAlertStatus) SlackConfig(io.hops.hopsworks.alerting.config.dto.SlackConfig) AlertManagerConfigReadException(io.hops.hopsworks.alerting.exceptions.AlertManagerConfigReadException) Jobs(io.hops.hopsworks.persistence.entity.jobs.description.Jobs) Featuregroup(io.hops.hopsworks.persistence.entity.featurestore.featuregroup.Featuregroup) Logger(java.util.logging.Logger) ServiceDiscoveryException(com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException) ProjectServiceAlert(io.hops.hopsworks.persistence.entity.project.alert.ProjectServiceAlert) List(java.util.List) AlertManagerConfigCtrlCreateException(io.hops.hopsworks.alerting.exceptions.AlertManagerConfigCtrlCreateException) JobAlertStatus(io.hops.hopsworks.persistence.entity.jobs.description.JobAlertStatus) Optional(java.util.Optional) AlertReceiver(io.hops.hopsworks.persistence.entity.alertmanager.AlertReceiver) EmailConfig(io.hops.hopsworks.alerting.config.dto.EmailConfig) ProjectServiceEnum(io.hops.hopsworks.persistence.entity.project.service.ProjectServiceEnum) Receiver(io.hops.hopsworks.alerting.config.dto.Receiver) Project(io.hops.hopsworks.persistence.entity.project.Project) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) Answer(org.mockito.stubbing.Answer) AlertManagerConfigFileNotFoundException(io.hops.hopsworks.alerting.exceptions.AlertManagerConfigFileNotFoundException) YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) AlertManagerConfigUpdateException(io.hops.hopsworks.alerting.exceptions.AlertManagerConfigUpdateException) PagerdutyConfig(io.hops.hopsworks.alerting.config.dto.PagerdutyConfig) Before(org.junit.Before) AlertManagerConfigEntity(io.hops.hopsworks.persistence.entity.alertmanager.AlertManagerConfigEntity) AlertManagerConfig(io.hops.hopsworks.alerting.config.dto.AlertManagerConfig) AlertManagerClientCreateException(io.hops.hopsworks.alerting.exceptions.AlertManagerClientCreateException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test) IOException(java.io.IOException) Featurestore(io.hops.hopsworks.persistence.entity.featurestore.Featurestore) ProjectServiceAlertStatus(io.hops.hopsworks.persistence.entity.project.alert.ProjectServiceAlertStatus) File(java.io.File) Mockito(org.mockito.Mockito) AlertReceiverFacade(io.hops.hopsworks.alert.dao.AlertReceiverFacade) JsonInclude(com.fasterxml.jackson.annotation.JsonInclude) AlertManagerConfig(io.hops.hopsworks.alerting.config.dto.AlertManagerConfig) Optional(java.util.Optional) AlertReceiver(io.hops.hopsworks.persistence.entity.alertmanager.AlertReceiver) AlertManagerConfigFacade(io.hops.hopsworks.alert.dao.AlertManagerConfigFacade) Date(java.util.Date) AlertManagerClient(io.hops.hopsworks.alerting.api.AlertManagerClient) AlertReceiverFacade(io.hops.hopsworks.alert.dao.AlertReceiverFacade) File(java.io.File) AlertManagerConfigEntity(io.hops.hopsworks.persistence.entity.alertmanager.AlertManagerConfigEntity) AlertManagerConfiguration(io.hops.hopsworks.alert.AlertManagerConfiguration) Before(org.junit.Before)

Aggregations

JsonInclude (com.fasterxml.jackson.annotation.JsonInclude)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)1 YAMLGenerator (com.fasterxml.jackson.dataformat.yaml.YAMLGenerator)1 ServiceDiscoveryException (com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException)1 AlertManagerConfiguration (io.hops.hopsworks.alert.AlertManagerConfiguration)1 AlertManagerConfigFacade (io.hops.hopsworks.alert.dao.AlertManagerConfigFacade)1 AlertReceiverFacade (io.hops.hopsworks.alert.dao.AlertReceiverFacade)1 AlertManagerUnreachableException (io.hops.hopsworks.alert.exception.AlertManagerUnreachableException)1 AlertManagerClient (io.hops.hopsworks.alerting.api.AlertManagerClient)1 AlertManagerConfigController (io.hops.hopsworks.alerting.config.AlertManagerConfigController)1 AlertManagerConfig (io.hops.hopsworks.alerting.config.dto.AlertManagerConfig)1 EmailConfig (io.hops.hopsworks.alerting.config.dto.EmailConfig)1 PagerdutyConfig (io.hops.hopsworks.alerting.config.dto.PagerdutyConfig)1 Receiver (io.hops.hopsworks.alerting.config.dto.Receiver)1 SlackConfig (io.hops.hopsworks.alerting.config.dto.SlackConfig)1 AlertManagerClientCreateException (io.hops.hopsworks.alerting.exceptions.AlertManagerClientCreateException)1 AlertManagerConfigCtrlCreateException (io.hops.hopsworks.alerting.exceptions.AlertManagerConfigCtrlCreateException)1 AlertManagerConfigFileNotFoundException (io.hops.hopsworks.alerting.exceptions.AlertManagerConfigFileNotFoundException)1