Search in sources :

Example 1 with AlertCriteria

use of com.thinkbiganalytics.alerts.api.AlertCriteria in project kylo by Teradata.

the class DefaultAlertManager method getAlerts.

/* (non-Javadoc)
     * @see com.thinkbiganalytics.alerts.spi.AlertSource#getAlerts()
     */
@Override
public Iterator<Alert> getAlerts(AlertCriteria criteria) {
    Long now = DateTime.now().getMillis();
    Principal[] principal = null;
    if (criteria != null && criteria.isAsServiceAccount()) {
        principal = new Principal[1];
        principal[0] = MetadataAccess.SERVICE;
    } else {
        principal = new Principal[0];
    }
    if (criteria.isOnlyIfChangesDetected() && !hasAlertsChanged(criteria)) {
        log.debug("Returning cached Alerts data");
        return new ArrayList(latestAlerts.get(criteria.toString()).getAlertList()).iterator();
    }
    log.debug("Query for Alerts data");
    List<Alert> alerts = this.metadataAccess.read(() -> {
        DefaultAlertCriteria critImpl = ensureAlertCriteriaType(criteria);
        return critImpl.createQuery().fetch().stream().map(a -> asValue(a)).collect(Collectors.toList());
    }, principal);
    if (criteria.isOnlyIfChangesDetected()) {
        latestAlerts.put(criteria.toString(), new AlertsCache(now, alerts));
    }
    return alerts.iterator();
}
Also used : AlertManager(com.thinkbiganalytics.alerts.spi.AlertManager) ClusterServiceMessageReceiver(com.thinkbiganalytics.cluster.ClusterServiceMessageReceiver) ServiceStatusAlerts(com.thinkbiganalytics.alerts.service.ServiceStatusAlerts) LoggerFactory(org.slf4j.LoggerFactory) AlertSource(com.thinkbiganalytics.alerts.spi.AlertSource) QueryDslRepositorySupport(org.springframework.data.jpa.repository.support.QueryDslRepositorySupport) AlertChangeEvent(com.thinkbiganalytics.alerts.api.AlertChangeEvent) ArrayList(java.util.ArrayList) AlertSummary(com.thinkbiganalytics.alerts.api.AlertSummary) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Alert(com.thinkbiganalytics.alerts.api.Alert) SecurityRole(com.thinkbiganalytics.security.role.SecurityRole) Map(java.util.Map) State(com.thinkbiganalytics.alerts.api.Alert.State) URI(java.net.URI) MetadataAccess(com.thinkbiganalytics.metadata.api.MetadataAccess) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) AlertId(com.thinkbiganalytics.metadata.jpa.alerts.JpaAlert.AlertId) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) AlertNotifyReceiver(com.thinkbiganalytics.alerts.spi.AlertNotifyReceiver) EntityIdentificationAlertContent(com.thinkbiganalytics.alerts.spi.EntityIdentificationAlertContent) JpaAlert(com.thinkbiganalytics.metadata.jpa.alerts.JpaAlert) Level(com.thinkbiganalytics.alerts.api.Alert.Level) JpaAlertChangeEvent(com.thinkbiganalytics.metadata.jpa.alerts.JpaAlertChangeEvent) DateTime(org.joda.time.DateTime) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) ClusterMessage(com.thinkbiganalytics.cluster.ClusterMessage) JPAQueryFactory(com.querydsl.jpa.impl.JPAQueryFactory) OperationalAlerts(com.thinkbiganalytics.metadata.api.alerts.OperationalAlerts) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Serializable(java.io.Serializable) List(java.util.List) Principal(java.security.Principal) AlertNotfoundException(com.thinkbiganalytics.alerts.api.AlertNotfoundException) JpaAlertRepository(com.thinkbiganalytics.metadata.jpa.alerts.JpaAlertRepository) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) ClusterService(com.thinkbiganalytics.cluster.ClusterService) AssessmentAlerts(com.thinkbiganalytics.alerts.sla.AssessmentAlerts) AlertDescriptor(com.thinkbiganalytics.alerts.spi.AlertDescriptor) Collections(java.util.Collections) AlertCriteria(com.thinkbiganalytics.alerts.api.AlertCriteria) AlertResponse(com.thinkbiganalytics.alerts.api.AlertResponse) ArrayList(java.util.ArrayList) Alert(com.thinkbiganalytics.alerts.api.Alert) JpaAlert(com.thinkbiganalytics.metadata.jpa.alerts.JpaAlert) Principal(java.security.Principal)

Example 2 with AlertCriteria

use of com.thinkbiganalytics.alerts.api.AlertCriteria in project kylo by Teradata.

the class KyloEntityAwareAlertCriteria method transfer.

@Override
public AlertCriteria transfer(AlertCriteria criteria) {
    AlertCriteria c = super.transfer(criteria);
    AtomicReference<KyloEntityAwareAlertCriteria> updated = new AtomicReference<>((KyloEntityAwareAlertCriteria) c);
    this.entityCriteria.forEach((t) -> updated.set(updated.get().entityCriteria(t)));
    return updated.get();
}
Also used : EntityAwareAlertCriteria(com.thinkbiganalytics.alerts.api.EntityAwareAlertCriteria) AlertCriteria(com.thinkbiganalytics.alerts.api.AlertCriteria) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Example 3 with AlertCriteria

use of com.thinkbiganalytics.alerts.api.AlertCriteria in project kylo by Teradata.

the class AlertsController method createCriteria.

private AlertCriteria createCriteria(UriInfo uriInfo) {
    // Query params: limit, state, level, before-time, after-time, before-alert, after-alert
    MultivaluedMap<String, String> params = uriInfo.getQueryParameters();
    AlertCriteria criteria = provider.criteria();
    try {
        Optional.ofNullable(params.get("type")).ifPresent(list -> list.forEach(typeStr -> criteria.type(URI.create(typeStr))));
        Optional.ofNullable(params.get("subtype")).ifPresent(list -> list.forEach(subtype -> criteria.subtype(subtype)));
        Optional.ofNullable(params.get("limit")).ifPresent(list -> list.forEach(limitStr -> criteria.limit(Integer.parseInt(limitStr))));
        Optional.ofNullable(params.get("state")).ifPresent(list -> list.forEach(stateStr -> criteria.state(Alert.State.valueOf(stateStr.toUpperCase()))));
        Optional.ofNullable(params.get("level")).ifPresent(list -> list.forEach(levelStr -> criteria.level(Alert.Level.valueOf(levelStr.toUpperCase()))));
        Optional.ofNullable(params.get("before")).ifPresent(list -> list.forEach(timeStr -> criteria.before(Formatters.parseDateTime(timeStr))));
        Optional.ofNullable(params.get("after")).ifPresent(list -> list.forEach(timeStr -> criteria.after(Formatters.parseDateTime(timeStr))));
        return criteria;
    } catch (IllegalArgumentException e) {
        throw new WebApplicationException("Invalid query parameter: " + e.getMessage(), Status.BAD_REQUEST);
    }
}
Also used : AlertCriteria(com.thinkbiganalytics.alerts.api.AlertCriteria) AlertManager(com.thinkbiganalytics.alerts.spi.AlertManager) PathParam(javax.ws.rs.PathParam) AlertResponder(com.thinkbiganalytics.alerts.api.AlertResponder) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) AggregatingAlertProvider(com.thinkbiganalytics.alerts.api.core.AggregatingAlertProvider) Path(javax.ws.rs.Path) ApiResponses(io.swagger.annotations.ApiResponses) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) AlertSummary(com.thinkbiganalytics.alerts.api.AlertSummary) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(javax.ws.rs.core.MediaType) AlertProvider(com.thinkbiganalytics.alerts.api.AlertProvider) QueryParam(javax.ws.rs.QueryParam) AlertCreateRequest(com.thinkbiganalytics.alerts.rest.model.AlertCreateRequest) RestResponseStatus(com.thinkbiganalytics.rest.model.RestResponseStatus) Consumes(javax.ws.rs.Consumes) Alert(com.thinkbiganalytics.alerts.api.Alert) AlertUpdateRequest(com.thinkbiganalytics.alerts.rest.model.AlertUpdateRequest) DefaultValue(javax.ws.rs.DefaultValue) AccessController(com.thinkbiganalytics.security.AccessController) AlertRange(com.thinkbiganalytics.alerts.rest.model.AlertRange) Formatters(com.thinkbiganalytics.Formatters) URI(java.net.URI) Named(javax.inject.Named) Api(io.swagger.annotations.Api) Status(javax.ws.rs.core.Response.Status) POST(javax.ws.rs.POST) OperationsAccessControl(com.thinkbiganalytics.jobrepo.security.OperationsAccessControl) Collection(java.util.Collection) AlertType(com.thinkbiganalytics.alerts.rest.model.AlertType) Set(java.util.Set) Collectors(java.util.stream.Collectors) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) List(java.util.List) Component(org.springframework.stereotype.Component) ApiResponse(io.swagger.annotations.ApiResponse) Optional(java.util.Optional) WebApplicationException(javax.ws.rs.WebApplicationException) KyloEntityAwareAlertManager(com.thinkbiganalytics.metadata.alerts.KyloEntityAwareAlertManager) UriInfo(javax.ws.rs.core.UriInfo) AlertsModel(com.thinkbiganalytics.alerts.rest.AlertsModel) AlertSummaryGrouped(com.thinkbiganalytics.alerts.rest.model.AlertSummaryGrouped) AlertCriteria(com.thinkbiganalytics.alerts.api.AlertCriteria) AlertCriteriaInput(com.thinkbiganalytics.alerts.api.core.AlertCriteriaInput) AlertResponse(com.thinkbiganalytics.alerts.api.AlertResponse) WebApplicationException(javax.ws.rs.WebApplicationException)

Example 4 with AlertCriteria

use of com.thinkbiganalytics.alerts.api.AlertCriteria in project kylo by Teradata.

the class AlertsController method getAlertSummaryUnhandled.

@GET
@Path("/summary/unhandled")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Lists summary grouped alerts.")
@ApiResponses(@ApiResponse(code = 200, message = "Returns summary of the alerts grouped.", response = AlertRange.class))
public Collection<AlertSummaryGrouped> getAlertSummaryUnhandled(@QueryParam("type") String type, @QueryParam("subtype") String subtype) {
    List<AlertSummary> alerts = new ArrayList<>();
    AlertCriteria criteria = createCriteria(null, type, subtype, Alert.State.UNHANDLED.name(), null, null, null, "false");
    provider.getAlertsSummary(criteria).forEachRemaining(alerts::add);
    return alertsModel.groupAlertSummaries(alerts);
}
Also used : AlertCriteria(com.thinkbiganalytics.alerts.api.AlertCriteria) ArrayList(java.util.ArrayList) AlertSummary(com.thinkbiganalytics.alerts.api.AlertSummary) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 5 with AlertCriteria

use of com.thinkbiganalytics.alerts.api.AlertCriteria in project kylo by Teradata.

the class OpsFeedManagerFeedProvider method abandonFeedJobs.

/**
 * This will call the stored procedure abandon_feed_jobs
 */
public void abandonFeedJobs(String feed) {
    String exitMessage = String.format("Job manually abandoned @ %s", DateTimeUtil.getNowFormattedWithTimeZone());
    String username = SecurityContextHolder.getContext().getAuthentication().getName();
    repository.abandonFeedJobs(feed, exitMessage, username);
    // TODO Notify the JobExecution Cache of updates
    // all the alerts manager to handle all job failures
    AlertCriteria criteria = alertProvider.criteria().type(OperationalAlerts.JOB_FALURE_ALERT_TYPE).subtype(feed);
    Iterator<? extends Alert> alerts = alertProvider.getAlerts(criteria);
    StreamSupport.stream(Spliterators.spliteratorUnknownSize(alerts, Spliterator.ORDERED), false).forEach(alert -> alertProvider.respondTo(alert.getId(), (alert1, response) -> response.handle(exitMessage)));
    alertManager.updateLastUpdatedTime();
}
Also used : AlertCriteria(com.thinkbiganalytics.alerts.api.AlertCriteria) AlertManager(com.thinkbiganalytics.alerts.spi.AlertManager) JobStatusCount(com.thinkbiganalytics.metadata.api.jobrepo.job.JobStatusCount) Spliterators(java.util.Spliterators) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) JpaBatchJobExecutionStatusCounts(com.thinkbiganalytics.metadata.jpa.jobrepo.job.JpaBatchJobExecutionStatusCounts) Projections(com.querydsl.core.types.Projections) GenericQueryDslFilter(com.thinkbiganalytics.metadata.jpa.support.GenericQueryDslFilter) Map(java.util.Map) AccessController(com.thinkbiganalytics.security.AccessController) OpsManagerFeed(com.thinkbiganalytics.metadata.api.feed.OpsManagerFeed) MetadataAccess(com.thinkbiganalytics.metadata.api.MetadataAccess) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) NifiFeedStatisticsProvider(com.thinkbiganalytics.metadata.api.jobrepo.nifi.NifiFeedStatisticsProvider) OpsManagerFeedProvider(com.thinkbiganalytics.metadata.api.feed.OpsManagerFeedProvider) Collection(java.util.Collection) Set(java.util.Set) MetadataEventService(com.thinkbiganalytics.metadata.api.event.MetadataEventService) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) JPAQuery(com.querydsl.jpa.impl.JPAQuery) BatchJobExecutionProvider(com.thinkbiganalytics.metadata.api.jobrepo.job.BatchJobExecutionProvider) ReadablePeriod(org.joda.time.ReadablePeriod) List(java.util.List) ExecutionConstants(com.thinkbiganalytics.metadata.api.jobrepo.ExecutionConstants) Expressions(com.querydsl.core.types.dsl.Expressions) PostConstruct(javax.annotation.PostConstruct) BatchJobExecution(com.thinkbiganalytics.metadata.api.jobrepo.job.BatchJobExecution) Spliterator(java.util.Spliterator) AlertCriteria(com.thinkbiganalytics.alerts.api.AlertCriteria) JpaServiceLevelAgreementDescription(com.thinkbiganalytics.metadata.jpa.sla.JpaServiceLevelAgreementDescription) DateTimeUtil(com.thinkbiganalytics.DateTimeUtil) BooleanBuilder(com.querydsl.core.BooleanBuilder) QJpaBatchJobExecution(com.thinkbiganalytics.metadata.jpa.jobrepo.job.QJpaBatchJobExecution) JpaNifiFeedStats(com.thinkbiganalytics.metadata.jpa.jobrepo.nifi.JpaNifiFeedStats) Value(org.springframework.beans.factory.annotation.Value) HashSet(java.util.HashSet) Inject(javax.inject.Inject) AlertProvider(com.thinkbiganalytics.alerts.api.AlertProvider) Lists(com.google.common.collect.Lists) Alert(com.thinkbiganalytics.alerts.api.Alert) Service(org.springframework.stereotype.Service) StreamSupport(java.util.stream.StreamSupport) Named(javax.inject.Named) LatestFeedJobExecution(com.thinkbiganalytics.metadata.api.feed.LatestFeedJobExecution) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) FeedNameUtil(com.thinkbiganalytics.support.FeedNameUtil) DateTime(org.joda.time.DateTime) NifiFeedStats(com.thinkbiganalytics.metadata.api.jobrepo.nifi.NifiFeedStats) JpaServiceLevelAgreementDescriptionRepository(com.thinkbiganalytics.metadata.jpa.sla.JpaServiceLevelAgreementDescriptionRepository) AbstractCacheBackedProvider(com.thinkbiganalytics.metadata.jpa.cache.AbstractCacheBackedProvider) JPAQueryFactory(com.querydsl.jpa.impl.JPAQueryFactory) OperationalAlerts(com.thinkbiganalytics.metadata.api.alerts.OperationalAlerts) EntityAccessControlled(com.thinkbiganalytics.metadata.jpa.common.EntityAccessControlled) QJpaBatchJobInstance(com.thinkbiganalytics.metadata.jpa.jobrepo.job.QJpaBatchJobInstance) JobStatusDslQueryExpressionBuilder(com.thinkbiganalytics.metadata.jpa.support.JobStatusDslQueryExpressionBuilder) FeedHealth(com.thinkbiganalytics.metadata.api.feed.FeedHealth) FeedSummary(com.thinkbiganalytics.metadata.api.feed.FeedSummary) Collections(java.util.Collections)

Aggregations

AlertCriteria (com.thinkbiganalytics.alerts.api.AlertCriteria)10 ArrayList (java.util.ArrayList)7 AlertSummary (com.thinkbiganalytics.alerts.api.AlertSummary)6 Alert (com.thinkbiganalytics.alerts.api.Alert)4 ApiOperation (io.swagger.annotations.ApiOperation)4 ApiResponses (io.swagger.annotations.ApiResponses)4 GET (javax.ws.rs.GET)4 Produces (javax.ws.rs.Produces)4 AlertManager (com.thinkbiganalytics.alerts.spi.AlertManager)3 JPAQueryFactory (com.querydsl.jpa.impl.JPAQueryFactory)2 AlertProvider (com.thinkbiganalytics.alerts.api.AlertProvider)2 AlertResponse (com.thinkbiganalytics.alerts.api.AlertResponse)2 AlertCriteriaInput (com.thinkbiganalytics.alerts.api.core.AlertCriteriaInput)2 AlertRange (com.thinkbiganalytics.alerts.rest.model.AlertRange)2 AlertSummaryGrouped (com.thinkbiganalytics.alerts.rest.model.AlertSummaryGrouped)2 OpsManagerFeed (com.thinkbiganalytics.metadata.api.feed.OpsManagerFeed)2 URI (java.net.URI)2 List (java.util.List)2 Optional (java.util.Optional)2 Set (java.util.Set)2