Search in sources :

Example 26 with Receiver

use of io.hops.hopsworks.alerting.config.dto.Receiver in project hopsworks by logicalclocks.

the class TestAlertManagerConfigController method testRemoveReceiver.

@Test
public void testRemoveReceiver() throws AlertManagerConfigReadException, AlertManagerConfigUpdateException, AlertManagerResponseException, AlertManagerServerException {
    Mockito.when(client.reload()).thenReturn(Response.ok().build());
    Receiver receiver = new Receiver("team-Y-mails");
    AlertManagerConfig alertManagerConfig = this.alertManagerConfigController.read();
    assert alertManagerConfig.getReceivers().contains(receiver);
    AlertManagerConfig config = alertManagerConfigController.removeReceiver("team-Y-mails", true);
    alertManagerConfigController.writeAndReload(config);
    alertManagerConfig = this.alertManagerConfigController.read();
    assert !alertManagerConfig.getReceivers().contains(receiver);
}
Also used : AlertManagerConfig(io.hops.hopsworks.alerting.config.dto.AlertManagerConfig) Receiver(io.hops.hopsworks.alerting.config.dto.Receiver) Test(org.junit.Test)

Example 27 with Receiver

use of io.hops.hopsworks.alerting.config.dto.Receiver in project hopsworks by logicalclocks.

the class AlertManagerConfigController method addEmailToReceiver.

/**
 * @param name
 * @param emailConfig
 * @return updated AlertManagerConfig
 * @throws IOException
 * @throws AlertManagerNoSuchElementException
 * @throws AlertManagerDuplicateEntryException
 * @throws AlertManagerConfigUpdateException
 * @throws IllegalArgumentException if emailConfig is missing to
 */
public AlertManagerConfig addEmailToReceiver(String name, EmailConfig emailConfig) throws AlertManagerNoSuchElementException, AlertManagerDuplicateEntryException, AlertManagerConfigReadException {
    validate(emailConfig);
    AlertManagerConfig alertManagerConfig = read();
    int index = getIndexOfReceiver(alertManagerConfig, name);
    Receiver receiverToUpdate = alertManagerConfig.getReceivers().get(index);
    if (receiverToUpdate.getEmailConfigs() == null) {
        receiverToUpdate.setEmailConfigs(new ArrayList<>());
    }
    if (receiverToUpdate.getEmailConfigs().contains(emailConfig)) {
        throw new AlertManagerDuplicateEntryException("A receiver with the same email already exists.");
    }
    receiverToUpdate.getEmailConfigs().add(emailConfig);
    return alertManagerConfig;
}
Also used : AlertManagerConfig(io.hops.hopsworks.alerting.config.dto.AlertManagerConfig) AlertManagerDuplicateEntryException(io.hops.hopsworks.alerting.exceptions.AlertManagerDuplicateEntryException) Receiver(io.hops.hopsworks.alerting.config.dto.Receiver)

Example 28 with Receiver

use of io.hops.hopsworks.alerting.config.dto.Receiver in project hopsworks by logicalclocks.

the class AlertManagerConfigController method addSlackToReceiver.

/**
 * @param name
 * @param slackConfig
 * @return updated AlertManagerConfig
 * @throws IOException
 * @throws AlertManagerNoSuchElementException
 * @throws AlertManagerDuplicateEntryException
 * @throws AlertManagerConfigUpdateException
 * @throws IllegalArgumentException if slackConfig is missing apiUrl or channel
 */
public AlertManagerConfig addSlackToReceiver(String name, SlackConfig slackConfig) throws AlertManagerNoSuchElementException, AlertManagerDuplicateEntryException, AlertManagerConfigReadException {
    validate(slackConfig);
    AlertManagerConfig alertManagerConfig = read();
    int index = getIndexOfReceiver(alertManagerConfig, name);
    Receiver receiverToUpdate = alertManagerConfig.getReceivers().get(index);
    if (receiverToUpdate.getSlackConfigs() == null) {
        receiverToUpdate.setSlackConfigs(new ArrayList<>());
    }
    if (receiverToUpdate.getSlackConfigs().contains(slackConfig)) {
        throw new AlertManagerDuplicateEntryException("A receiver with the same api url and channel already exists.");
    }
    receiverToUpdate.getSlackConfigs().add(slackConfig);
    return alertManagerConfig;
}
Also used : AlertManagerConfig(io.hops.hopsworks.alerting.config.dto.AlertManagerConfig) AlertManagerDuplicateEntryException(io.hops.hopsworks.alerting.exceptions.AlertManagerDuplicateEntryException) Receiver(io.hops.hopsworks.alerting.config.dto.Receiver)

Example 29 with Receiver

use of io.hops.hopsworks.alerting.config.dto.Receiver in project hopsworks by logicalclocks.

the class AlertManagerConfigController method removeSlackFromReceiver.

/**
 * @param name
 * @param slackConfig
 * @return updated AlertManagerConfig or null if it was not updated
 * @throws AlertManagerNoSuchElementException
 * @throws AlertManagerServerException
 * @throws AlertManagerConfigReadException
 */
public AlertManagerConfig removeSlackFromReceiver(String name, SlackConfig slackConfig) throws AlertManagerNoSuchElementException, AlertManagerConfigReadException {
    AlertManagerConfig alertManagerConfig = read();
    int index = getIndexOfReceiver(alertManagerConfig, name);
    Receiver receiverToUpdate = alertManagerConfig.getReceivers().get(index);
    index = receiverToUpdate.getSlackConfigs() == null ? -1 : receiverToUpdate.getSlackConfigs().indexOf(slackConfig);
    if (index > -1) {
        receiverToUpdate.getSlackConfigs().remove(index);
        return alertManagerConfig;
    }
    return null;
}
Also used : AlertManagerConfig(io.hops.hopsworks.alerting.config.dto.AlertManagerConfig) Receiver(io.hops.hopsworks.alerting.config.dto.Receiver)

Example 30 with Receiver

use of io.hops.hopsworks.alerting.config.dto.Receiver in project hopsworks by logicalclocks.

the class ReceiverResource method update.

@PUT
@Path("{name}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update a receiver.", response = SilenceDTO.class)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER", "HOPS_SERVICE_USER" })
public Response update(@PathParam("name") String name, @QueryParam("defaultTemplate") @DefaultValue("false") Boolean defaultTemplate, PostableReceiverDTO postableReceiverDTO, @Context UriInfo uriInfo, @Context HttpServletRequest req, @Context SecurityContext sc) throws AlertException, ProjectException {
    if (postableReceiverDTO == null) {
        throw new AlertException(RESTCodes.AlertErrorCode.ILLEGAL_ARGUMENT, Level.FINE, "No payload.");
    }
    Receiver receiver = receiverBuilder.build(postableReceiverDTO, defaultTemplate, true);
    validateReceiverOneConfig(receiver);
    try {
        alertManagerConfiguration.updateReceiver(name, receiver, getProject());
    } catch (AlertManagerConfigCtrlCreateException | AlertManagerUnreachableException | AlertManagerConfigReadException e) {
        throw new AlertException(RESTCodes.AlertErrorCode.FAILED_TO_READ_CONFIGURATION, Level.FINE, e.getMessage());
    } catch (AlertManagerDuplicateEntryException e) {
        throw new AlertException(RESTCodes.AlertErrorCode.RECEIVER_EXIST, Level.FINE, e.getMessage());
    } catch (AlertManagerConfigUpdateException e) {
        throw new AlertException(RESTCodes.AlertErrorCode.FAILED_TO_UPDATE_AM_CONFIG, Level.FINE, e.getMessage());
    } catch (AlertManagerClientCreateException e) {
        throw new AlertException(RESTCodes.AlertErrorCode.FAILED_TO_CONNECT, Level.FINE, e.getMessage());
    } catch (AlertManagerNoSuchElementException e) {
        throw new AlertException(RESTCodes.AlertErrorCode.RECEIVER_NOT_FOUND, Level.FINE, e.getMessage());
    } catch (AlertManagerAccessControlException e) {
        throw new AlertException(RESTCodes.AlertErrorCode.ACCESS_CONTROL_EXCEPTION, Level.FINE, e.getMessage());
    } catch (IllegalArgumentException e) {
        throw new AlertException(RESTCodes.AlertErrorCode.ILLEGAL_ARGUMENT, Level.FINE, e.getMessage());
    }
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.RECEIVERS);
    ReceiverDTO dto = receiverBuilder.build(uriInfo, resourceRequest, receiver.getName(), getProject());
    return Response.ok().entity(dto).build();
}
Also used : AlertManagerUnreachableException(io.hops.hopsworks.alert.exception.AlertManagerUnreachableException) AlertManagerAccessControlException(io.hops.hopsworks.alert.exception.AlertManagerAccessControlException) Receiver(io.hops.hopsworks.alerting.config.dto.Receiver) AlertManagerConfigUpdateException(io.hops.hopsworks.alerting.exceptions.AlertManagerConfigUpdateException) AlertManagerClientCreateException(io.hops.hopsworks.alerting.exceptions.AlertManagerClientCreateException) AlertManagerDuplicateEntryException(io.hops.hopsworks.alerting.exceptions.AlertManagerDuplicateEntryException) AlertManagerNoSuchElementException(io.hops.hopsworks.alerting.exceptions.AlertManagerNoSuchElementException) AlertManagerConfigCtrlCreateException(io.hops.hopsworks.alerting.exceptions.AlertManagerConfigCtrlCreateException) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) AlertManagerConfigReadException(io.hops.hopsworks.alerting.exceptions.AlertManagerConfigReadException) AlertException(io.hops.hopsworks.exceptions.AlertException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles) PUT(javax.ws.rs.PUT)

Aggregations

Receiver (io.hops.hopsworks.alerting.config.dto.Receiver)34 AlertManagerConfig (io.hops.hopsworks.alerting.config.dto.AlertManagerConfig)21 Test (org.junit.Test)16 ArrayList (java.util.ArrayList)13 EmailConfig (io.hops.hopsworks.alerting.config.dto.EmailConfig)11 AlertManagerDuplicateEntryException (io.hops.hopsworks.alerting.exceptions.AlertManagerDuplicateEntryException)9 AlertManagerUnreachableException (io.hops.hopsworks.alert.exception.AlertManagerUnreachableException)7 AlertManagerClientCreateException (io.hops.hopsworks.alerting.exceptions.AlertManagerClientCreateException)7 AlertManagerConfigCtrlCreateException (io.hops.hopsworks.alerting.exceptions.AlertManagerConfigCtrlCreateException)7 AlertManagerConfigReadException (io.hops.hopsworks.alerting.exceptions.AlertManagerConfigReadException)7 AlertManagerConfigUpdateException (io.hops.hopsworks.alerting.exceptions.AlertManagerConfigUpdateException)7 ResourceRequest (io.hops.hopsworks.common.api.ResourceRequest)6 AlertException (io.hops.hopsworks.exceptions.AlertException)6 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)6 ApiOperation (io.swagger.annotations.ApiOperation)6 Consumes (javax.ws.rs.Consumes)6 Produces (javax.ws.rs.Produces)6 SlackConfig (io.hops.hopsworks.alerting.config.dto.SlackConfig)5 AlertManagerNoSuchElementException (io.hops.hopsworks.alerting.exceptions.AlertManagerNoSuchElementException)5 PagerdutyConfig (io.hops.hopsworks.alerting.config.dto.PagerdutyConfig)4