Beispiel #1
0
    def _resolve_targeting_type(self):
        """
        Determine the targeting type based on the value in the definition.
        Check for problems or incompatibilities.
        :return: the matching TargetType enum value
        :raises: ClaException: if there are problems or incompatibilities
        """
        _method_name = '_resolve_targeting_type'

        if 'targeting' not in self._domain_typedef:
            return None

        targeting_text = self._domain_typedef['targeting']

        # there are no valid targeting types for version 12c and up
        if self.wls_helper.is_set_server_groups_supported():
            ex = exception_helper.create_cla_exception(
                'WLSDPLY-12311', targeting_text, self._domain_typedef_filename,
                self.wls_helper.get_weblogic_version())
            self._logger.throwing(ex,
                                  class_name=self.__class_name,
                                  method_name=_method_name)
            raise ex

        # if specified, targeting must be one of the known types
        if targeting_text not in TargetingType:
            ex = exception_helper.create_cla_exception(
                'WLSDPLY-12312', targeting_text, self._domain_typedef_filename)
            self._logger.throwing(ex,
                                  class_name=self.__class_name,
                                  method_name=_method_name)
            raise ex

        return TargetingType[targeting_text]
def process_online_args(optional_arg_map):
    """
    Determine if we are executing in online mode and if so, validate/prompt for the necessary parameters.
    :param optional_arg_map: the optional arguments map
    :return: the WLST mode
    :raises CLAException: if an error occurs reading input from the user
    """
    _method_name = 'process_online_args'

    mode = WlstModes.OFFLINE
    if CommandLineArgUtil.ADMIN_URL_SWITCH in optional_arg_map:
        if CommandLineArgUtil.ADMIN_USER_SWITCH not in optional_arg_map:
            try:
                username = getcreds.getuser('WLSDPLY-09001')
            except IOException, ioe:
                ex = exception_helper.create_cla_exception('WLSDPLY-09002', ioe.getLocalizedMessage(), error=ioe)
                ex.setExitCode(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE)
                __logger.throwing(ex, class_name=_class_name, method_name=_method_name)
                raise ex
            optional_arg_map[CommandLineArgUtil.ADMIN_USER_SWITCH] = username

        if CommandLineArgUtil.ADMIN_PASS_SWITCH not in optional_arg_map:
            try:
                password = getcreds.getpass('WLSDPLY-09003')
            except IOException, ioe:
                ex = exception_helper.create_cla_exception('WLSDPLY-09004', ioe.getLocalizedMessage(), error=ioe)
                ex.setExitCode(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE)
                __logger.throwing(ex, class_name=_class_name, method_name=_method_name)
                raise ex
            optional_arg_map[CommandLineArgUtil.ADMIN_PASS_SWITCH] = String(password)
Beispiel #3
0
    def _print_model_folder_sample(self, model_path_tokens,
                                   valid_section_folder_keys, control_option):
        """
        Prints a model sample for a folder in a model, when more than just the section_name[:] is provided.
        :param model_path_tokens: a Python list of path elements built from model path
        :param valid_section_folder_keys: A list of valid folder names for the model section in the path
        :param control_option: A command-line switch that controls what is output to STDOUT
        """
        _method_name = '_print_model_folder_sample'

        section_name = model_path_tokens[0]
        top_folder = model_path_tokens[1]
        if top_folder not in valid_section_folder_keys:
            ex = exception_helper.create_cla_exception(
                'WLSDPLY-10110', section_name + ':', top_folder,
                ', '.join(valid_section_folder_keys))
            self._logger.throwing(ex,
                                  class_name=_class_name,
                                  method_name=_method_name)
            raise ex

        print("")

        # write the parent folders, with indention and any name folders included

        indent = 0
        model_location = LocationContext()
        for token in model_path_tokens:
            if indent > 0:
                code, message = self._alias_helper.is_valid_model_folder_name(
                    model_location, token)
                if code != ValidationCodes.VALID:
                    ex = exception_helper.create_cla_exception(
                        "WLSDPLY-05027", message)
                    self._logger.throwing(ex,
                                          class_name=_class_name,
                                          method_name=_method_name)
                    raise ex
                model_location.append_location(token)

            _print_indent(token + ":", indent)
            indent += 1

            if self._has_multiple_folders(model_location):
                short_name = self._get_short_name(model_location)
                name = "'" + short_name + "-1'"
                _print_indent(name + ":", indent)
                indent += 1

        # list the attributes and folders, as specified

        if model_help_utils.show_attributes(control_option):
            # Print the attributes associated with location context
            self._print_attributes_sample(model_location, indent)

        if model_help_utils.show_folders(control_option):
            self._print_subfolders_sample(model_location, control_option,
                                          indent)

        return
Beispiel #4
0
    def _validate_admin_url_arg(self, value):
        method_name = '_validate_admin_url_arg'

        if value is None or len(value) == 0:
            ex = exception_helper.create_cla_exception('WLSDPLY-01611')
            ex.setExitCode(self.ARG_VALIDATION_ERROR_EXIT_CODE)
            self._logger.throwing(ex,
                                  class_name=self._class_name,
                                  method_name=method_name)
            raise ex

        #
        # Because we cannot use java.net.URL due to it not understanding t3 and other RMI protocols,
        # do the best we can to validate the structure...
        #
        url_separator_index = value.find('://')
        if not url_separator_index > 0:
            ex = exception_helper.create_cla_exception('WLSDPLY-01612', value)
            ex.setExitCode(self.ARG_VALIDATION_ERROR_EXIT_CODE)
            self._logger.throwing(ex,
                                  class_name=self._class_name,
                                  method_name=method_name)
            raise ex

        try:
            JURI(value)
        except JURISyntaxException, use:
            ex = exception_helper.create_cla_exception(
                'WLSDPLY-01613', value, use.getLocalizedMessage(), error=use)
            ex.setExitCode(self.ARG_VALIDATION_ERROR_EXIT_CODE)
            self._logger.throwing(ex,
                                  class_name=self._class_name,
                                  method_name=method_name)
            raise ex
Beispiel #5
0
    def _validate_target_version_arg(self, value):
        method_name = '_validate_target_version_arg'

        # Try our best to determine if this is a legitimate WLS version number.
        # At the end of the day, the user can still enter a non-existent version number
        # like 845.283.412 and this code will not invalidate it because we cannot
        # predict future version numbers...
        #
        if value is None or len(value) == 0:
            ex = exception_helper.create_cla_exception('WLSDPLY-01627')
            ex.setExitCode(self.ARG_VALIDATION_ERROR_EXIT_CODE)
            self._logger.throwing(ex,
                                  class_name=self._class_name,
                                  method_name=method_name)
            raise ex
        elif not JVersionUtils.isVersion(value):
            ex = exception_helper.create_cla_exception('WLSDPLY-01628', value)
            ex.setExitCode(self.ARG_VALIDATION_ERROR_EXIT_CODE)
            self._logger.throwing(ex,
                                  class_name=self._class_name,
                                  method_name=method_name)
            raise ex
        else:
            wl_helper = WebLogicHelper(self._logger, value)
            if not wl_helper.is_supported_weblogic_version():
                ex = exception_helper.create_cla_exception(
                    'WLSDPLY-01629', value)
                ex.setExitCode(self.ARG_VALIDATION_ERROR_EXIT_CODE)
                self._logger.throwing(ex,
                                      class_name=self._class_name,
                                      method_name=method_name)
                raise ex
        return
Beispiel #6
0
    def _validate_print_usage_arg(self, value):
        method_name = '_validate_print_usage_arg'

        if value is None or len(value) == 0:
            ex = exception_helper.create_cla_exception('WLSDPLY-01619')
            ex.setExitCode(self.ARG_VALIDATION_ERROR_EXIT_CODE)
            self._logger.throwing(ex,
                                  class_name=self._class_name,
                                  method_name=method_name)
            raise ex
        matcher = MODEL_PATH_PATTERN.match(value)
        if not matcher:
            ex = exception_helper.create_cla_exception('WLSDPLY-01633',
                                                       self.PRINT_USAGE_SWITCH,
                                                       value)
            ex.setExitCode(self.ARG_VALIDATION_ERROR_EXIT_CODE)
            self._logger.throwing(ex,
                                  class_name=self._class_name,
                                  method_name=method_name)
            raise ex
        section_name = matcher.group(1)
        if section_name not in KNOWN_TOPLEVEL_MODEL_SECTIONS:
            ex = exception_helper.create_cla_exception(
                'WLSDPLY-01634', self.PRINT_USAGE_SWITCH, value, section_name,
                KNOWN_TOPLEVEL_MODEL_SECTIONS)
            ex.setExitCode(self.ARG_VALIDATION_ERROR_EXIT_CODE)
            self._logger.throwing(ex,
                                  class_name=self._class_name,
                                  method_name=method_name)
            raise ex
        return value
def __process_archive_filename_arg(required_arg_map):
    """
    Validate the archive file name and load the archive file object.
    :param required_arg_map: the required arguments map
    :raises CLAException: if a validation error occurs while loading the archive file object
    """
    _method_name = '__process_archive_filename_arg'

    archive_file_name = required_arg_map[
        CommandLineArgUtil.ARCHIVE_FILE_SWITCH]
    archive_dir_name = path_utils.get_parent_directory(archive_file_name)
    if os.path.exists(archive_dir_name) is False:
        ex = exception_helper.create_cla_exception('WLSDPLY-06026',
                                                   archive_file_name)
        __logger.throwing(ex, class_name=_class_name, method_name=_method_name)
        raise ex
    try:
        archive_file = WLSDeployArchive(archive_file_name)
    except (IllegalArgumentException, IllegalStateException), ie:
        ex = exception_helper.create_cla_exception('WLSDPLY-06013',
                                                   _program_name,
                                                   archive_file_name,
                                                   ie.getLocalizedMessage(),
                                                   error=ie)
        __logger.throwing(ex, class_name=_class_name, method_name=_method_name)
        raise ex
Beispiel #8
0
    def _validate_target_mode_arg(self, value):
        method_name = '_validate_target_mode_arg'

        if value is None or len(value) == 0:
            ex = exception_helper.create_cla_exception('WLSDPLY-01630')
            ex.setExitCode(self.ARG_VALIDATION_ERROR_EXIT_CODE)
            self._logger.throwing(ex, class_name=self._class_name, method_name=method_name)
            raise ex
        elif value.lower() != 'online' and value.lower() != 'offline':
            ex = exception_helper.create_cla_exception('WLSDPLY-01631', value)
            ex.setExitCode(self.ARG_VALIDATION_ERROR_EXIT_CODE)
            self._logger.throwing(ex, class_name=self._class_name, method_name=method_name)
            raise ex
        return
Beispiel #9
0
def __process_print_usage_args(optional_arg_map):
    """
    Validate the -print_usage related arguments.
    :param optional_arg_map: the optional argument map
    :raises: CLAException: if the arguments are not valid
    """
    _method_name = '__process_print_usage_args'

    if CommandLineArgUtil.PRINT_USAGE_SWITCH in optional_arg_map:
        print_usage_path = optional_arg_map[
            CommandLineArgUtil.PRINT_USAGE_SWITCH]
        found_controller_arg = None
        if CommandLineArgUtil.ATTRIBUTES_ONLY_SWITCH in optional_arg_map:
            found_controller_arg = CommandLineArgUtil.ATTRIBUTES_ONLY_SWITCH

        if CommandLineArgUtil.FOLDERS_ONLY_SWITCH in optional_arg_map:
            if found_controller_arg is None:
                found_controller_arg = CommandLineArgUtil.FOLDERS_ONLY_SWITCH
            else:
                ex = exception_helper.create_cla_exception(
                    'WLSDPLY-05401', _program_name,
                    CommandLineArgUtil.PRINT_USAGE_SWITCH,
                    CommandLineArgUtil.FOLDERS_ONLY_SWITCH,
                    found_controller_arg)
                __logger.throwing(ex,
                                  class_name=_class_name,
                                  method_name=_method_name)
                raise ex

        if CommandLineArgUtil.RECURSIVE_SWITCH in optional_arg_map:
            if found_controller_arg is None:
                found_controller_arg = CommandLineArgUtil.RECURSIVE_SWITCH
            else:
                ex = exception_helper.create_cla_exception(
                    'WLSDPLY-05401', _program_name,
                    CommandLineArgUtil.PRINT_USAGE_SWITCH,
                    CommandLineArgUtil.RECURSIVE_SWITCH, found_controller_arg)
                __logger.throwing(ex,
                                  class_name=_class_name,
                                  method_name=_method_name)
                raise ex
        if found_controller_arg is not None:
            __logger.fine('WLSDPLY-05402',
                          _program_name,
                          CommandLineArgUtil.PRINT_USAGE_SWITCH,
                          print_usage_path,
                          found_controller_arg,
                          class_name=_class_name,
                          method_name=_method_name)
    return
    def _validate_validate_method_arg(self, value):
        method_name = '_validate_validate_method_arg'

        if value is None or len(value) == 0:
            ex = exception_helper.create_cla_exception('WLSDPLY-20029')
            ex.setExitCode(self.ARG_VALIDATION_ERROR_EXIT_CODE)
            self._logger.throwing(ex, class_name=self._class_name, method_name=method_name)
            raise ex
        elif value.lower() != 'strict' and value.lower() != 'lax':
            ex = exception_helper.create_cla_exception('WLSDPLY-20030', value, "strict, or lax")
            ex.setExitCode(self.ARG_VALIDATION_ERROR_EXIT_CODE)
            self._logger.throwing(ex, class_name=self._class_name, method_name=method_name)
            raise ex
        return value
Beispiel #11
0
    def _validate_validate_method_arg(self, value):
        method_name = '_validate_validate_method_arg'

        if value is None or len(value) == 0:
            ex = exception_helper.create_cla_exception('WLSDPLY-20029')
            ex.setExitCode(self.ARG_VALIDATION_ERROR_EXIT_CODE)
            self._logger.throwing(ex, class_name=self._class_name, method_name=method_name)
            raise ex
        elif value not in self.VALIDATION_METHODS:
            ex = exception_helper.create_cla_exception('WLSDPLY-20030', value, self.VALIDATION_METHODS)
            ex.setExitCode(self.ARG_VALIDATION_ERROR_EXIT_CODE)
            self._logger.throwing(ex, class_name=self._class_name, method_name=method_name)
            raise ex
        return value
def __process_rcu_args(optional_arg_map, domain_type, domain_typedef):
    """
    Determine if the RCU is needed and validate/prompt for any missing information
    :param optional_arg_map: the optional arguments map
    :param domain_type:      the domain type
    :param domain_typedef:   the domain_typedef data structure
    :raises CLAException:    if an error occurs getting the passwords from the user or arguments are missing
    """
    _method_name = '__process_rcu_args'

    rcu_schema_count = len(domain_typedef.get_rcu_schemas())
    run_rcu = False
    if CommandLineArgUtil.RUN_RCU_SWITCH in optional_arg_map:
        run_rcu = optional_arg_map[CommandLineArgUtil.RUN_RCU_SWITCH]
        if rcu_schema_count == 0:
            __logger.info('WLSDPLY-12402', _program_name, CommandLineArgUtil.RUN_RCU_SWITCH, domain_type)
            del optional_arg_map[CommandLineArgUtil.RUN_RCU_SWITCH]
            return

    if rcu_schema_count > 0:
        if CommandLineArgUtil.RCU_DB_SWITCH in optional_arg_map:
            if CommandLineArgUtil.RCU_PREFIX_SWITCH in optional_arg_map:
                if run_rcu and CommandLineArgUtil.RCU_SYS_PASS_SWITCH not in optional_arg_map:
                    try:
                        password = getcreds.getpass('WLSDPLY-12403')
                    except IOException, ioe:
                        ex = exception_helper.create_cla_exception('WLSDPLY-12404', ioe.getLocalizedMessage(),
                                                                   error=ioe)
                        ex.setExitCode(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE)
                        __logger.throwing(ex, class_name=_class_name, method_name=_method_name)
                        raise ex
                    optional_arg_map[CommandLineArgUtil.RCU_SYS_PASS_SWITCH] = String(password)
                if CommandLineArgUtil.RCU_SCHEMA_PASS_SWITCH not in optional_arg_map:
                    try:
                        password = getcreds.getpass('WLSDPLY-12405')
                    except IOException, ioe:
                        ex = exception_helper.create_cla_exception('WLSDPLY-12406', ioe.getLocalizedMessage(),
                                                                   error=ioe)
                        ex.setExitCode(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE)
                        __logger.throwing(ex, class_name=_class_name, method_name=_method_name)
                        raise ex
                    optional_arg_map[CommandLineArgUtil.RCU_SCHEMA_PASS_SWITCH] = String(password)
            else:
                ex = exception_helper.create_cla_exception('WLSDPLY-12407', _program_name,
                                                           CommandLineArgUtil.RCU_DB_SWITCH,
                                                           CommandLineArgUtil.RCU_PREFIX_SWITCH)
                ex.setExitCode(CommandLineArgUtil.USAGE_ERROR_EXIT_CODE)
                __logger.throwing(ex, class_name=_class_name, method_name=_method_name)
                raise ex
def validate_optional_archive(program_name, optional_arg_map):
    """
    If the archive file was specified on the command line, verify that it exists.
    :param program_name: the name of the calling program, for logging
    :param optional_arg_map: the optional arguments from the command line
    :raises CLAException: if the archive was specified and does not exist
    """
    _method_name = 'validate_optional_archive'

    if CommandLineArgUtil.ARCHIVE_FILE_SWITCH in optional_arg_map:
        archive_file_name = optional_arg_map[
            CommandLineArgUtil.ARCHIVE_FILE_SWITCH]

        try:
            FileUtils.validateExistingFile(archive_file_name)
        except IllegalArgumentException, iae:
            ex = exception_helper.create_cla_exception(
                'WLSDPLY-20014',
                program_name,
                archive_file_name,
                iae.getLocalizedMessage(),
                error=iae)
            ex.setExitCode(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE)
            __logger.throwing(ex,
                              class_name=_class_name,
                              method_name=_method_name)
            raise ex
def validate_variable_file_exists(program_name, argument_map):
    """
    Validate that the variable file(s) exist.
    Assume that the caller allows multiple variables files.
    :param program_name: the name of the tool
    :param argument_map: the program arguments
    """
    method_name = 'validate_variable_file_exists'
    if CommandLineArgUtil.VARIABLE_FILE_SWITCH in argument_map:
        result_files = []  # type: list
        value = argument_map[CommandLineArgUtil.VARIABLE_FILE_SWITCH]
        files = value.split(CommandLineArgUtil.MODEL_FILES_SEPARATOR)
        for file in files:
            try:
                variable_file = FileUtils.validateExistingFile(file)
                result_files.append(variable_file.getAbsolutePath())
            except IllegalArgumentException, iae:
                ex = exception_helper.create_cla_exception(
                    'WLSDPLY-20031',
                    program_name,
                    file,
                    iae.getLocalizedMessage(),
                    error=iae)
                ex.setExitCode(
                    CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE)
                __logger.throwing(ex,
                                  class_name=_class_name,
                                  method_name=method_name)
                raise ex

        argument_map[CommandLineArgUtil.VARIABLE_FILE_SWITCH] = ",".join(
            result_files)
Beispiel #15
0
def __process_model_args(optional_arg_map):
    """
    Determine if the model file was passed separately or requires extraction from the archive.
    :param optional_arg_map: the optional arguments map
    :raises CLAException: if the arguments were not valid or an error occurred extracting the model from the archive
    """
    _method_name = '__process_model_args'

    if CommandLineArgUtil.PRINT_USAGE_SWITCH in optional_arg_map:
        # nothing to do since we are printing help information rather than validating supplied artifacts...
        return

    cla_helper.validate_optional_archive(_program_name, optional_arg_map)
    cla_helper.validate_model_present(_program_name, optional_arg_map)

    something_to_validate = False
    if CommandLineArgUtil.MODEL_FILE_SWITCH in optional_arg_map:
        something_to_validate = True

    if not something_to_validate:
        ex = exception_helper.create_cla_exception(
            'WLSDPLY-05400', _program_name,
            CommandLineArgUtil.PRINT_USAGE_SWITCH,
            CommandLineArgUtil.MODEL_FILE_SWITCH,
            CommandLineArgUtil.ARCHIVE_FILE_SWITCH)
        __logger.throwing(ex, class_name=_class_name, method_name=_method_name)
        raise ex
    return
def __process_args(args):
    """
    Process the command-line arguments.
    :param args: the command-line arguments list
    :raises CLAException: if an error occurs while validating and processing the command-line arguments
    """
    _method_name = '__process_args'

    cla_util = CommandLineArgUtil(_program_name, __required_arguments, __optional_arguments)
    required_arg_map, optional_arg_map = cla_util.process_args(args, trailing_arg_count=1)

    cla_helper.verify_required_args_present(_program_name, __required_arguments, required_arg_map)

    combined_arg_map = optional_arg_map.copy()
    combined_arg_map.update(required_arg_map)

    # zero or one output type arguments should be set
    found = False
    for key in __output_types:
        if key in combined_arg_map:
            if found:
                types_text = ', '.join(__output_types)
                ex = exception_helper.create_cla_exception('WLSDPLY-10100', types_text)
                ex.setExitCode(CommandLineArgUtil.USAGE_ERROR_EXIT_CODE)
                __logger.throwing(ex, class_name=_class_name, method_name=_method_name)
                raise ex
            found = True

    return model_context_helper.create_context(_program_name, combined_arg_map)
Beispiel #17
0
def __process_model_args(optional_arg_map):
    """
    Determine if the model file was passed separately or requires extraction from the archive.
    :param optional_arg_map: the optional arguments map
    :raises CLAException: if the arguments were not valid or an error occurred extracting the model from the archive
    """
    _method_name = '__process_model_args'
    global __tmp_model_dir

    if CommandLineArgUtil.PRINT_USAGE_SWITCH in optional_arg_map:
        # nothing to do since we are printing help information rather than validating supplied artifacts...
        return

    something_to_validate = False
    if CommandLineArgUtil.ARCHIVE_FILE_SWITCH in optional_arg_map:
        #
        # Verify that the archive file exists
        #
        archive_file_name = optional_arg_map[
            CommandLineArgUtil.ARCHIVE_FILE_SWITCH]
        try:
            FileUtils.validateExistingFile(archive_file_name)
        except IllegalArgumentException, iae:
            ex = exception_helper.create_cla_exception(
                'WLSDPLY-20014',
                _program_name,
                archive_file_name,
                iae.getLocalizedMessage(),
                error=iae)
            ex.setExitCode(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE)
            __logger.throwing(ex,
                              class_name=_class_name,
                              method_name=_method_name)
            raise ex
        something_to_validate = True
Beispiel #18
0
    def extract_model(self, program_name):
        """
        Extract the model from the archive.
        :param program_name: the program name (for logging purposes)
        :return: the temporary directory and the full path to the model file
        :raises: BundleAwareException of the appropriate type: if an error occurs
        """
        _method_name = 'extract_model'

        self.__logger.entering(program_name,
                               class_name=self.__class_name,
                               method_name=_method_name)
        try:
            tmp_model_dir = FileUtils.createTempDirectory(program_name)
            tmp_model_file = self.__archive_file.extractModel(tmp_model_dir)
        except (IllegalArgumentException, IllegalStateException,
                WLSDeployArchiveIOException), archex:
            ex = exception_helper.create_cla_exception(
                'WLSDPLY-20010',
                program_name,
                self.__archive_file_name,
                archex.getLocalizedMessage(),
                error=archex)
            self.__logger.throwing(ex,
                                   class_name=self.__class_name,
                                   method_name=_method_name)
            raise ex
def process_target_arguments(argument_map):
    """
    If the -target option is in the argument map, verify that -output_dir is specified.
    If variables_file was not specified, add it with the file <outputDir>/<targetName>_variable.properties .
    :param argument_map: the argument map to be checked and possibly modified
    """
    _method_name = 'process_target_arguments'

    if CommandLineArgUtil.TARGET_SWITCH in argument_map:
        target_name = argument_map[CommandLineArgUtil.TARGET_SWITCH]

        # if -target is specified -output_dir is required
        output_dir = dictionary_utils.get_element(
            argument_map, CommandLineArgUtil.OUTPUT_DIR_SWITCH)
        if (output_dir is None) or (not os.path.isdir(output_dir)):
            ex = exception_helper.create_cla_exception(
                'WLSDPLY-01642', CommandLineArgUtil.OUTPUT_DIR_SWITCH,
                CommandLineArgUtil.TARGET_SWITCH, target_name)
            __logger.throwing(ex,
                              class_name=__class_name,
                              method_name=_method_name)
            raise ex

        # Set the -variable_file parameter if not present with default
        if CommandLineArgUtil.VARIABLE_FILE_SWITCH not in argument_map:
            path = os.path.join(output_dir,
                                target_name + "_variable.properties")
            argument_map[CommandLineArgUtil.VARIABLE_FILE_SWITCH] = path
def __process_passphrase_arg(optional_arg_map):
    """
    Prompt for the passphrase.
    :param optional_arg_map: the optional arguments map
    :raises CLAException: if an error occurs reading the passphrase input from the user
    """
    _method_name = '__process_passphrase_arg'

    if CommandLineArgUtil.PASSPHRASE_SWITCH not in optional_arg_map:
        got_matching_passphrases = False
        while not got_matching_passphrases:
            try:
                passphrase = getcreds.getpass('WLSDPLY-04203')
                passphrase2 = getcreds.getpass('WLSDPLY-04204')
            except IOException, ioe:
                ex = exception_helper.create_encryption_exception(
                    'WLSDPLY-04205', ioe.getLocalizedMessage(), error=ioe)
                __logger.throwing(ex,
                                  class_name=_class_name,
                                  method_name=_method_name)
                raise ex

            if passphrase == passphrase2:
                got_matching_passphrases = True
                optional_arg_map[
                    CommandLineArgUtil.PASSPHRASE_SWITCH] = String(passphrase)
            else:
                # if it is script mode do not prompt again
                if System.console() is None:
                    ex = exception_helper.create_cla_exception('WLSDPLY-04213')
                    ex.setExitCode(CommandLineArgUtil.PROG_ERROR_EXIT_CODE)
                    __logger.throwing(ex,
                                      class_name=_class_name,
                                      method_name=_method_name)
                    raise ex
Beispiel #21
0
def __process_model_args(optional_arg_map):
    """
    Determine if the model file was passed separately or requires extraction from the archive.
    :param optional_arg_map:   the optional arguments map
    :raises CLAException: If an error occurs validating the arguments or extracting the model from the archive
    """
    _method_name = '__process_model_args'
    global __tmp_model_dir

    archive_file_name = None
    if CommandLineArgUtil.ARCHIVE_FILE_SWITCH in optional_arg_map:
        archive_file_name = optional_arg_map[
            CommandLineArgUtil.ARCHIVE_FILE_SWITCH]

        try:
            FileUtils.validateExistingFile(archive_file_name)
        except IllegalArgumentException, iae:
            ex = exception_helper.create_cla_exception(
                'WLSDPLY-20014',
                _program_name,
                archive_file_name,
                iae.getLocalizedMessage(),
                error=iae)
            ex.setExitCode(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE)
            __logger.throwing(ex,
                              class_name=_class_name,
                              method_name=_method_name)
            raise ex
Beispiel #22
0
    def __init__(self, program_name, domain_type):
        """
        The DomainTypedef constructor.
        :param program_name: the name of the program create this object
        :param domain_type: the domain type
        """
        _method_name = '__init__'

        self._logger = PlatformLogger('wlsdeploy.create')
        self._program_name = program_name
        self._domain_type = domain_type
        self.wls_helper = WebLogicHelper(self._logger)

        file_name = domain_type + self.__domain_typedef_extension
        self._domain_typedef_filename = path_utils.find_config_path(
            os.path.join('typedefs', file_name))

        # No need to explicitly validate the filename since the JsonToPython constructor does that...
        try:
            json_parser = JsonToPython(self._domain_typedef_filename)
            self._domain_typedefs_dict = json_parser.parse()
        except IllegalArgumentException, iae:
            ex = exception_helper.create_cla_exception(
                'WLSDPLY-12300',
                self._program_name,
                self._domain_type,
                self._domain_typedef_filename,
                iae.getLocalizedMessage(),
                error=iae)
            ex.setExitCode(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE)
            self._logger.throwing(ex,
                                  class_name=self.__class_name,
                                  method_name=_method_name)
            raise ex
    def _check_trailing_arguments(self, args, trailing_arg_count):
        """
        Remove any trailing (no switch) arguments from the argument list and add them to the required result.
          example:
            command.sh -oracle_home /oracle file1 file2
            file1 and file2 are trailing arguments

        :param args: the arguments to be examined
        :param trailing_arg_count: the number of trailing arguments that are expected
        :return: the argument list, with the trailing arguments removed
        :raises CLAException: if there are not enough arguments present
        """
        method_name = '_check_trailing_arguments'
        args_len = len(args)

        # verify there are enough arguments for any trailing (no switch) args
        if args_len < trailing_arg_count + 1:
            ex = exception_helper.create_cla_exception('WLSDPLY-01639',
                                                       trailing_arg_count)
            ex.setExitCode(self.ARG_VALIDATION_ERROR_EXIT_CODE)
            self._logger.throwing(ex,
                                  class_name=self._class_name,
                                  method_name=method_name)
            raise ex

        # set required_result['TRAILING_ARGS'] to list of trailing args (such as ['file1', 'file2'])
        trailing_args = []
        for index in range(args_len - trailing_arg_count, args_len):
            arg = args[index]
            trailing_args.append(arg)
        self._required_result[self.TRAILING_ARGS_SWITCH] = trailing_args

        # remove trailing args from the list and return revised list
        return args[0:(args_len - trailing_arg_count)]
Beispiel #24
0
def __process_model_args(optional_arg_map):
    """
    Verify that either the model_file or archive_file was provided and exists.
    Extract the model file if only the archive_file was provided.
    :param optional_arg_map: the optional arguments map
    :raises CLAException: if the arguments are invalid or an error occurs extracting the model from the archive
    """
    _method_name = '__process_model_args'
    global __tmp_model_dir

    if CommandLineArgUtil.MODEL_FILE_SWITCH in optional_arg_map:
        model_file_name = optional_arg_map[
            CommandLineArgUtil.MODEL_FILE_SWITCH]

        try:
            FileUtils.validateExistingFile(model_file_name)
        except IllegalArgumentException, iae:
            ex = exception_helper.create_cla_exception(
                'WLSDPLY-20006',
                _program_name,
                model_file_name,
                iae.getLocalizedMessage(),
                error=iae)
            ex.setExitCode(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE)
            __logger.throwing(ex,
                              class_name=_class_name,
                              method_name=_method_name)
            raise ex
def __process_variable_filename_arg(optional_arg_map):
    """
    If the variable filename argument is present, the required model variable injector json file must exist in
    the WLSDEPLOY lib directory.
    :param optional_arg_map: containing the variable file name
    :raises: CLAException: if this argument is present but the model variable injector json does not exist
    """
    _method_name = '__process_variable_filename_arg'

    if CommandLineArgUtil.VARIABLE_PROPERTIES_FILE_SWITCH in optional_arg_map:
        variable_injector_file_name = variable_injector.get_default_variable_injector_file_name(
        )
        try:
            FileUtils.validateExistingFile(variable_injector_file_name)
        except IllegalArgumentException, ie:
            ex = exception_helper.create_cla_exception(
                'WLSDPLY-06021',
                optional_arg_map[
                    CommandLineArgUtil.VARIABLE_PROPERTIES_FILE_SWITCH],
                variable_injector_file_name,
                ie.getLocalizedMessage(),
                error=ie)
            __logger.throwing(ex,
                              class_name=_class_name,
                              method_name=_method_name)
            raise ex
    def _validate_model_file_arg(self, value):
        method_name = '_validate_model_file_arg'

        result_model_files = []  # type: list
        if self._allow_multiple_models:
            model_files = get_model_files(value)
        else:
            model_files = [value]

        for model_file in model_files:
            try:
                model_file = JFileUtils.validateFileName(model_file)
                model_file = model_file.getAbsolutePath()
                result_model_files.append(model_file)
            except JIllegalArgumentException, iae:
                ex = exception_helper.create_cla_exception(
                    'WLSDPLY-01617',
                    model_file,
                    iae.getLocalizedMessage(),
                    error=iae)
                ex.setExitCode(self.ARG_VALIDATION_ERROR_EXIT_CODE)
                self._logger.throwing(ex,
                                      class_name=self._class_name,
                                      method_name=method_name)
                raise ex
Beispiel #27
0
def __process_java_home_arg(optional_arg_map):
    """
    Verify that java_home is set.  If not, set it.
    :param optional_arg_map: the optional arguments map
    :raises CLAException: if the java home argument is not valid
    """
    _method_name = '__process_java_home_arg'

    if CommandLineArgUtil.JAVA_HOME_SWITCH not in optional_arg_map:
        java_home_name = os.environ.get('JAVA_HOME')
        try:
            java_home = FileUtils.validateExistingDirectory(java_home_name)
        except IllegalArgumentException, iae:
            ex = exception_helper.create_cla_exception(
                'WLSDPLY-12400',
                _program_name,
                java_home_name,
                iae.getLocalizedMessage(),
                error=iae)
            ex.setExitCode(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE)
            __logger.throwing(ex,
                              class_name=_class_name,
                              method_name=_method_name)
            raise ex
        optional_arg_map[
            CommandLineArgUtil.JAVA_HOME_SWITCH] = java_home.getAbsolutePath()
def validate_model_present(program_name, optional_arg_map):
    """
    Determine if the model file was passed separately or requires extraction from the archive.
    If the model is in the archive, extract it to the temporary model location, and set that file as the
    MODEL_FILE_SWITCH argument.
    The MODEL_FILE_SWITCH value may be specified as multiple comma-separated models.
    :param program_name: the name of the calling program, for logging
    :param optional_arg_map: the optional arguments from the command line
    :raises CLAException: if the specified model is not an existing file, or the model is not found in the archive,
    or the model is not found from either argument
    """
    _method_name = 'validate_model_present'
    global __tmp_model_dir

    if CommandLineArgUtil.MODEL_FILE_SWITCH in optional_arg_map:
        model_file_value = optional_arg_map[
            CommandLineArgUtil.MODEL_FILE_SWITCH]
        model_files = cla_utils.get_model_files(model_file_value)

        for model_file in model_files:
            try:
                FileUtils.validateExistingFile(model_file)
            except IllegalArgumentException, iae:
                ex = exception_helper.create_cla_exception(
                    'WLSDPLY-20006',
                    program_name,
                    model_file,
                    iae.getLocalizedMessage(),
                    error=iae)
                ex.setExitCode(
                    CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE)
                __logger.throwing(ex,
                                  class_name=_class_name,
                                  method_name=_method_name)
                raise ex
def __validate_mode_args(optional_arg_map):
    """
    Verify that either the model_file or the manual switch was specified.
    :param optional_arg_map: the optional arguments map
    :raises CLAException: if the arguments are not valid
    """
    _method_name = '__validate_mode_args'

    if CommandLineArgUtil.MODEL_FILE_SWITCH in optional_arg_map:
        model_file_name = optional_arg_map[
            CommandLineArgUtil.MODEL_FILE_SWITCH]
        try:
            FileUtils.validateExistingFile(model_file_name)
        except IllegalArgumentException, iae:
            ex = exception_helper.create_cla_exception(
                'WLSDPLY-20006',
                _program_name,
                model_file_name,
                iae.getLocalizedMessage(),
                error=iae)
            ex.setExitCode(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE)
            __logger.throwing(ex,
                              class_name=_class_name,
                              method_name=_method_name)
            raise ex
Beispiel #30
0
class DomainTypedef(object):
    """
    The class that processes domain type definitions.
    """
    __class_name = 'DomainTypedef'

    __domain_typedef_extension = '.json'

    JRF_TEMPLATE_REGEX = "^(.*jrf_template[0-9._]*\\.jar)|(Oracle JRF WebServices Asynchronous services)$"
    RESTRICTED_JRF_TEMPLATE_REGEX = "^(Oracle Restricted JRF)$"
    JRF_SERVER_GROUP = 'JRF-MAN-SVR'

    def __init__(self, program_name, domain_type):
        """
        The DomainTypedef constructor.
        :param program_name: the name of the program create this object
        :param domain_type: the domain type
        """
        _method_name = '__init__'

        self._logger = PlatformLogger('wlsdeploy.create')
        self._program_name = program_name
        self._domain_type = domain_type
        self.wls_helper = WebLogicHelper(self._logger)

        file_name = domain_type + self.__domain_typedef_extension
        self._domain_typedef_filename = path_utils.find_config_path(
            os.path.join('typedefs', file_name))

        # No need to explicitly validate the filename since the JsonToPython constructor does that...
        try:
            json_parser = JsonToPython(self._domain_typedef_filename)
            self._domain_typedefs_dict = json_parser.parse()
        except IllegalArgumentException, iae:
            ex = exception_helper.create_cla_exception(
                'WLSDPLY-12300',
                self._program_name,
                self._domain_type,
                self._domain_typedef_filename,
                iae.getLocalizedMessage(),
                error=iae)
            ex.setExitCode(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE)
            self._logger.throwing(ex,
                                  class_name=self.__class_name,
                                  method_name=_method_name)
            raise ex
        except JsonException, je:
            ex = exception_helper.create_cla_exception(
                'WLSDPLY-12301',
                self._program_name,
                self._domain_type,
                self._domain_typedef_filename,
                je.getLocalizedMessage(),
                error=je)
            ex.setExitCode(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE)
            self._logger.throwing(ex,
                                  class_name=self.__class_name,
                                  method_name=_method_name)
            raise ex