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();
}
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;
}
Aggregations