Пример #1
0
	def startAnalyticsBuilderCorrelator(self, blockSourceDir=None, Xclock=True, numWorkers=4, injectBlocks = True, **kwargs):
		"""
		Start a correlator with the EPL for Analytics Builder loaded.
		:param blockSourceDir: A location of blocks to include, or a list of locations
		:param Xclock: Externally clock correlator (on by default).
		:param numWorkers: Number of workers for Analytics Builder runtime (4 by default).
		:param injectBlocks: if false, don't inject the actual block EPL (use if there are dependencies), returns blockOutput directory. Also skips applicationInitialized call.
		:param \**kwargs: extra kwargs are passed to startCorrelator
		"""

		# Build and extract the block extension:
		if blockSourceDir == None: blockSourceDir = self.input
		if not isinstance(blockSourceDir, list):
			blockSourceDir = [blockSourceDir]
		blockOutput = self.output+'/block-output-'
		blockOutputDirs=[]
		blockSrcOutput = self.output+'/block-src-'
		for blockDir in blockSourceDir:
			blockOutput=blockSrcOutput + os.path.basename(blockDir)
			self.buildExtensionDirectory(blockDir, blockOutput)
			blockOutputDirs.append(Path(blockOutput))
		# Start the correlator:
		corr = CorrelatorHelper(self)
		arguments=kwargs.get('arguments', [])
		arguments.append(f'-DanalyticsBuilder.numWorkerThreads={numWorkers}')
		arguments.append(f'-DanalyticsBuilder.timedelay_secs=0.1')
		kwargs['arguments']=arguments
		logfile=kwargs.get('logfile', 'correlator.log')
		kwargs['logfile']=logfile
		corr.start(Xclock=Xclock, **kwargs)
		corr.logfile = logfile
		corr.injectEPL([self.project.APAMA_HOME+'/monitors/'+i+'.mon' for i in ['ScenarioService', 'data_storage/MemoryStore', 'JSONPlugin', 'AnyExtractor', 'ManagementImpl', 'Management', 'ConnectivityPluginsControl', 'ConnectivityPlugins', 'HTTPClientEvents', 'AutomaticOnApplicationInitialized']])
		corr.injectCDP(self.project.ANALYTICS_BUILDER_SDK+'/block-api/framework/analyticsbuilder-framework.cdp')
		self.injectCumulocityEvents(corr)
		corr.injectCDP(self.project.ANALYTICS_BUILDER_SDK + '/block-api/framework/cumulocity-inventoryLookup-events.cdp')
		corr.injectEPL(self.project.ANALYTICS_BUILDER_SDK+'/testframework/resources/TestHelpers.mon')


		for blockOutput in blockOutputDirs:
			corr.send(sorted(list(blockOutput.rglob('*.evt'))))
		self.analyticsBuilderCorrelator = corr
		corr.receive('output.evt', channels=['TestOutput'])
		corr.injectTestEventLogger(channels=['TestOutput'])

		if not injectBlocks:
			return blockOutputDirs

		self.preInjectBlock(corr)

		# inject block files:
		for blockOutput in blockOutputDirs:
			corr.injectEPL(sorted(list(blockOutput.rglob('*.mon'))))
			corr.send(sorted(list(blockOutput.rglob('*.evt'))))
		# now done
		corr.sendEventStrings('com.apama.connectivity.ApplicationInitialized()')
		corr.flush(count=10)
		return corr
Пример #2
0
    def startAnalyticsBuilderCorrelator(self,
                                        blockSourceDir=None,
                                        Xclock=True,
                                        numWorkers=4,
                                        **kwargs):
        """
		Start a correlator with the EPL for Analytics Builder loaded.
		:param blockSourceDir: A location of blocks to include.
		:param Xclock: Externally clock correlator (on by default).
		:param numWorkers: Number of workers for Analytics Builder runtime (4 by default).
		"""

        # Build and extract the block extension:
        if blockSourceDir == None: blockSourceDir = self.input
        blockOutput = self.output + '/block-output.zip'
        self.runAnalyticsBuilderScript([
            'build', 'extension', '--input', blockSourceDir, '--output',
            blockOutput
        ])
        with zipfile.ZipFile(blockOutput, 'r') as zf:
            blockOutput = Path(self.output + '/block-output/')
            os.mkdir(blockOutput)
            zf.extractall(blockOutput)

        # Start the correlator:
        corr = CorrelatorHelper(self)
        arguments = kwargs.get('arguments', [])
        arguments.append(f'-DanalyticsBuilder.numWorkerThreads={numWorkers}')
        kwargs['arguments'] = arguments
        logfile = kwargs.get('logfile', 'correlator.log')
        kwargs['logfile'] = logfile
        corr.start(Xclock=Xclock, **kwargs)
        corr.logfile = logfile
        corr.injectEPL([
            self.project.APAMA_HOME + '/monitors/' + i + '.mon' for i in [
                'ScenarioService', 'data_storage/MemoryStore', 'JSONPlugin',
                'AnyExtractor', 'ManagementImpl', 'Management',
                'ConnectivityPluginsControl', 'ConnectivityPlugins',
                'HTTPClientEvents', 'AutomaticOnApplicationInitialized'
            ]
        ])
        corr.injectCDP(self.project.ANALYTICS_BUILDER_SDK +
                       '/block-api/framework/analyticsbuilder-framework.cdp')
        self.injectCumulocityEvents(corr)
        corr.injectCDP(
            self.project.ANALYTICS_BUILDER_SDK +
            '/block-api/framework/cumulocity-inventoryLookup-events.cdp')
        corr.injectEPL(self.project.ANALYTICS_BUILDER_SDK +
                       '/testframework/resources/TestHelpers.mon')

        # inject block files:
        corr.injectEPL(sorted(list(blockOutput.rglob('*.mon'))))
        corr.send(sorted(list(blockOutput.rglob('*.evt'))))

        # now done
        corr.sendEventStrings(
            'com.apama.connectivity.ApplicationInitialized()')
        corr.flush(10)
        self.analyticsBuilderCorrelator = corr
        corr.receive('output.evt', channels=['TestOutput'])
        corr.injectTestEventLogger(channels=['TestOutput'])

        return corr