Search in sources :

Example 26 with Notification

use of io.cdap.cdap.proto.Notification in project cdap by caskdata.

the class ProgramStatusEventPublisher method processMessages.

@Override
protected void processMessages(StructuredTableContext structuredTableContext, Iterator<ImmutablePair<String, Notification>> messages) {
    List<ProgramStatusEvent> programStatusEvents = new ArrayList<>();
    long publishTime = System.currentTimeMillis();
    messages.forEachRemaining(message -> {
        Notification notification = message.getSecond();
        if (!notification.getNotificationType().equals(Notification.Type.PROGRAM_STATUS)) {
            return;
        }
        Map<String, String> properties = notification.getProperties();
        // get program run ID
        String programStatus = properties.get(ProgramOptionConstants.PROGRAM_STATUS);
        if (programStatus == null) {
            return;
        }
        ProgramRunStatus programRunStatus = ProgramRunStatus.valueOf(programStatus);
        String programRun = properties.get(ProgramOptionConstants.PROGRAM_RUN_ID);
        ProgramRunId programRunId = GSON.fromJson(programRun, ProgramRunId.class);
        // Should event publish happen for this status
        if (!shouldPublish(programRunId)) {
            return;
        }
        ProgramStatusEventDetails.Builder builder = ProgramStatusEventDetails.getBuilder(programRunId.getRun(), programRunId.getApplication(), programRunId.getProgram(), programRunId.getNamespace(), programStatus, RunIds.getTime(programRunId.getRun(), TimeUnit.MILLISECONDS));
        String userArgsString = properties.get(ProgramOptionConstants.USER_OVERRIDES);
        String sysArgsString = properties.get(ProgramOptionConstants.SYSTEM_OVERRIDES);
        Type argsMapType = new TypeToken<Map<String, String>>() {
        }.getType();
        builder = builder.withUserArgs(GSON.fromJson(userArgsString, argsMapType)).withSystemArgs(GSON.fromJson(sysArgsString, argsMapType));
        if (programRunStatus.isEndState()) {
            builder = populateErrorDetailsAndMetrics(builder, properties, programRunStatus, programRunId);
        }
        ProgramStatusEventDetails programStatusEventDetails = builder.build();
        ProgramStatusEvent programStatusEvent = new ProgramStatusEvent(publishTime, EVENT_VERSION, instanceName, projectName, programStatusEventDetails);
        programStatusEvents.add(programStatusEvent);
    });
    this.eventWriters.forEach(eventWriter -> eventWriter.write(programStatusEvents));
}
Also used : ArrayList(java.util.ArrayList) Notification(io.cdap.cdap.proto.Notification) Type(java.lang.reflect.Type) ProgramRunStatus(io.cdap.cdap.proto.ProgramRunStatus) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) Map(java.util.Map)

Aggregations

Notification (io.cdap.cdap.proto.Notification)26 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)7 IOException (java.io.IOException)7 Map (java.util.Map)7 MessagingService (io.cdap.cdap.messaging.MessagingService)6 ProgramRunStatus (io.cdap.cdap.proto.ProgramRunStatus)6 Test (org.junit.Test)6 Gson (com.google.gson.Gson)5 ProgramStateWriter (io.cdap.cdap.app.runtime.ProgramStateWriter)5 RunIds (io.cdap.cdap.common.app.RunIds)5 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)5 Constants (io.cdap.cdap.common.conf.Constants)5 MessagingProgramStateWriter (io.cdap.cdap.internal.app.program.MessagingProgramStateWriter)5 ProgramOptionConstants (io.cdap.cdap.internal.app.runtime.ProgramOptionConstants)5 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)5 TopicNotFoundException (io.cdap.cdap.api.messaging.TopicNotFoundException)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 Service (com.google.common.util.concurrent.Service)3 CloseableIterator (io.cdap.cdap.api.dataset.lib.CloseableIterator)3 PartitionKey (io.cdap.cdap.api.dataset.lib.PartitionKey)3