Search in sources :

Example 1 with AlertManagerConfigFacade

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

the class TestAlertManagerConfigTimer method testRestoreBackup.

@Test
public void testRestoreBackup() throws AlertManagerUnreachableException, AlertManagerConfigCtrlCreateException, AlertManagerConfigUpdateException, IOException, AlertManagerConfigReadException, AlertManagerClientCreateException {
    Mockito.doAnswer((Answer<Void>) invocation -> {
        Object[] args = invocation.getArguments();
        if (args != null && args.length > 0 && args[0] != null) {
            AlertManagerConfigEntity alertManagerConfigEntity = (AlertManagerConfigEntity) args[0];
            AlertManagerConfig alertManagerConfig = fromJson(alertManagerConfigEntity.getContent());
            LOGGER.log(Level.INFO, "Update database routes={0}, receivers={1}.", new Object[] { alertManagerConfig.getRoute().getRoutes().size(), alertManagerConfig.getReceivers().size() });
            assert alertManagerConfig.getRoute().getRoutes().size() == 15;
            assert alertManagerConfig.getReceivers().size() == 9;
        }
        return null;
    }).when(alertManagerConfigFacade).update(Mockito.any());
    alertManagerConfiguration.restoreFromBackup();
    AlertManagerConfig alertManagerConfig = alertManagerConfigController.read();
    assert alertManagerConfig.getRoute().getRoutes().size() == 15;
    assert alertManagerConfig.getReceivers().size() == 9;
}
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) JSONObject(org.json.JSONObject) AlertManagerConfigEntity(io.hops.hopsworks.persistence.entity.alertmanager.AlertManagerConfigEntity) Test(org.junit.Test)

Example 2 with AlertManagerConfigFacade

use of io.hops.hopsworks.alert.dao.AlertManagerConfigFacade 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)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)2 YAMLGenerator (com.fasterxml.jackson.dataformat.yaml.YAMLGenerator)2 ServiceDiscoveryException (com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException)2 AlertManagerConfiguration (io.hops.hopsworks.alert.AlertManagerConfiguration)2 AlertManagerConfigFacade (io.hops.hopsworks.alert.dao.AlertManagerConfigFacade)2 AlertReceiverFacade (io.hops.hopsworks.alert.dao.AlertReceiverFacade)2 AlertManagerUnreachableException (io.hops.hopsworks.alert.exception.AlertManagerUnreachableException)2 AlertManagerClient (io.hops.hopsworks.alerting.api.AlertManagerClient)2 AlertManagerConfigController (io.hops.hopsworks.alerting.config.AlertManagerConfigController)2 AlertManagerConfig (io.hops.hopsworks.alerting.config.dto.AlertManagerConfig)2 EmailConfig (io.hops.hopsworks.alerting.config.dto.EmailConfig)2 PagerdutyConfig (io.hops.hopsworks.alerting.config.dto.PagerdutyConfig)2 Receiver (io.hops.hopsworks.alerting.config.dto.Receiver)2 SlackConfig (io.hops.hopsworks.alerting.config.dto.SlackConfig)2 AlertManagerClientCreateException (io.hops.hopsworks.alerting.exceptions.AlertManagerClientCreateException)2 AlertManagerConfigCtrlCreateException (io.hops.hopsworks.alerting.exceptions.AlertManagerConfigCtrlCreateException)2 AlertManagerConfigFileNotFoundException (io.hops.hopsworks.alerting.exceptions.AlertManagerConfigFileNotFoundException)2