Search in sources :

Example 16 with CoreV1Event

use of io.kubernetes.client.openapi.models.CoreV1Event in project java by kubernetes-client.

the class EventAggregator method aggregate.

public synchronized MutablePair<CoreV1Event, String> aggregate(CoreV1Event event) {
    OffsetDateTime now = OffsetDateTime.now();
    MutablePair<String, String> aggregatedKeys = keyFunc.apply(event);
    String aggregatedKey = aggregatedKeys.getLeft();
    String localKey = aggregatedKeys.getRight();
    AggregatedRecord record = this.spammingCache.get(aggregatedKey, k -> new AggregatedRecord());
    record.lastTimestamp = now;
    record.localKeys.add(localKey);
    if (record.localKeys.size() < this.maxEvents) {
        this.spammingCache.put(aggregatedKey, record);
        return new MutablePair<>(event, EventUtils.getEventKey(event));
    }
    // remove any keys
    record.localKeys.remove(record.localKeys.stream().findAny().get());
    CoreV1Event aggregatedEvent = new CoreV1EventBuilder(event).withMetadata(new V1ObjectMetaBuilder().withName(EventUtils.generateName(event.getInvolvedObject().getName(), now)).withNamespace(event.getInvolvedObject().getNamespace()).build()).withCount(1).withFirstTimestamp(now).withLastTimestamp(now).withMessage(this.messageFunc.apply(event)).build();
    this.spammingCache.put(aggregatedKey, record);
    return new MutablePair<>(aggregatedEvent, aggregatedKey);
}
Also used : MutablePair(org.apache.commons.lang3.tuple.MutablePair) OffsetDateTime(java.time.OffsetDateTime) CoreV1EventBuilder(io.kubernetes.client.openapi.models.CoreV1EventBuilder) V1ObjectMetaBuilder(io.kubernetes.client.openapi.models.V1ObjectMetaBuilder) CoreV1Event(io.kubernetes.client.openapi.models.CoreV1Event)

Example 17 with CoreV1Event

use of io.kubernetes.client.openapi.models.CoreV1Event in project java by kubernetes-client.

the class LegacyEventBroadcaster method recordToSink.

private void recordToSink(CoreV1Event event) throws InterruptedException {
    Optional<MutablePair<CoreV1Event, V1Patch>> eventAndPatch = this.eventCorrelator.correlate(event);
    if (!eventAndPatch.isPresent()) {
        // skip
        return;
    }
    CoreV1Event recordingEvent = eventAndPatch.get().getLeft();
    V1Patch patch = eventAndPatch.get().getRight();
    for (int retries = 0; retries < maxTriesPerEvent; retries++) {
        if (recordEvent(recordingEvent, patch, event.getCount() > 1)) {
            break;
        }
        Thread.sleep(sleepDuration.toMillis());
    }
}
Also used : MutablePair(org.apache.commons.lang3.tuple.MutablePair) V1Patch(io.kubernetes.client.custom.V1Patch) CoreV1Event(io.kubernetes.client.openapi.models.CoreV1Event)

Example 18 with CoreV1Event

use of io.kubernetes.client.openapi.models.CoreV1Event in project java by kubernetes-client.

the class CoreV1Api method readNamespacedEventWithHttpInfo.

/**
 * read the specified Event
 *
 * @param name name of the Event (required)
 * @param namespace object name and auth scope, such as for teams and projects (required)
 * @param pretty If &#39;true&#39;, then the output is pretty printed. (optional)
 * @return ApiResponse&lt;CoreV1Event&gt;
 * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the
 *     response body
 * @http.response.details
 *     <table summary="Response Details" border="1">
 * <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
 * <tr><td> 200 </td><td> OK </td><td>  -  </td></tr>
 * <tr><td> 401 </td><td> Unauthorized </td><td>  -  </td></tr>
 * </table>
 */
public ApiResponse<CoreV1Event> readNamespacedEventWithHttpInfo(String name, String namespace, String pretty) throws ApiException {
    okhttp3.Call localVarCall = readNamespacedEventValidateBeforeCall(name, namespace, pretty, null);
    Type localVarReturnType = new TypeToken<CoreV1Event>() {
    }.getType();
    return localVarApiClient.execute(localVarCall, localVarReturnType);
}
Also used : Type(java.lang.reflect.Type) CoreV1Event(io.kubernetes.client.openapi.models.CoreV1Event)

Aggregations

CoreV1Event (io.kubernetes.client.openapi.models.CoreV1Event)18 Type (java.lang.reflect.Type)8 CoreV1EventBuilder (io.kubernetes.client.openapi.models.CoreV1EventBuilder)7 V1ObjectMetaBuilder (io.kubernetes.client.openapi.models.V1ObjectMetaBuilder)4 Test (org.junit.Test)4 V1Patch (io.kubernetes.client.custom.V1Patch)3 EventUtils (io.kubernetes.client.extended.event.legacy.EventUtils)3 V1EventSourceBuilder (io.kubernetes.client.openapi.models.V1EventSourceBuilder)3 V1ObjectReference (io.kubernetes.client.openapi.models.V1ObjectReference)3 OffsetDateTime (java.time.OffsetDateTime)3 MutablePair (org.apache.commons.lang3.tuple.MutablePair)3 V1EventSource (io.kubernetes.client.openapi.models.V1EventSource)2 V1ObjectReferenceBuilder (io.kubernetes.client.openapi.models.V1ObjectReferenceBuilder)2 EventAggregator (io.kubernetes.client.extended.event.legacy.EventAggregator)1 EventCorrelator (io.kubernetes.client.extended.event.legacy.EventCorrelator)1 EventLogger (io.kubernetes.client.extended.event.legacy.EventLogger)1 EventSpamFilter (io.kubernetes.client.extended.event.legacy.EventSpamFilter)1 V1ObjectMeta (io.kubernetes.client.openapi.models.V1ObjectMeta)1 Parameters (org.junit.runners.Parameterized.Parameters)1