Search in sources :

Example 1 with MonitorDAO

use of alma.acs.monitoring.DAO.MonitorDAO in project ACS by ACS-Community.

the class TestBlobber method initialize.

/**
	 * Call this method instead of the inherited {@link #initialize(ContainerServices)}.
	 * @param inContainerServices
	 * @param inName Name of this test component instance, so that we can pass the JUnit test's ContainerServices object and still 
	 *               use a component name different from that test name.
	 * @throws ComponentLifecycleException
	 */
public void initialize(ContainerServices inContainerServices, String inName) throws ComponentLifecycleException {
    Logger tmpLogger = inContainerServices.getLogger();
    myBlobDataLock = new DataLock<BlobData>(tmpLogger, "blobberworker");
    MonitorDAO monitorDAO = new TestMonitorDAO(tmpLogger, myBlobDataLock);
    TestMonitorPointExpert myMonitorPointExpert = new TestMonitorPointExpert();
    myBlobberPlugin = new TestBlobberWorker.TestBlobberPlugin(inContainerServices, monitorDAO, myMonitorPointExpert);
    // calls createBlobberPlugin() etc
    initialize(inContainerServices);
    m_instanceName = inName;
}
Also used : TestBlobberPlugin(alma.acs.monitoring.blobber.TestBlobberWorker.TestBlobberPlugin) Logger(java.util.logging.Logger) MonitorDAO(alma.acs.monitoring.DAO.MonitorDAO)

Example 2 with MonitorDAO

use of alma.acs.monitoring.DAO.MonitorDAO in project ACS by ACS-Community.

the class BlobberWorker method harvestCollector.

/**
	 * Retrieves and processes the data from one monitor collector component, that is, from one container.
	 * <p>
	 * Storage details:
	 * <ul>
	 * <li>Uses {@link MonitorDAO} to control DB transactions and store the data.
	 * <li>Uses a total of one DB transaction (for the data from all properties of all devices, which comes in many
	 * {@link MonitorDataBlock}s).
	 * </ul>
	 * 
	 * @param collectorData
	 *            The collector ID / name, used for logging and stats.
	 * @param collector
	 *            Reference to the collector component
	 * @return Number of attempted or successful DB inserts, i.e., calls to
	 *         {@link alma.archive.tmcdb.DAO.MonitorDAO#store(alma.archive.tmcdb.DAO.ComponentData)}.
	 * @throws Exception
	 */
private int harvestCollector(CollectorData collectorData, MonitorCollectorOperations collector) throws Exception {
    int insertCount = 0;
    myLogger.fine("About to call " + collectorData.getCollectorId() + "#getMonitorData()");
    MonitorDataBlock[] dataBlocks = collector.getMonitorData();
    collectorData.setLastSuccessfulAccessTime(System.currentTimeMillis());
    if (dataBlocks != null) {
        // be the name.
        if (myLogger.isLoggable(Level.FINE)) {
            myLogger.fine("Received " + dataBlocks.length + " MonitorDataBlocks from collector " + collector.name());
        }
        if (isProfilingEnabled) {
            debugDataSender.sendUDPPacket("Received " + dataBlocks.length + " MonitorDataBlocks from collector " + collector.name(), cycleCount.longValue());
            Runtime runtime = Runtime.getRuntime();
            debugDataSender.sendUDPPacket("Used memory: " + Long.toString((runtime.totalMemory() - runtime.freeMemory())), cycleCount.longValue());
            debugDataSender.sendUDPPacket("Free memory: " + Long.toString(runtime.freeMemory()), cycleCount.longValue());
            debugDataSender.sendUDPPacket("Total memory: " + Long.toString(runtime.totalMemory()), cycleCount.longValue());
        }
        for (MonitorDAO monitorDAO : myMonitorDAOList) {
            // @TODO: Should we catch / log the possible Exception, or just let it fly?
            monitorDAO.openTransactionStore(Long.toString(cycleCount.longValue()) + "-" + collectorData.getCollectorId());
        }
        // iterate over devices
        for (MonitorDataBlock block : dataBlocks) {
            myLogger.log(AcsLogLevel.DEBUG, "MonitorDataBlock for device " + block.componentName + " contains " + block.monitorBlobs.length + " MonitorBlobs");
            // iterate over properties
            for (MonitorBlob blob : block.monitorBlobs) {
                BlobData blobData = null;
                try {
                    String propertyName = blob.propertyName;
                    String propertyNameSimple = propertyName.substring(propertyName.indexOf(':') + 1);
                    // TODO: Shouldn't we pass propertyName instead of propertyNameSimple?
                    List<MonitorPointTimeSeries> containerList = anyExtractor.extractData(blob.blobDataSeq, propertyNameSimple);
                    // iterate over expanded logical properties
                    for (int index = 0; index < containerList.size(); index++) {
                        MonitorPointTimeSeries container = containerList.get(index);
                        // The serial number by default comes from the device, 
                        // but it can be overwritten for a monitor point.
                        // In Alma this is done for correlator properties.
                        String serialNumber = block.deviceSerialNumber;
                        if (blob.propertySerialNumber != null) {
                            if (blob.propertySerialNumber.length == 1) {
                                // One SN per baci property, even if it expands to multiple monitor points.
                                serialNumber = blob.propertySerialNumber[0];
                            } else if (blob.propertySerialNumber.length > index) {
                                serialNumber = blob.propertySerialNumber[index];
                            } else if (blob.propertySerialNumber.length > 0) {
                                this.myLogger.warning("Underspecified MonitorBlob#propertySerialNumber for " + blob.propertyName);
                            }
                        }
                        myLogger.log(AcsLogLevel.DEBUG, "Handling data for property " + blob.propertyName);
                        blobData = createBlobData(block, blob, container, propertyNameSimple, serialNumber, myLogger);
                        if (blobData.getDataSize() > 0) {
                            insertCount++;
                            // hand over our blob data to the DAO(s)
                            storeData(blobData);
                        }
                    }
                } catch (Exception e) {
                    if (!this.loggedFailedStore.contains(blob.propertyName)) {
                        this.loggedFailedStore.add(blob.propertyName);
                        // @TODO check if http://jira.alma.cl/browse/COMP-4512 can be closed
                        String msg = "Problem when handling property [" + blob.propertyName + "]. " + "The data cache for this property in collector [" + collectorData.getCollectorId() + "] will be cleared, the data is NOT stored. ";
                        myLogger.log(Level.WARNING, msg, e);
                        // unclear if we want this log. If so, it should be included in the above log,
                        // to avoid spreading the info over many log records that won't be adjacent in jlog.
                        // see alma.archive.tmcdb.DAO.ComponentData.toString() where currently the clob data is excluded.
                        myLogger.log(Level.WARNING, "The data contained in the data cache: " + blobData);
                    } else {
                    // RK: Matthias suggested we log this too
                    // HSO commented it out again, because now instead we log this AcsJStoreFailureEx
                    // directly in alma.archive.tmcdb.DAO.MonitorDAOImpl.store(ComponentData) at level FINER
                    // myLogger.log(Level.WARNING,
                    // "Repeat of problem when handling property ["
                    // + blob.propertyName + "]", e);
                    }
                }
            }
        // end loop over properties of a single device
        }
        // close the transaction
        for (MonitorDAO monitorDAO : myMonitorDAOList) {
            try {
                myLogger.fine("myMonitorDAO.closeTransactionStore() for: " + dataBlocks.length + " MonitorDataBlocks from collector " + collector.name());
                monitorDAO.closeTransactionStore();
            } catch (Exception ex) {
                myLogger.log(Level.WARNING, "Exception caught. Some monitoring data couldn't be archived", ex);
            }
        }
    }
    return insertCount;
}
Also used : MonitorBlob(alma.TMCDB.MonitorBlob) MonitorDAO(alma.acs.monitoring.DAO.MonitorDAO) MonitorDataBlock(alma.TMCDB.MonitorDataBlock) MonitorPointTimeSeries(alma.acs.monitoring.MonitorPointTimeSeries) UnknownHostException(java.net.UnknownHostException)

Aggregations

MonitorDAO (alma.acs.monitoring.DAO.MonitorDAO)2 MonitorBlob (alma.TMCDB.MonitorBlob)1 MonitorDataBlock (alma.TMCDB.MonitorDataBlock)1 MonitorPointTimeSeries (alma.acs.monitoring.MonitorPointTimeSeries)1 TestBlobberPlugin (alma.acs.monitoring.blobber.TestBlobberWorker.TestBlobberPlugin)1 UnknownHostException (java.net.UnknownHostException)1 Logger (java.util.logging.Logger)1