def jmx(self, bash_command): """ JMX is build-in instrumentation that enables to monitor and manage JVM :param bash_command: list of bash comments :type bash_command: [] :return: """ jmx_enabled = self.merged_args.get(JVM_ARGS_CONF_KEY).get( 'jmx_enabled') if not is_blank(jmx_enabled) and jmx_enabled is True: jmx_port = self.merged_args.get(JVM_ARGS_CONF_KEY).get('jmx_port') if not is_blank('jmx_port'): jmx = '-Djavax.management.builder.initial= -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=%s' % ( jmx_port) jmx_args = self.merged_args.get(JVM_ARGS_CONF_KEY).get( 'jmx_args') if not is_blank(jmx_args): jmx += ' %s' % jmx_args else: self.log.error('Could not find jmx_port') raise ValueError('Please set jmx_port') bash_command.extend(jmx.split(' '))
def logback(self, bash_command): """ Handle logback options: use java_overriding_logback_conf_path if exist, otherwise get java_logback_conf_path :param bash_command: list of bash comments :type bash_command list :return: """ logback_config = '-Dlogging.config=%s' overriding_logback_config = False logback_conf_key = 'java_overriding_logback_conf_path' java_overriding_logback_conf_path = self.merged_args.get( JVM_ARGS_CONF_KEY).get(logback_conf_key) if not is_blank(java_overriding_logback_conf_path): if os.path.isfile(java_overriding_logback_conf_path): overriding_logback_config = True bash_command.append(logback_config % (java_overriding_logback_conf_path)) java_logback_conf_path = self.merged_args.get(JVM_ARGS_CONF_KEY).get( logback_conf_key) if not is_blank( java_logback_conf_path) and overriding_logback_config is False: bash_command.append(logback_config % java_logback_conf_path)
def spring_profile(self, bash_command): """ :param bash_command: list of bash comments :type bash_command list :return: """ profile = self.merged_args.get(JVM_ARGS_CONF_KEY).get('profile') if not is_blank(profile): bash_command.append('-Dspring.profiles.active={}'.format(profile))
def timezone(self, bash_command): """ :param bash_command: list of bash comments :type bash_command list :return: """ timezone = self.merged_args.get(JVM_ARGS_CONF_KEY).get('timezone') if not is_blank(timezone): bash_command.append(timezone)
def extra_args(self, bash_command): """ :param bash_command: list of bash comments :type bash_command: [] :return: """ extra_args = self.merged_args.get('extra_args') if not is_blank(extra_args): bash_command.extend(extra_args.split(' '))
def jvm_memory_allocation(self, bash_command): """ Xmx specifies the maximum memory allocation pool for a Java Virtual Machine (JVM), Xms specifies the initial memory allocation pool. :param bash_command: list of bash comments :type bash_command: [] :return: """ xms = self.merged_args.get(JVM_ARGS_CONF_KEY).get('xms') if not is_blank(xms): xms = '-Xms%sm' % xms bash_command.extend([xms]) xmx = self.merged_args.get(JVM_ARGS_CONF_KEY).get('xmx') if not is_blank(xmx): xmx = '-Xmx%sm' % xmx bash_command.extend([xmx])
def validate_mandatory_fields(self): """ Validate if all the mandatory fields were set. main_class, jar_path or class_path are mandatory. :raise ValueError - throw an exception when fields are missing. :return: """ jar_path = self.jvm_args.get('jar_path') class_path = self.jvm_args.get('class_path') if is_blank(jar_path) and is_blank(class_path): self.log.error( 'Could not run jar file without class path or jar path') raise ValueError('Please set class path or jar path') main_class = self.jvm_args.get('main_class') if is_blank(main_class): self.log.error('Could not run jar file without main class') raise ValueError('Please set the full name of main class')
def extra_jvm(self, bash_command): """ extra args (like GC) for Java Virtual Machine (JVM), :param bash_command: list of bash comments :type bash_command: [] :return: """ extra_jvm = self.merged_args.get(JVM_ARGS_CONF_KEY).get('extra_jvm') if not is_blank(extra_jvm): bash_command.extend([extra_jvm])
def jar_path(self, bash_command): """ Validate that main_class, jar_path or class_path exist in merged_args, otherwise throw an error :param bash_command: list of bash comments :type bash_command: [] :raise ValueError: main_class, class path or jar path were not defined :return: """ jar_path_conf_key = 'jar_path' class_path = self.merged_args.get(JVM_ARGS_CONF_KEY).get( jar_path_conf_key) if not is_blank( self.merged_args.get(JVM_ARGS_CONF_KEY).get(class_path)): class_path = '%s;%s' % ( self.merged_args.get(JVM_ARGS_CONF_KEY).get(jar_path_conf_key), self.merged_args.get(JVM_ARGS_CONF_KEY).get(class_path)) if is_blank(class_path): self.log.error( 'Could not run jar file without class path or jar path') raise ValueError('Please set class path or jar path') main_class_conf_key = 'main_class' if is_blank( self.merged_args.get(JVM_ARGS_CONF_KEY).get( main_class_conf_key)): self.log.error('Could not run jar file without main class') raise ValueError('Please set the full name of main class') else: bash_command.extend(['-cp', class_path]) bash_command.extend([ '-Dloader.main=%s' % self.merged_args.get( JVM_ARGS_CONF_KEY).get(main_class_conf_key) ]) bash_command.extend( ['org.springframework.boot.loader.PropertiesLauncher'])
def remote_debug_options(self, bash_command): """ Handle debug options :param bash_command: list of bash comments :type bash_command list :return: """ remote_debug_conf_key = 'remote_debug_enabled' remote_debug_enabled = self.merged_args.get(JVM_ARGS_CONF_KEY).get( remote_debug_conf_key) if not is_blank(remote_debug_enabled) and remote_debug_enabled is True: remote_debug_suspend = self.merged_args.get(JVM_ARGS_CONF_KEY).get( 'remote_debug_suspend') if not is_blank( remote_debug_suspend) and remote_debug_suspend is True: remote_debug_suspend = 'y' else: remote_debug_suspend = 'n' remote_debug = '-agentlib:jdwp=transport=dt_socket,address=%s,server=y,suspend=%s' % ( self.merged_args.get(JVM_ARGS_CONF_KEY).get( 'remote_debug_port'), remote_debug_suspend) bash_command.append(remote_debug)
def java_path(self, bash_command): """ Java location e.g: /usr/bin/java :param bash_command: list of bash comments :type bash_command: [] :return: """ java_path = self.merged_args.get('java_path') if not is_blank(java_path): bash_command.extend([java_path]) else: self.log.error('java_path is not defined') raise ValueError('Please set java_path')
def get_args(self, args, bash_command, command): if not is_blank(args): args = ' '.join(SpringBootJarOperator.java_args_prefix + '%s %s' % (key, val) for (key, val) in args.iteritems()) bash_command.append(command) bash_command.append(args)