Search in sources :

Example 1 with InhibitRule

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

the class ManagementResource method updateInhibitRules.

@PUT
@Path("inhibit")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN" })
public Response updateInhibitRules(PostableInhibitRulesDTOList postableInhibitRulesDTOList, @Context SecurityContext sc) throws AlertException {
    List<InhibitRule> inhibitRules = toInhibitRules(postableInhibitRulesDTOList);
    InhibitRulesDTO dto = new InhibitRulesDTO();
    try {
        alertManagerConfiguration.updateInhibitRules(inhibitRules);
        List<InhibitRule> i = alertManagerConfiguration.getInhibitRules();
        dto.setInhibitRules(i);
    } catch (AlertManagerConfigCtrlCreateException | AlertManagerUnreachableException | AlertManagerConfigReadException e) {
        throw new AlertException(RESTCodes.AlertErrorCode.FAILED_TO_READ_CONFIGURATION, 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 (IllegalArgumentException e) {
        throw new AlertException(RESTCodes.AlertErrorCode.ILLEGAL_ARGUMENT, Level.FINE, e.getMessage());
    }
    return Response.ok().entity(dto).build();
}
Also used : InhibitRule(io.hops.hopsworks.alerting.config.dto.InhibitRule) AlertManagerUnreachableException(io.hops.hopsworks.alert.exception.AlertManagerUnreachableException) AlertManagerConfigCtrlCreateException(io.hops.hopsworks.alerting.exceptions.AlertManagerConfigCtrlCreateException) AlertManagerConfigUpdateException(io.hops.hopsworks.alerting.exceptions.AlertManagerConfigUpdateException) AlertManagerConfigReadException(io.hops.hopsworks.alerting.exceptions.AlertManagerConfigReadException) AlertException(io.hops.hopsworks.exceptions.AlertException) AlertManagerClientCreateException(io.hops.hopsworks.alerting.exceptions.AlertManagerClientCreateException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) PUT(javax.ws.rs.PUT)

Example 2 with InhibitRule

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

the class ManagementResource method toInhibitRule.

private InhibitRule toInhibitRule(PostableInhibitRulesDTO p) {
    InhibitRule inhibitRule = new InhibitRule();
    inhibitRule.setEqual(p.getEqual());
    if (p.getSourceMatch() != null && !p.getSourceMatch().isEmpty()) {
        inhibitRule.setSourceMatch(p.getSourceMatch().stream().filter(entry -> entry != null && entry.getKey() != null && entry.getValue() != null).collect(Collectors.toMap(Entry::getKey, Entry::getValue)));
    }
    if (p.getSourceMatchRe() != null && !p.getSourceMatchRe().isEmpty()) {
        inhibitRule.setSourceMatchRe(p.getSourceMatchRe().stream().filter(entry -> entry != null && entry.getKey() != null && entry.getValue() != null).collect(Collectors.toMap(Entry::getKey, Entry::getValue)));
    }
    if (p.getTargetMatch() != null && !p.getTargetMatch().isEmpty()) {
        inhibitRule.setTargetMatch(p.getTargetMatch().stream().filter(entry -> entry != null && entry.getKey() != null && entry.getValue() != null).collect(Collectors.toMap(Entry::getKey, Entry::getValue)));
    }
    if (p.getTargetMatchRe() != null && !p.getTargetMatchRe().isEmpty()) {
        inhibitRule.setTargetMatchRe(p.getTargetMatchRe().stream().filter(entry -> entry != null && entry.getKey() != null && entry.getValue() != null).collect(Collectors.toMap(Entry::getKey, Entry::getValue)));
    }
    return inhibitRule;
}
Also used : Entry(io.hops.hopsworks.api.alert.Entry) InhibitRule(io.hops.hopsworks.alerting.config.dto.InhibitRule)

Aggregations

InhibitRule (io.hops.hopsworks.alerting.config.dto.InhibitRule)2 AlertManagerUnreachableException (io.hops.hopsworks.alert.exception.AlertManagerUnreachableException)1 AlertManagerClientCreateException (io.hops.hopsworks.alerting.exceptions.AlertManagerClientCreateException)1 AlertManagerConfigCtrlCreateException (io.hops.hopsworks.alerting.exceptions.AlertManagerConfigCtrlCreateException)1 AlertManagerConfigReadException (io.hops.hopsworks.alerting.exceptions.AlertManagerConfigReadException)1 AlertManagerConfigUpdateException (io.hops.hopsworks.alerting.exceptions.AlertManagerConfigUpdateException)1 Entry (io.hops.hopsworks.api.alert.Entry)1 AlertException (io.hops.hopsworks.exceptions.AlertException)1 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)1 Consumes (javax.ws.rs.Consumes)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1