Search in sources :

Example 36 with Event

use of com.google.cloud.video.livestream.v1.Event in project java-docs-samples by GoogleCloudPlatform.

the class TestUtils method cleanStaleChannels.

public static void cleanStaleChannels(String projectId, String location) {
    try (LivestreamServiceClient livestreamServiceClient = LivestreamServiceClient.create()) {
        var listChannelsRequest = ListChannelsRequest.newBuilder().setParent(LocationName.of(projectId, location).toString()).build();
        LivestreamServiceClient.ListChannelsPagedResponse response = livestreamServiceClient.listChannels(listChannelsRequest);
        for (Channel channel : response.iterateAll()) {
            if (channel.getCreateTime().getSeconds() < Instant.now().getEpochSecond() - DELETION_THRESHOLD_TIME_HOURS_IN_SECONDS) {
                // Stop the channel
                try {
                    livestreamServiceClient.stopChannelAsync(channel.getName()).get(1, TimeUnit.MINUTES);
                } catch (ExecutionException e) {
                    // Ignore error if the channel isn't stopped or the stop operation times out.
                    e.printStackTrace();
                } catch (NotFoundException | InterruptedException | TimeoutException e) {
                    e.printStackTrace();
                    continue;
                }
                // Delete the channel events
                var listEventsRequest = ListEventsRequest.newBuilder().setParent(channel.getName()).build();
                LivestreamServiceClient.ListEventsPagedResponse eventsResponse = livestreamServiceClient.listEvents(listEventsRequest);
                for (Event event : eventsResponse.iterateAll()) {
                    var deleteEventRequest = DeleteEventRequest.newBuilder().setName(event.getName()).build();
                    livestreamServiceClient.deleteEvent(deleteEventRequest);
                }
                // Delete the channel
                var deleteChannelRequest = DeleteChannelRequest.newBuilder().setName(channel.getName()).build();
                livestreamServiceClient.deleteChannelAsync(deleteChannelRequest).get(1, TimeUnit.MINUTES);
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    } catch (NotFoundException | InterruptedException | ExecutionException | TimeoutException e) {
        e.printStackTrace();
    }
}
Also used : Channel(com.google.cloud.video.livestream.v1.Channel) NotFoundException(com.google.api.gax.rpc.NotFoundException) IOException(java.io.IOException) Event(com.google.cloud.video.livestream.v1.Event) ExecutionException(java.util.concurrent.ExecutionException) LivestreamServiceClient(com.google.cloud.video.livestream.v1.LivestreamServiceClient) TimeoutException(java.util.concurrent.TimeoutException)

Example 37 with Event

use of com.google.cloud.video.livestream.v1.Event in project skywalking by apache.

the class EventHookCallbackTest method testEventCallbackHasRightFlow.

@Test
public void testEventCallbackHasRightFlow() throws Exception {
    List<AlarmMessage> msgs = mockAlarmMessagesHasSingleElement();
    EventHookCallback callback = new EventHookCallback(this.moduleManager);
    when(moduleManager.find("event-analyzer")).thenReturn(moduleProviderHolder);
    when(moduleProviderHolder.provider()).thenReturn(moduleServiceHolder);
    when(moduleServiceHolder.getService(EventAnalyzerService.class)).thenReturn(mockEventAnalyzerService);
    // make sure current service be called.
    callback.doAlarm(msgs);
    verify(mockEventAnalyzerService).analyze(any(Event.class));
    when(moduleServiceHolder.getService(EventAnalyzerService.class)).thenReturn(eventAnalyzerService);
    callback.doAlarm(msgs);
    // Ensure that the current Event is properly constructed
    ArgumentCaptor<Event> argument = ArgumentCaptor.forClass(Event.class);
    verify(eventAnalyzerService).analyze(argument.capture());
    Event value = argument.getValue();
    AlarmMessage msg = msgs.get(0);
    assertEquals(msg.getName(), value.getSource().getService());
    assertEquals("Alarm", value.getName());
    assertEquals(msg.getAlarmMessage(), value.getMessage());
    assertEquals(msg.getPeriod(), (value.getEndTime() - value.getStartTime()) / 1000 / 60);
}
Also used : AlarmMessage(org.apache.skywalking.oap.server.core.alarm.AlarmMessage) Event(org.apache.skywalking.apm.network.event.v3.Event) Test(org.junit.Test)

Example 38 with Event

use of com.google.cloud.video.livestream.v1.Event in project skywalking by apache.

the class EventHookCallbackTest method testRelationEventBeProperlyConstructed.

@Test
public void testRelationEventBeProperlyConstructed() {
    List<AlarmMessage> msgs = mockAlarmMessagesHasSourceAndDest();
    EventHookCallback callback = new EventHookCallback(this.moduleManager);
    when(moduleManager.find("event-analyzer")).thenReturn(moduleProviderHolder);
    when(moduleProviderHolder.provider()).thenReturn(moduleServiceHolder);
    when(moduleServiceHolder.getService(EventAnalyzerService.class)).thenReturn(eventAnalyzerService);
    callback.doAlarm(msgs);
    ArgumentCaptor<Event> argument = ArgumentCaptor.forClass(Event.class);
    verify(eventAnalyzerService, times(2)).analyze(argument.capture());
    List<Event> events = argument.getAllValues();
    assertEquals(events.size(), 2);
    Event sourceEvent = events.get(0);
    Event destEvent = events.get(1);
    AlarmMessage msg = msgs.get(0);
    assertEquals(sourceEvent.getSource().getService(), IDManager.ServiceID.analysisId(msg.getId0()).getName());
    assertEquals((sourceEvent.getEndTime() - sourceEvent.getStartTime()) / 1000 / 60, msg.getPeriod());
    assertEquals(destEvent.getSource().getService(), IDManager.ServiceID.analysisId(msg.getId1()).getName());
    assertEquals((destEvent.getEndTime() - destEvent.getStartTime()) / 1000 / 60, msg.getPeriod());
}
Also used : AlarmMessage(org.apache.skywalking.oap.server.core.alarm.AlarmMessage) Event(org.apache.skywalking.apm.network.event.v3.Event) Test(org.junit.Test)

Example 39 with Event

use of com.google.cloud.video.livestream.v1.Event in project incubator-skywalking by apache.

the class EventHookCallback method doAlarm.

@Override
public void doAlarm(List<AlarmMessage> alarmMessage) {
    EventAnalyzerService analyzerService = manager.find(EventAnalyzerModule.NAME).provider().getService(EventAnalyzerService.class);
    alarmMessage.forEach(a -> {
        for (Event event : constructCurrentEvent(a)) {
            analyzerService.analyze(event);
        }
    });
}
Also used : EventAnalyzerService(org.apache.skywalking.oap.server.analyzer.event.EventAnalyzerService) Event(org.apache.skywalking.apm.network.event.v3.Event)

Example 40 with Event

use of com.google.cloud.video.livestream.v1.Event in project prison-api by ministryofjustice.

the class NomisApiV1ServiceTest method getEvents.

@Test
public void getEvents() {
    final var date = LocalDateTime.parse("2020-01-02T03:02:01");
    when(eventsV1Repository.getEvents(anyString(), isNull(), anyLong(), isNull(), anyString(), any(), anyLong())).thenReturn(List.of(new EventSP(5L, date, "MDI", "A1234", "ETYPE", "Event ", "Data 2", " and 3")));
    final var events = service.getEvents("prison", new OffenderIdentifier("12345"), "type", LocalDateTime.now(), 5L);
    assertThat(events).containsExactly(new Event("ETYPE", 5L, "A1234", "MDI", date, "Event Data 2 and 3"));
}
Also used : OffenderIdentifier(uk.gov.justice.hmpps.prison.api.model.v1.OffenderIdentifier) Event(uk.gov.justice.hmpps.prison.api.model.v1.Event) EventSP(uk.gov.justice.hmpps.prison.repository.v1.model.EventSP) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.Test)18 Event (io.requery.test.model3.Event)9 UUID (java.util.UUID)9 Event (org.apache.skywalking.apm.network.event.v3.Event)9 Test (org.junit.jupiter.api.Test)9 LivestreamServiceClient (com.google.cloud.video.livestream.v1.LivestreamServiceClient)5 Event (org.eclipse.bpmn2.Event)5 Event (com.google.cloud.video.livestream.v1.Event)4 Place (io.requery.test.model3.Place)4 Tag (io.requery.test.model3.Tag)4 AlarmMessage (org.apache.skywalking.oap.server.core.alarm.AlarmMessage)4 ListNamespacedEvent (com.marcnuri.yakc.api.events.v1.EventsV1Api.ListNamespacedEvent)3 Event (com.marcnuri.yakc.model.io.k8s.api.events.v1.Event)3 Event (io.fabric8.kubernetes.api.model.events.v1.Event)3 Event (io.requery.test.model2.Event)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Event (uk.gov.justice.hmpps.prison.api.model.v1.Event)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 JsonArray (com.google.gson.JsonArray)2