All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.netflix.eureka2.server.audit.AuditServiceController Maven / Gradle / Ivy

/*
 * Copyright 2014 Netflix, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.netflix.eureka2.server.audit;

import com.netflix.eureka2.interests.ChangeNotification;
import com.netflix.eureka2.interests.Interests;
import com.netflix.eureka2.registry.InstanceInfo;
import com.netflix.eureka2.server.registry.EurekaServerRegistry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import rx.Subscriber;

import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Singleton;

/**
 * @author Tomasz Bak
 */
@Singleton
public class AuditServiceController {

    private static final Logger logger = LoggerFactory.getLogger(AuditServiceController.class);

    private final EurekaServerRegistry registry;
    private final AuditService auditService;

    @Inject
    public AuditServiceController(EurekaServerRegistry registry, AuditService auditService) {
        this.registry = registry;
        this.auditService = auditService;
    }

    @PostConstruct
    public void startRegistryAuditing() {
        // TODO: this should be only Origin.Local, but since bridge works on replication channel we would not audit eureka 1.0 entries.
        registry.forInterest(Interests.forFullRegistry()).subscribe(new Subscriber>() {
            @Override
            public void onCompleted() {
                logger.warn("Registry auditing finished");
            }

            @Override
            public void onError(Throwable e) {
                logger.warn("Registry auditing finished due to an error in interest channel subscription", e);
            }

            @Override
            public void onNext(ChangeNotification notification) {
                AuditRecord record = AuditRecords.forChangeNotification(System.currentTimeMillis(), false, notification);
                auditService.write(record);
            }
        });
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy