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
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())
Ejemplo n.º 3
0
    def extract_file(self, path, location=None):
        """
        Extract the specified file from the archive into the Domain Home directory.
        :param path: the path into the archive
        :param location: the location to which to extract the file
        :return: path to the extracted file
        :raises: BundleAwareException of the appropriate type: if an error occurs
        """
        _method_name = 'extract_file'

        self.__logger.entering(path,
                               class_name=self.__class_name,
                               method_name=_method_name)
        try:
            if location is None:
                result = self.__archive_file.extractFile(
                    path, self.__domain_home)
            else:
                extract_location = FileUtils.getCanonicalFile(File(location))
                result = self.__archive_file.extractFile(
                    path, extract_location, True)
        except (IllegalArgumentException, WLSDeployArchiveIOException), e:
            ex = exception_helper.create_exception(self.__exception_type,
                                                   "WLSDPLY-19303",
                                                   path,
                                                   self.__archive_file_name,
                                                   e.getLocalizedMessage(),
                                                   error=e)
            self.__logger.throwing(ex,
                                   class_name=self.__class_name,
                                   method_name=_method_name)
            raise ex
    def _add_custom_configuration_to_archive(self, model_name, model_value, location):
        """
        Add custom configuration file to the archive. Modify the configuration file name in the model.
        :param model_name: attribute name of the custom configuration
        :param model_value: value containing the custom configuration file name
        :param location: context containing current location information
        :return: update custom configuration file name
        """
        _method_name = '_add_custom_configuration_to_archive'
        temp = LocationContext()
        temp.append_location(model_constants.COHERENCE_CLUSTER_SYSTEM_RESOURCE)
        cluster_name = location.get_name_for_token(self._aliases.get_name_token(temp))
        _logger.entering(cluster_name, model_name, model_value, class_name=_class_name, method_name=_method_name)
        new_name = model_value
        if model_value is not None:
            archive_file = self._model_context.get_archive_file()
            file_name_path = self._convert_path(model_value)
            config_file = None
            try:
                config_file = FileUtils.getCanonicalFile(File(file_name_path))
            except (IOException, SecurityException), se:
                _logger.warning('WLSDPLY-06314', cluster_name, file_name_path, se.getLocalizedMessage(),
                                class_name=_class_name, method_name=_method_name)
                new_name = None

            if file is not None:
                try:
                    new_name = archive_file.addCoherenceConfigFile(cluster_name, config_file)
                    _logger.finer('WLSDPLY-06315', file_name_path, class_name=_class_name, method_name=_method_name)
                except (IllegalArgumentException, WLSDeployArchiveIOException), wioe:
                    _logger.warning('WLSDPLY-06316', cluster_name, file_name_path, wioe.getLocalizedMessage(),
                                    class_name=_class_name, method_name=_method_name)
                    new_name = None
Ejemplo n.º 5
0
    if model_file_name is None:
        add_to_archive = True
        try:
            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():