コード例 #1
0
def __persist_model(model, model_context):
    """
    Save the model to the specified model file name or to the archive if the file name was not specified.
    :param model: the model to save
    :param model_context: the model context
    :raises DiscoverException: if an error occurs while create a temporary file for the model
                               or while adding it to the archive
    :raises TranslateException: if an error occurs while serializing the model or writing it to disk
    """
    _method_name = '__persist_model'

    __logger.entering(class_name=_class_name, method_name=_method_name)

    add_to_archive = False
    model_file_name = model_context.get_model_file()
    model_file = FileUtils.getCanonicalFile(File(model_file_name))
    if model_file_name is None:
        add_to_archive = True
    try:
        model_translator.PythonToFile(model.get_model()).write_to_file(model_file.getAbsolutePath())
    except TranslateException, ex:
        # Jython 2.2.1 does not support finally so use this like a finally block...
        if add_to_archive and not model_file.delete():
            model_file.deleteOnExit()
        raise ex
コード例 #2
0
def persist_model(model_context, model_dictionary):
    """
    If environment variable __WLSDEPLOY_STORE_MODEL__ is set, save the specified model.
    If the variable's value starts with a slash, save to that file, otherwise use a default location.
    :param model_context: the model context
    :param model_dictionary: the model to be saved
    """
    _method_name = 'persist_model'

    if check_persist_model():
        store_value = os.environ.get(_store_environment_variable)

        if store_value.startswith('/') or store_value.startswith('\\'):
            file_path = store_value
        elif model_context.get_domain_home() is not None:
            file_path = model_context.get_domain_home() + os.sep + 'wlsdeploy' + os.sep + 'domain_model.json'
        else:
            file_dir = FileUtils.createTempDirectory('wlsdeploy')
            file_path = File(file_dir, 'domain_model.json').getAbsolutePath()

        __logger.info('WLSDPLY-01650', file_path, class_name=_class_name, method_name=_method_name)

        persist_dir = path_utils.get_parent_directory(file_path)
        if not os.path.exists(persist_dir):
            os.makedirs(persist_dir)

        model_file = FileUtils.getCanonicalFile(File(file_path))
        model_translator.PythonToFile(model_dictionary).write_to_file(model_file.getAbsolutePath())
コード例 #3
0
            domain_name = model_context.get_domain_name()
            model_file = File.createTempFile(domain_name,
                                             '.yaml').getCanonicalFile()
            model_file_name = model_context.get_domain_name() + '.yaml'
        except (IllegalArgumentException, IOException), ie:
            ex = exception_helper.create_discover_exception(
                'WLSDPLY-06008', ie.getLocalizedMessage(), error=ie)
            __logger.throwing(ex,
                              class_name=_class_name,
                              method_name=_method_name)
            raise ex
    else:
        model_file = FileUtils.getCanonicalFile(File(model_file_name))

    try:
        model_translator.PythonToFile(model.get_model()).write_to_file(
            model_file.getAbsolutePath())
    except TranslateException, ex:
        # Jython 2.2.1 does not support finally so use this like a finally block...
        if add_to_archive and not model_file.delete():
            model_file.deleteOnExit()
        raise ex

    if add_to_archive:
        try:
            archive_file = model_context.get_archive_file()
            archive_file.addModel(model_file, model_file_name)
            if not model_file.delete():
                model_file.deleteOnExit()
        except (WLSDeployArchiveIOException,
                IllegalArgumentException), arch_ex:
            ex = exception_helper.create_discover_exception(