def _test_instance_submit(self): """ Test submitting a bundle from an Instance. Tests all four mechanisms. """ sab_name = 'ISJ_'+uuid.uuid4().hex topo = topology.Topology(sab_name, namespace='myinstancens') s = op.Source(topo, "spl.utility::Beacon", 'tuple<uint64 seq>', params = {'period': 0.02, 'iterations':100}) s.seq = s.output('IterationCount()') f = op.Map('spl.relational::Filter', s.stream, params = {'filter': op.Expression.expression('seq % 2ul == 0ul')}) bb = streamsx.topology.context.submit('BUNDLE', topo, {}) self.assertIn('bundlePath', bb) self.assertIn('jobConfigPath', bb) sc = self.sc instances = sc.get_instances() if len(instances) == 1: instance = instances[0] else: instance = sc.get_instance(os.environ['STREAMS_INSTANCE_ID']) job = instance.submit_job(bb['bundlePath']) self.assertIsInstance(job, Job) self.assertEqual('myinstancens::'+sab_name, job.applicationName) job.cancel() with open(bb['jobConfigPath']) as fp: jc = JobConfig.from_overlays(json.load(fp)) jn = 'JN_'+uuid.uuid4().hex jc.job_name = jn job = instance.submit_job(bb['bundlePath'], jc) self.assertIsInstance(job, Job) self.assertEqual('myinstancens::'+sab_name, job.applicationName) self.assertEqual(jn, job.name) job.cancel() ab = instance.upload_bundle(bb['bundlePath']) self.assertIsInstance(ab, ApplicationBundle) job = ab.submit_job() self.assertIsInstance(job, Job) self.assertEqual('myinstancens::'+sab_name, job.applicationName) job.cancel() jn = 'JN_'+uuid.uuid4().hex jc.job_name = jn job = ab.submit_job(jc) self.assertIsInstance(job, Job) self.assertEqual('myinstancens::'+sab_name, job.applicationName) self.assertEqual(jn, job.name) job.cancel() os.remove(bb['bundlePath']) os.remove(bb['jobConfigPath'])
def _test_instance_submit(self): """ Test submitting a bundle from an Instance. Tests all four mechanisms. """ sab_name = 'ISJ_'+uuid.uuid4().hex topo = topology.Topology(sab_name, namespace='myinstancens') s = op.Source(topo, "spl.utility::Beacon", 'tuple<uint64 seq>', params = {'period': 0.02, 'iterations':100}) s.seq = s.output('IterationCount()') f = op.Map('spl.relational::Filter', s.stream, params = {'filter': op.Expression.expression('seq % 2ul == 0ul')}) bb = streamsx.topology.context.submit('BUNDLE', topo, {}) self.assertIn('bundlePath', bb) self.assertIn('jobConfigPath', bb) sc = self.sc instances = sc.get_instances() if len(instances) == 1: instance = instances[0] else: instance = sc.get_instance(os.environ['STREAMS_INSTANCE_ID']) job = instance.submit_job(bb['bundlePath']) self.assertIsInstance(job, Job) self.assertEqual('myinstancens::'+sab_name, job.applicationName) job.cancel() with open(bb['jobConfigPath']) as fp: jc = JobConfig.from_overlays(json.load(fp)) jn = 'JN_'+uuid.uuid4().hex jc.job_name = jn job = instance.submit_job(bb['bundlePath'], jc) self.assertIsInstance(job, Job) self.assertEqual('myinstancens::'+sab_name, job.applicationName) self.assertEqual(jn, job.name) job.cancel() ab = instance.upload_bundle(bb['bundlePath']) self.assertIsInstance(ab, ApplicationBundle) job = ab.submit_job() self.assertIsInstance(job, Job) self.assertEqual('myinstancens::'+sab_name, job.applicationName) job.cancel() jn = 'JN_'+uuid.uuid4().hex jc.job_name = jn job = ab.submit_job(jc) self.assertIsInstance(job, Job) self.assertEqual('myinstancens::'+sab_name, job.applicationName) self.assertEqual(jn, job.name) job.cancel() os.remove(bb['bundlePath']) os.remove(bb['jobConfigPath'])
def _check_matching(self, jcs): jcf = JobConfig.from_overlays(jcs.as_overlays()) self.assertEqual(jcs.comment, jcf.comment) self.assertEqual(jcs.job_name, jcf.job_name) self.assertEqual(jcs.job_group, jcf.job_group) self.assertEqual(jcs.preload, jcf.preload) self.assertEqual(jcs.data_directory, jcf.data_directory) self.assertEqual(jcs.tracing, jcf.tracing) self.assertEqual(jcs.target_pe_count, jcf.target_pe_count) self.assertEqual(jcs.submission_parameters, jcf.submission_parameters) self.assertEqual(jcs.raw_overlay, jcf.raw_overlay)
def _check_matching(self, jcs): jcf = JobConfig.from_overlays(jcs.as_overlays()) self.assertEqual(jcs.comment, jcf.comment) self.assertEqual(jcs.job_name, jcf.job_name) self.assertEqual(jcs.job_group, jcf.job_group) self.assertEqual(jcs.preload, jcf.preload) self.assertEqual(jcs.data_directory, jcf.data_directory) self.assertEqual(jcs.tracing, jcf.tracing) self.assertEqual(jcs.target_pe_count, jcf.target_pe_count) self.assertEqual(jcs.submission_parameters, jcf.submission_parameters) self.assertEqual(jcs.raw_overlay, jcf.raw_overlay)
def test_from_topology(self): topo = Topology('SabTest', namespace='mynamespace') s = topo.source([1, 2]) es = s.for_each(lambda x: None) cfg = {} jc = JobConfig(job_name='ABCD', job_group='XXG', preload=True) jc.add(cfg) bb = streamsx.topology.context.submit('BUNDLE', topo, cfg) self.assertIn('bundlePath', bb) self.assertIn('jobConfigPath', bb) with open(bb['jobConfigPath']) as json_data: jct = JobConfig.from_overlays(json.load(json_data)) self.assertEqual(jc.job_name, jct.job_name) self.assertEqual(jc.job_group, jct.job_group) self.assertEqual(jc.preload, jct.preload) os.remove(bb['bundlePath']) os.remove(bb['jobConfigPath'])
def test_from_topology(self): topo = Topology('SabTest', namespace='mynamespace') s = topo.source([1,2]) es = s.for_each(lambda x : None) cfg = {} jc = JobConfig(job_name='ABCD', job_group='XXG', preload=True) jc.add(cfg) bb = streamsx.topology.context.submit('BUNDLE', topo, cfg) self.assertIn('bundlePath', bb) self.assertIn('jobConfigPath', bb) with open(bb['jobConfigPath']) as json_data: jct = JobConfig.from_overlays(json.load(json_data)) self.assertEqual(jc.job_name, jct.job_name) self.assertEqual(jc.job_group, jct.job_group) self.assertEqual(jc.preload, jct.preload) os.remove(bb['bundlePath']) os.remove(bb['jobConfigPath'])