Search in sources :

Example 6 with Notification

use of co.cask.cdap.proto.Notification in project cdap by caskdata.

the class JobQueueDataset method isTriggerSatisfied.

private boolean isTriggerSatisfied(Trigger trigger, List<Notification> notifications) {
    if (trigger instanceof TimeTrigger || trigger instanceof StreamSizeTrigger) {
        // is initially created
        return true;
    }
    if (trigger instanceof PartitionTrigger) {
        PartitionTrigger partitionTrigger = (PartitionTrigger) trigger;
        int numPartitions = 0;
        for (Notification notification : notifications) {
            String numPartitionsString = notification.getProperties().get("numPartitions");
            numPartitions += Integer.parseInt(numPartitionsString);
        }
        return numPartitions >= partitionTrigger.getNumPartitions();
    }
    throw new IllegalArgumentException("Unknown trigger class: " + trigger.getClass());
}
Also used : TimeTrigger(co.cask.cdap.internal.app.runtime.schedule.trigger.TimeTrigger) StreamSizeTrigger(co.cask.cdap.internal.app.runtime.schedule.trigger.StreamSizeTrigger) Constraint(co.cask.cdap.internal.schedule.constraint.Constraint) Notification(co.cask.cdap.proto.Notification) PartitionTrigger(co.cask.cdap.internal.app.runtime.schedule.trigger.PartitionTrigger)

Example 7 with Notification

use of co.cask.cdap.proto.Notification in project cdap by caskdata.

the class CoreSchedulerServiceTest method publishNotification.

private void publishNotification(TopicId topicId, ProgramId programId, String dataset) throws TopicNotFoundException, IOException, TransactionFailureException, AlreadyExistsException, BadRequestException {
    DatasetId datasetId = programId.getNamespaceId().dataset(dataset);
    PartitionKey partitionKey = PartitionKey.builder().addIntField("part1", 1).build();
    Notification notification = Notification.forPartitions(datasetId, ImmutableList.of(partitionKey));
    messagingService.publish(StoreRequestBuilder.of(topicId).addPayloads(GSON.toJson(notification)).build());
}
Also used : PartitionKey(co.cask.cdap.api.dataset.lib.PartitionKey) Notification(co.cask.cdap.proto.Notification) DatasetId(co.cask.cdap.proto.id.DatasetId)

Example 8 with Notification

use of co.cask.cdap.proto.Notification in project cdap by caskdata.

the class ScheduleTaskPublisher method publishNotification.

/**
   * Publish notification for the triggered schedule
   *  @param notificationType type of the notification
   * @param scheduleId       {@link ScheduleId} of the triggered schedule
   * @param systemOverrides Arguments that would be supplied as system runtime arguments for the program.
   * @param userOverrides Arguments to add to the user runtime arguments for the program.
   */
public void publishNotification(Notification.Type notificationType, ScheduleId scheduleId, Map<String, String> systemOverrides, Map<String, String> userOverrides) throws Exception {
    Map<String, String> properties = new HashMap<>();
    properties.put(ProgramOptionConstants.SCHEDULE_ID, scheduleId.toString());
    properties.put(ProgramOptionConstants.SYSTEM_OVERRIDES, GSON.toJson(systemOverrides));
    properties.put(ProgramOptionConstants.USER_OVERRIDES, GSON.toJson(userOverrides));
    Notification notification = new Notification(notificationType, properties);
    messagingService.publish(StoreRequestBuilder.of(topicId).addPayloads(GSON.toJson(notification)).build());
}
Also used : HashMap(java.util.HashMap) Notification(co.cask.cdap.proto.Notification)

Aggregations

Notification (co.cask.cdap.proto.Notification)8 HashMap (java.util.HashMap)3 KeyValueTable (co.cask.cdap.api.dataset.lib.KeyValueTable)2 PartitionDetail (co.cask.cdap.api.dataset.lib.PartitionDetail)2 PartitionKey (co.cask.cdap.api.dataset.lib.PartitionKey)2 PartitionedFileSet (co.cask.cdap.api.dataset.lib.PartitionedFileSet)2 Location (org.apache.twill.filesystem.Location)2 Test (org.junit.Test)2 KeyValue (co.cask.cdap.api.dataset.lib.KeyValue)1 Message (co.cask.cdap.api.messaging.Message)1 MessagingContext (co.cask.cdap.api.messaging.MessagingContext)1 ApplicationWithPrograms (co.cask.cdap.internal.app.deploy.pipeline.ApplicationWithPrograms)1 BasicArguments (co.cask.cdap.internal.app.runtime.BasicArguments)1 MultiThreadMessagingContext (co.cask.cdap.internal.app.runtime.messaging.MultiThreadMessagingContext)1 ProgramSchedule (co.cask.cdap.internal.app.runtime.schedule.ProgramSchedule)1 PartitionTrigger (co.cask.cdap.internal.app.runtime.schedule.trigger.PartitionTrigger)1 StreamSizeTrigger (co.cask.cdap.internal.app.runtime.schedule.trigger.StreamSizeTrigger)1 TimeTrigger (co.cask.cdap.internal.app.runtime.schedule.trigger.TimeTrigger)1 Constraint (co.cask.cdap.internal.schedule.constraint.Constraint)1 MessagingService (co.cask.cdap.messaging.MessagingService)1