Ejemplo n.º 1
0
    def updateTomcatCode(self, kwargs):
        valid_filetypes = [ 'zip', 'tar', 'git' ]
        exp_params = [('filetype', is_in_list(valid_filetypes)),
                      ('codeVersionId', is_string),
                      ('file', is_uploaded_file, None),
                      ('revision', is_string, '')]
        try:
            filetype, codeVersionId, file, revision = check_arguments(exp_params, kwargs)
            if filetype != 'git' and not file:
                raise Exception("The '%s' filetype requires an uploaded file" % filetype)
            elif filetype == 'git' and not revision:
                raise Exception("The 'git' filetype requires the 'revision' parameter")
        except Exception as ex:
            return HttpErrorResponse("%s" % ex)

        if filetype == 'zip':
            source = zipfile.ZipFile(file.file, 'r')
        elif filetype == 'tar':
            source = tarfile.open(fileobj=file.file)
        elif filetype == 'git':
            source = git.DEFAULT_CODE_REPO

        target_dir = join(self.VAR_CACHE, 'tomcat_instance', 'webapps', codeVersionId)
        if exists(target_dir):
            rmtree(target_dir)

        if filetype == 'git':
            subdir = str(self.SERVICE_ID)
            self.logger.debug("git_enable_revision('%s', '%s', '%s', '%s')" %
                    (target_dir, source, revision, subdir))
            git.git_enable_revision(target_dir, source, revision, subdir)
        else:
            source.extractall(target_dir)

        return HttpJsonResponse()
Ejemplo n.º 2
0
    def updatePHPCode(self, kwargs):

        if 'filetype' not in kwargs:
            return HttpErrorResponse(AgentException(
                AgentException.E_ARGS_MISSING, 'filetype').message)
        filetype = kwargs.pop('filetype')

        if 'codeVersionId' not in kwargs:
            return HttpErrorResponse(AgentException(
                AgentException.E_ARGS_MISSING, 'codeVersionId').message)
        codeVersionId = kwargs.pop('codeVersionId')

        if 'file' not in kwargs:
            return HttpErrorResponse(AgentException(
                AgentException.E_ARGS_MISSING, 'file').message)
        file = kwargs.pop('file')

        if filetype != 'git' and not isinstance(file, FileUploadField):
            return HttpErrorResponse(AgentException(
                AgentException.E_ARGS_INVALID, detail='"file" should be a file').message)
        else:
            revision = file

        if len(kwargs) != 0:
            return HttpErrorResponse(AgentException(
                AgentException.E_ARGS_UNEXPECTED, kwargs.keys()).message)

        if filetype == 'zip':
            source = zipfile.ZipFile(file.file, 'r')
        elif filetype == 'tar':
            source = tarfile.open(fileobj=file.file)
        elif filetype == 'git':
            source = git.DEFAULT_CODE_REPO
        else:
            return HttpErrorResponse('Unknown archive type ' + str(filetype))

        if not exists(join(self.VAR_CACHE, 'www')):
            makedirs(join(self.VAR_CACHE, 'www'))

        target_dir = join(self.VAR_CACHE, 'www', codeVersionId)
        if exists(target_dir):
            rmtree(target_dir)

        if filetype == 'git':
            target_dir = join(self.VAR_CACHE, 'www')
            self.logger.debug("git_enable_revision('%s', '%s', '%s')" % (target_dir, source, revision))
            git.git_enable_revision(target_dir, source, revision)
        else:
            source.extractall(target_dir)

        # Fix session handlers
        self.fix_session_handlers(target_dir)

        return HttpJsonResponse()
Ejemplo n.º 3
0
    def updatePHPCode(self, kwargs):

        if 'filetype' not in kwargs:
            return HttpErrorResponse(
                AgentException(AgentException.E_ARGS_MISSING,
                               'filetype').message)
        filetype = kwargs.pop('filetype')

        if 'codeVersionId' not in kwargs:
            return HttpErrorResponse(
                AgentException(AgentException.E_ARGS_MISSING,
                               'codeVersionId').message)
        codeVersionId = kwargs.pop('codeVersionId')

        if 'file' not in kwargs:
            return HttpErrorResponse(
                AgentException(AgentException.E_ARGS_MISSING, 'file').message)
        file = kwargs.pop('file')

        if filetype != 'git' and not isinstance(file, FileUploadField):
            return HttpErrorResponse(
                AgentException(AgentException.E_ARGS_INVALID,
                               detail='"file" should be a file').message)

        if len(kwargs) != 0:
            return HttpErrorResponse(
                AgentException(AgentException.E_ARGS_UNEXPECTED,
                               kwargs.keys()).message)

        if filetype == 'zip': source = zipfile.ZipFile(file.file, 'r')
        elif filetype == 'tar': source = tarfile.open(fileobj=file.file)
        elif filetype == 'git': source = git.DEFAULT_CODE_REPO
        else: return HttpErrorResponse('Unknown archive type ' + str(filetype))

        if not exists(join(self.VAR_CACHE, 'www')):
            makedirs(join(self.VAR_CACHE, 'www'))

        target_dir = join(self.VAR_CACHE, 'www', codeVersionId)
        if exists(target_dir):
            rmtree(target_dir)

        if filetype == 'git':
            target_dir = join(self.VAR_CACHE, 'www')
            self.logger.debug("git_enable_revision('%s', '%s', '%s')" %
                              (target_dir, source, codeVersionId))
            git.git_enable_revision(target_dir, source, codeVersionId)
        else:
            source.extractall(target_dir)

        # Fix session handlers
        self.fix_session_handlers(target_dir)

        return HttpJsonResponse()
Ejemplo n.º 4
0
    def update_code(self, kwargs):
        valid_filetypes = [ 'zip', 'tar', 'git' ]
        exp_params = [('filetype', is_in_list(valid_filetypes)),
                      ('codeVersionId', is_string),
                      ('file', is_uploaded_file, None),
                      ('revision', is_string, '')]
        try:
            filetype, codeVersionId, file, revision = check_arguments(exp_params, kwargs)
            if filetype != 'git' and not file:
                raise Exception("The '%s' filetype requires an uploaded file" % filetype)
            elif filetype == 'git' and not revision:
                raise Exception("The 'git' filetype requires the 'revision' parameter")
        except Exception as ex:
            return HttpErrorResponse("%s" % ex)

        self.logger.info("Updating code to version '%s'" % codeVersionId)

        if filetype == 'zip':
            source = zipfile.ZipFile(file.file, 'r')
        elif filetype == 'tar':
            source = tarfile.open(fileobj=file.file)
        elif filetype == 'git':
            source = git.DEFAULT_CODE_REPO

        # kill all scripts that may still be running
        if self.processes:
            self._kill_all_processes()
            self.processes = {}

        target_dir = self.CODE_DIR

        if exists(target_dir):
            rmtree(target_dir)

        if filetype == 'git':
            subdir = str(self.SERVICE_ID)
            self.logger.debug("git_enable_revision('%s', '%s', '%s', '%s')" %
                    (target_dir, source, revision, subdir))
            git.git_enable_revision(target_dir, source, revision, subdir)
        else:
            source.extractall(target_dir)

        self.logger.info("Code updated, executing the 'init' command")

        # every time a new code tarball is activated, execute the init.sh script
        self._execute_script('init')

        return HttpJsonResponse()
Ejemplo n.º 5
0
    def test_07_git_enable_revision(self):
        target_dir = tempfile.mkdtemp()
        repo = git.git_create_tmp_repo()
        rev = git.git_code_version(repo)

        dest_dir = git.git_enable_revision(target_dir, repo, rev)

        self.assertEquals(rev, os.path.basename(dest_dir))
Ejemplo n.º 6
0
    def test_07_git_enable_revision(self):
        target_dir = tempfile.mkdtemp()
        repo = git.git_create_tmp_repo()
        rev = git.git_code_version(repo) 

        dest_dir = git.git_enable_revision(target_dir, repo, rev)

        self.assertEquals(rev, os.path.basename(dest_dir))
Ejemplo n.º 7
0
    def update_code(self, kwargs):

        if 'filetype' not in kwargs:
            return HttpErrorResponse(AgentException(
                AgentException.E_ARGS_MISSING, 'filetype').message)
        filetype = kwargs.pop('filetype')

        if 'codeVersionId' not in kwargs:
            return HttpErrorResponse(AgentException(
                AgentException.E_ARGS_MISSING, 'codeVersionId').message)
        codeVersionId = kwargs.pop('codeVersionId')

        if 'file' not in kwargs:
            return HttpErrorResponse(AgentException(
                AgentException.E_ARGS_MISSING, 'file').message)
        file = kwargs.pop('file')

        if filetype != 'git' and not isinstance(file, FileUploadField):
            return HttpErrorResponse(AgentException(
                AgentException.E_ARGS_INVALID, detail='"file" should be a file').message)
        else:
            revision = file

        self.logger.info("Updating code to version '%s'" % codeVersionId)

        if len(kwargs) != 0:
            return HttpErrorResponse(AgentException(
                AgentException.E_ARGS_UNEXPECTED, kwargs.keys()).message)

        if filetype == 'zip':
            source = zipfile.ZipFile(file.file, 'r')
        elif filetype == 'tar':
            source = tarfile.open(fileobj=file.file)
        elif filetype == 'git':
            source = git.DEFAULT_CODE_REPO
        else:
            return HttpErrorResponse('Unknown archive type ' + str(filetype))

        # kill all scripts that may still be running
        if self.processes:
            self._kill_all_processes()
            self.processes = {}

        target_dir = self.CODE_DIR

        if exists(target_dir):
            rmtree(target_dir)

        if filetype == 'git':
            self.logger.debug("git_enable_revision('%s', '%s', '%s')" %
                    (self.VAR_CACHE, source, revision))
            git_dir = git.git_enable_revision(self.VAR_CACHE, source, revision)
            rename(git_dir, target_dir)
        else:
            source.extractall(target_dir)

        self.logger.info("Code updated, executing the 'init' command")

        # every time a new code tarball is activated, execute the init.sh script
        self._execute_script('init')

        return HttpJsonResponse()