<commit_before>/*
 * Copyright 2009-2011 Red Hat, 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.
 */


#include "condor_common.h"

// local includes
#include "ODSMongodbOps.h"
#include "ODSUtils.h"
#include "ODSAccountant.h"
#include "ODSProcessors.h"
#include "ODSDBNames.h"

// seems boost meddles with assert defs
#include "assert.h"
#include "condor_config.h"
#include "../condor_collector.V6/CollectorPlugin.h"
#include "hashkey.h"
#include "../condor_collector.V6/collector.h"
#include "../condor_daemon_core.V6/condor_daemon_core.h"

using namespace std;
using namespace mongo;
using namespace plumage::etl;
using namespace plumage::util;

int historyInterval;
int initialDelay;
int statsTimer;
int acctTimer;
int acctInterval;

class PlumageCollectorPlugin : public Service, CollectorPlugin
{
	string m_name;
	string m_ip;
	ODSMongodbOps* m_ads_conn;
	ODSMongodbOps* m_stats_conn;
    ClassAd* m_acct_ad;
    bool  m_settled;
    
    // Accountant ad is a special case: we don't get it from the Collector
    // it needs its own processing and sample interval
    void
    recordAccountantAd() {
        dprintf(D_FULLDEBUG, "PlumageCollectorPlugin::recordAccountantAd() called...\n");
        ODSAccountant acct;
        acct.connect();
        if (m_acct_ad) {
            delete m_acct_ad;
            m_acct_ad = NULL;
        }
        if (!(m_acct_ad = acct.fetchAd())) {
            dprintf(D_ALWAYS, "PlumageCollectorPlugin: unable to retrieve accountant ad from negotiator\n");
        }
        Date_t ts_now = jsTime();
        processAccountantStats(m_acct_ad, m_stats_conn, ts_now);
    }

    void
    processStatsTimer() {
        m_settled = true;
        dprintf(D_FULLDEBUG, "PlumageCollectorPlugin::processStatsTimer() called\n");
        // sync all stat records to the same timestamp
        Date_t ts_sync = jsTime();
        processSubmitterStats(m_stats_conn, ts_sync);
        processMachineStats(m_stats_conn, ts_sync);
        processSchedulerStats(m_stats_conn, ts_sync);
    }
    
    

public:
    PlumageCollectorPlugin(): m_ads_conn(NULL), m_stats_conn(NULL),m_acct_ad(NULL),m_settled(FALSE)
    {
        //
    }

	void
	initialize()
	{

		dprintf(D_FULLDEBUG, "PlumageCollectorPlugin: Initializing...\n");

		m_name = getPoolName();
		m_ip = my_ip_string();

        HostAndPort hap = getDbHostPort("PLUMAGE_JOBS_DB_HOST","PLUMAGE_JOBS_DB_PORT");

        m_ads_conn = new ODSMongodbOps(DB_RAW_ADS);
        if (!m_ads_conn->init(hap.toString())) {
			EXCEPT("Failed to initialize DB connection for raw ads");
		}

        m_stats_conn = new ODSMongodbOps(DB_STATS_SAMPLES);
        if (!m_stats_conn->init(hap.toString())) {
			EXCEPT("Failed to initialize DB connection for stats");
		}

        historyInterval = param_integer("POOL_HISTORY_SAMPLING_INTERVAL",60);
        initialDelay = param_integer("UPDATE_INTERVAL",300);<commit_msg>Change plumage collector db host and port config values<commit_after>/*
 * Copyright 2009-2011 Red Hat, 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.
 */


#include "condor_common.h"

// local includes
#include "ODSMongodbOps.h"
#include "ODSUtils.h"
#include "ODSAccountant.h"
#include "ODSProcessors.h"
#include "ODSDBNames.h"

// seems boost meddles with assert defs
#include "assert.h"
#include "condor_config.h"
#include "../condor_collector.V6/CollectorPlugin.h"
#include "hashkey.h"
#include "../condor_collector.V6/collector.h"
#include "../condor_daemon_core.V6/condor_daemon_core.h"

using namespace std;
using namespace mongo;
using namespace plumage::etl;
using namespace plumage::util;

int historyInterval;
int initialDelay;
int statsTimer;
int acctTimer;
int acctInterval;

class PlumageCollectorPlugin : public Service, CollectorPlugin
{
	string m_name;
	string m_ip;
	ODSMongodbOps* m_ads_conn;
	ODSMongodbOps* m_stats_conn;
    ClassAd* m_acct_ad;
    bool  m_settled;
    
    // Accountant ad is a special case: we don't get it from the Collector
    // it needs its own processing and sample interval
    void
    recordAccountantAd() {
        dprintf(D_FULLDEBUG, "PlumageCollectorPlugin::recordAccountantAd() called...\n");
        ODSAccountant acct;
        acct.connect();
        if (m_acct_ad) {
            delete m_acct_ad;
            m_acct_ad = NULL;
        }
        if (!(m_acct_ad = acct.fetchAd())) {
            dprintf(D_ALWAYS, "PlumageCollectorPlugin: unable to retrieve accountant ad from negotiator\n");
        }
        Date_t ts_now = jsTime();
        processAccountantStats(m_acct_ad, m_stats_conn, ts_now);
    }

    void
    processStatsTimer() {
        m_settled = true;
        dprintf(D_FULLDEBUG, "PlumageCollectorPlugin::processStatsTimer() called\n");
        // sync all stat records to the same timestamp
        Date_t ts_sync = jsTime();
        processSubmitterStats(m_stats_conn, ts_sync);
        processMachineStats(m_stats_conn, ts_sync);
        processSchedulerStats(m_stats_conn, ts_sync);
    }
    
    

public:
    PlumageCollectorPlugin(): m_ads_conn(NULL), m_stats_conn(NULL),m_acct_ad(NULL),m_settled(FALSE)
    {
        //
    }

	void
	initialize()
	{

		dprintf(D_FULLDEBUG, "PlumageCollectorPlugin: Initializing...\n");

		m_name = getPoolName();
		m_ip = my_ip_string();

        HostAndPort hap = getDbHostPort("PLUMAGE_DEFAULT_DB_HOST","PLUMAGE_DEFAULT_DB_PORT");

        m_ads_conn = new ODSMongodbOps(DB_RAW_ADS);
        if (!m_ads_conn->init(hap.toString())) {
			EXCEPT("Failed to initialize DB connection for raw ads");
		}

        m_stats_conn = new ODSMongodbOps(DB_STATS_SAMPLES);
        if (!m_stats_conn->init(hap.toString())) {
			EXCEPT("Failed to initialize DB connection for stats");
		}

        historyInterval = param_integer("POOL_HISTORY_SAMPLING_INTERVAL",60);
        initialDelay = param_integer("UPDATE_INTERVAL",300);
{'fraction_non_alphanumeric': 0.10043795620437956, 'fraction_numerical': 0.00583941605839416, 'mean_word_length': 3.546118115461181, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1369059', 'n_tokens_mistral': 2314, 'n_tokens_neox': 2213, 'n_words': 561}