Esempio n. 1
0
    def test_get_instance_path_with_dot(self):
        """Tests that getting the instance path works correctly with a '.'."""
        paths = spawn.SpawnPaths('/does/not/exist', 1)
        job, bucket, running = utils.get_instance_path('test.dot.yml', paths)
        self.assertEqual(job, '/does/not/exist/apps/jobs/test.dot')
        self.assertEqual(bucket, '/does/not/exist/running/000000')
        self.assertEqual(running, '/does/not/exist/running/000000/test.dot')

        job, bucket, running = utils.get_instance_path('test.dot', paths)
        self.assertEqual(job, '/does/not/exist/apps/jobs/test.dot')
        self.assertEqual(bucket, '/does/not/exist/running/000000')
        self.assertEqual(running, '/does/not/exist/running/000000/test.dot')
Esempio n. 2
0
    def _on_created(self, path):
        """This is the handler function when files are created."""
        if os.path.basename(path).startswith('.'):
            return

        job, bucket, running = spawn_utils.get_instance_path(path, self.paths)

        _LOGGER.debug('Deleting - (%r, %r)', job, running)

        if not os.path.exists(running):
            _LOGGER.debug('Delete %r failed - does not exist', running)
            return

        fs.rm_safe(running)
        self._nuke(bucket)
        shutil.rmtree(job, ignore_errors=True)
        fs.rm_safe(path)
    def _create_instance(self, path):
        """Create an spawn instance."""
        job, bucket, running = spawn_utils.get_instance_path(path, self.paths)

        _LOGGER.debug('Creating - (%r, %r)', job, running)

        if os.path.exists(running):
            _LOGGER.debug('Create %r failed - already exists', running)
            return

        inst = instance.Instance(path)
        data_dir = os.path.join(job, spawn.JOB_DATA_DIR)

        fs.mkdir_safe(job)
        fs.mkdir_safe(data_dir)

        utils.create_script(
            os.path.join(job, 'run'),
            'spawn.run',
            id=inst.id,
            name=inst.name,
            service_exit=inst.settings.get('service_exit', False),
            **subproc.get_aliases()
        )

        utils.create_script(
            os.path.join(job, 'finish'),
            'spawn.finish',
            id=inst.id,
            stop=inst.settings.get('stop', False),
            reconnect=inst.settings.get('reconnect', False),
            reconnect_timeout=inst.settings.get('reconnect_timeout', 0),
            **subproc.get_aliases()
        )

        with io.open(os.path.join(data_dir, 'manifest'), 'w') as f:
            f.writelines(
                utils.json_genencode(inst.manifest)
            )

        with io.open(os.path.join(job, 'timeout-finish'), 'w') as f:
            f.write(six.text_type(spawn.JOB_FINISH_TIMEOUT))

        fs.symlink_safe(running, job)

        self._scan(bucket)
Esempio n. 4
0
    def _create_instance(self, path):
        """Create an spawn instance."""
        job, bucket, running = spawn_utils.get_instance_path(path, self.paths)

        _LOGGER.debug('Creating - (%r, %r)', job, running)

        if os.path.exists(running):
            _LOGGER.debug('Create %r failed - already exists', running)
            return

        inst = instance.Instance(path)
        data_dir = os.path.join(job, spawn.JOB_DATA_DIR)

        fs.mkdir_safe(job)
        fs.mkdir_safe(data_dir)

        utils.create_script(
            os.path.join(job, 'run'),
            'spawn.run',
            id=inst.id,
            name=inst.name,
            cellapi=self.paths.cellapi_sock,
            zk2fs=self.paths.zk_mirror_dir)

        utils.create_script(
            os.path.join(job, 'finish'),
            'spawn.finish',
            id=inst.id,
            cellapi=self.paths.cellapi_sock,
            cleanup=self.paths.cleanup_dir,
            stop=inst.settings['stop'],
            reconnect=inst.settings['reconnect'],
            reconnect_timeout=inst.settings['reconnect_timeout'])

        with open(os.path.join(data_dir, 'manifest'), 'w') as f:
            json.dump(inst.manifest, f)

        with open(os.path.join(job, 'timeout-finish'), 'w') as f:
            f.write(str(spawn.JOB_FINISH_TIMEOUT))

        fs.symlink_safe(running, job)

        self._scan(bucket)