Search in sources :

Example 1 with NotifyServiceData

use of alma.acs.nsstatistics.NotifyServiceData in project ACS by ACS-Community.

the class nsStatisticsService method run.

/**
	 * 
	 */
public void run() {
    // 1min
    long acqFreq = ACQUISITION_FREQUENCY;
    // at least 1min		
    long logFreq = params.getFrequency();
    if (logFreq < acqFreq) {
        logger.log(AcsLogLevel.WARNING, "Statistics of Notification Services will be obtained with a very high frequency (less than 1 minute time interval)");
        acqFreq = logFreq;
    }
    logger.log(AcsLogLevel.INFO, "Acquisition frequency: " + String.valueOf(acqFreq) + "ms");
    logger.log(AcsLogLevel.INFO, "Log frequency: " + String.valueOf(logFreq) + "ms");
    acqFreq = acqFreq / MAIN_LOOP_FREQUENCY;
    logFreq = logFreq / MAIN_LOOP_FREQUENCY;
    boolean nsExists = false;
    long counter = 0;
    while (stop == false) {
        try {
            if (// Time to get statistics from the channels
            counter % acqFreq == 0) {
                nsExists = eventModel.getChannelStatistics();
                if (false == nsExists) {
                    setServicesStatus(Status.UNKNOWN);
                    if (eventModel.reconnectNamingService() == false) {
                        logger.log(AcsLogLevel.ERROR, "Naming Service is unreachable");
                    } else {
                        nsExists = true;
                    }
                // Calculate statistics
                } else {
                    // Get notify services 
                    NotifyServices ns = eventModel.getNotifyServicesRoot();
                    // Get services to be treated
                    List<NotifyServiceData> services = getCurrentServices();
                    // Get channels to be treated
                    List<ChannelData> channels = getCurrentChannels(ns);
                    // Update status of services and channels
                    updateStatus(services, channels);
                }
            }
            // It's time to log statistics
            if (true == nsExists && (counter + 1) % logFreq == 0) {
                // Log services and channels statistics
                logStatus();
                // After logging statistics, we have to reset them
                resetStats();
            }
        } catch (Exception e) {
            logger.warning("Notification Service doesn't exist!");
            String str = "";
            StackTraceElement[] stack = e.getStackTrace();
            for (int k = 0; k < stack.length; ++k) {
                str += stack[k] + "\n";
            }
            logger.warning(e.getMessage() + "\n" + str);
        }
        try {
            ++counter;
            sleep(MAIN_LOOP_FREQUENCY);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    logger.info("nsStatisticsService thread has been finished");
}
Also used : ChannelData(alma.acs.nsstatistics.ChannelData) NotifyServiceData(alma.acs.nsstatistics.NotifyServiceData) NotifyServices(alma.acs.nsstatistics.NotifyServices) AcsJException(alma.acs.exceptions.AcsJException)

Example 2 with NotifyServiceData

use of alma.acs.nsstatistics.NotifyServiceData in project ACS by ACS-Community.

the class nsStatisticsService method getCurrentServices.

/**
	 * Get current services to be treated
	 * @return List of services
	 */
protected List<NotifyServiceData> getCurrentServices() {
    NotifyServices ns = eventModel.getNotifyServicesRoot();
    List<NotifyServiceData> selServices = new ArrayList<NotifyServiceData>();
    List<NotifyServiceData> services = ns.getServices();
    if (params.getSelectedServicesChannels().isEmpty()) {
        return services;
    } else {
        NotifyServiceData service = null;
        for (Iterator<NotifyServiceData> it = services.iterator(); it.hasNext(); ) {
            service = it.next();
            if (params.getSelectedServicesChannels().containsKey(service.getName())) {
                selServices.add(service);
            }
        }
    }
    return selServices;
}
Also used : NotifyServiceData(alma.acs.nsstatistics.NotifyServiceData) ArrayList(java.util.ArrayList) NotifyServices(alma.acs.nsstatistics.NotifyServices)

Example 3 with NotifyServiceData

use of alma.acs.nsstatistics.NotifyServiceData in project ACS by ACS-Community.

the class nsStatisticsService method updateStatus.

protected void updateStatus(List<NotifyServiceData> services, List<ChannelData> channels) {
    NotifyServiceData service = null;
    ChannelData channel = null;
    // Iterate services passed as input parameter to update their status
    for (Iterator<NotifyServiceData> it = services.iterator(); it.hasNext(); ) {
        service = it.next();
        // Status of the current service already exists
        if (status.containsKey(service.getName())) {
            ServiceInfo serviceInfo = status.get(service.getName());
            if (Status.DISABLED == serviceInfo.status) {
                logger.warning("Notify Service '" + service.getName() + "' has been restarted");
                serviceInfo.status = Status.ENABLED;
            } else if (Status.UNKNOWN == serviceInfo.status) {
                logger.warning("Notify Service '" + service.getName() + "' is running");
                serviceInfo.status = Status.ENABLED;
            }
        // Status of the current service didn't exist so we create it
        } else {
            status.put(service.getName(), new ServiceInfo(Status.ENABLED));
            logger.warning("Notify Service '" + service.getName() + "' is running");
        }
    }
    // Iterate channels passed as input parameter to update their status
    for (Iterator<ChannelData> it = channels.iterator(); it.hasNext(); ) {
        channel = it.next();
        String channelName = channel.getQualifiedName();
        String serviceName = channel.getParent().getName();
        ServiceInfo serviceInfo = null;
        if (status.containsKey(serviceName)) {
            serviceInfo = status.get(serviceName);
        // Status of the service of the current channel doesn't exist so we create it	
        } else {
            serviceInfo = new ServiceInfo(Status.ENABLED);
            status.put(serviceName, serviceInfo);
            logger.warning("Notify Service '" + serviceName + "' is running");
        }
        ChannelInfo channelInfo = null;
        if (serviceInfo.channels.containsKey(channelName)) {
            channelInfo = serviceInfo.channels.get(channelName);
            if (Status.DISABLED == channelInfo.status) {
                channelInfo.status = Status.ENABLED;
            } else if (Status.UNKNOWN == channelInfo.status) {
                channelInfo.status = Status.ENABLED;
            }
        } else {
            channelInfo = new ChannelInfo(Status.ENABLED);
            serviceInfo.channels.put(channelName, channelInfo);
        }
        // Update channel statistics
        channelInfo.stats.setData(channel);
    }
    // Iterate services and channels already registered to disable the ones
    // that are not found
    Set<String> registeredServices = status.keySet();
    for (Iterator<String> it = registeredServices.iterator(); it.hasNext(); ) {
        String serviceName = it.next();
        ServiceInfo serviceInfo = status.get(serviceName);
        boolean found = false;
        for (Iterator<NotifyServiceData> it2 = services.iterator(); it2.hasNext() && false == found; ) {
            service = it2.next();
            if (service.getName().equals(serviceName)) {
                found = true;
            }
        }
        if (false == found && Status.ENABLED == serviceInfo.status) {
            logger.warning("Notify Service '" + serviceName + "' has been stopped");
            serviceInfo.status = Status.DISABLED;
        }
        Set<String> registeredChannels = serviceInfo.channels.keySet();
        for (Iterator<String> itc = registeredChannels.iterator(); itc.hasNext(); ) {
            String channelName = itc.next();
            ChannelInfo channelInfo = serviceInfo.channels.get(channelName);
            found = false;
            for (Iterator<ChannelData> itc2 = channels.iterator(); itc2.hasNext() && false == found; ) {
                channel = itc2.next();
                if (channel.getQualifiedName().equals(channelName)) {
                    found = true;
                }
            }
            if (false == found && Status.ENABLED == channelInfo.status) {
                channelInfo.status = Status.DISABLED;
            }
        }
    }
}
Also used : ChannelData(alma.acs.nsstatistics.ChannelData) NotifyServiceData(alma.acs.nsstatistics.NotifyServiceData)

Aggregations

NotifyServiceData (alma.acs.nsstatistics.NotifyServiceData)3 ChannelData (alma.acs.nsstatistics.ChannelData)2 NotifyServices (alma.acs.nsstatistics.NotifyServices)2 AcsJException (alma.acs.exceptions.AcsJException)1 ArrayList (java.util.ArrayList)1