Skip to content

Commit

Permalink
Merge 26ceab8 into 06e5b42
Browse files Browse the repository at this point in the history
  • Loading branch information
mogproject committed Oct 31, 2016
2 parents 06e5b42 + 26ceab8 commit 2a81f88
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -17,7 +17,7 @@ dev-uninstall:
$(PYTHON) setup.py develop -u

pep8:
pep8 --max-line-length 120 --ignore E402,E731 src/$(PROG) tests
pep8 --max-line-length 140 --ignore E402,E731 src/$(PROG) tests

test: pep8
$(PYTHON) setup.py test
Expand Down
26 changes: 13 additions & 13 deletions README.rst
Expand Up @@ -28,19 +28,19 @@ YAML-Configurable Java Application Wrapper
Features
--------

*Launch your Java application more safely, explicitly and flexibly!*
*Launch your Java application more safely, explicitly, and flexibly!*

This script does ...

* (before launch)
* Load settings from YAML file
* Verify OS user name and Java version
* Check the application is already running if the duplicate running is not allowed
* (before the launch)
* Load settings from a YAML file
* Verify the OS user name and Java version
* Check if the application has already been running when duplicate running is prohibited
* Execute pre-launch commands
* Logging to syslog
* Launch the Java application with proper options
* (after launch)
* Logging to syslog
* Log to syslog
* Launch the Java application with the proper options
* (after the launch)
* Log to syslog
* Execute post-launch commands

------------
Expand All @@ -55,7 +55,7 @@ Dependencies
Installation
------------

* ``pip`` command may need ``sudo``
* ``pip`` command may require ``sudo``

+-------------------------+-------------------------------------+
| Operation | Command |
Expand All @@ -73,13 +73,13 @@ Installation

* Then, write your configuration to the file ``your-app.yml``.

See an example below.
See the example below.

---------------------
Configuration Example
---------------------

See an `example <https://github.com/mogproject/javactl/blob/master/tests/resources/example.yml>`_.
See this `example <https://github.com/mogproject/javactl/blob/master/tests/resources/example.yml>`_.

---------------------------
Now Launch Your Application
Expand All @@ -91,7 +91,7 @@ Now Launch Your Application

javactl --check /path/to/your-app.yml

* Launch java application
* Launch the java application

::

Expand Down
2 changes: 1 addition & 1 deletion src/javactl/__init__.py
@@ -1 +1 @@
__version__ = '0.1.7'
__version__ = '0.2.0'
24 changes: 16 additions & 8 deletions src/javactl/setting/java_setting.py
Expand Up @@ -66,8 +66,8 @@ def get_opts(self):
xs = [
'-Dcom.sun.management.jmxremote',
omap(lambda x: '-Dcom.sun.management.jmxremote.port=%d' % x, self.port),
omap(lambda b: '-Dcom.sun.management.jmxremote.ssl=%s' % str(b).lower(), self.ssl),
omap(lambda b: '-Dcom.sun.management.jmxremote.authenticate=%s' % str(b).lower(), self.authenticate),
omap(lambda b: '-Dcom.sun.management.jmxremote.ssl=%s' % JavaSetting.py_to_java_str(b), self.ssl),
omap(lambda b: '-Dcom.sun.management.jmxremote.authenticate=%s' % JavaSetting.py_to_java_str(b), self.authenticate),
]
return [x for x in xs if x is not None]

Expand All @@ -77,15 +77,15 @@ def __init__(self,
server=None,
memory=None,
jmx=None,
env=None,
prop=None,
option=None):
# constraints
assert home is not None and os.path.isabs(home), 'java.home is required and must be an absolute path'
assert version is not None, 'java.version is required'

# TODO: check value types and format
assert env is None or isinstance(env, dict), 'java.env must be a dict'
assert option is None or isinstance(option, list), 'java.env must be a list'
assert prop is None or isinstance(prop, dict), 'java.prop must be a dict'
assert option is None or isinstance(option, list), 'java.option must be a list'

CaseClass.__init__(
self,
Expand All @@ -94,7 +94,7 @@ def __init__(self,
('server', server),
('memory', JavaSetting.Memory(version, **oget(memory, {}))),
('jmx', JavaSetting.JMX(**oget(jmx, {}))),
('env', oget(env, {})),
('prop', oget(prop, {})),
('option', oget(option, [])),
)

Expand All @@ -103,8 +103,16 @@ def get_executable(self):

def get_opts(self):
sv = ['-server'] if self.server else []
ev = ['-D%s=%s' % (k, v) for k, v in sorted(self.env.items())]
return sv + self.memory.get_opts() + self.jmx.get_opts() + ev + self.option
pr = ['-D%s=%s' % (k, JavaSetting.py_to_java_str(v)) for k, v in sorted(self.prop.items())]
return sv + self.memory.get_opts() + self.jmx.get_opts() + pr + self.option

def get_args(self):
return [self.get_executable()] + self.get_opts()

@staticmethod
def py_to_java_str(value):
"""Convert python data to Java-like string"""
if isinstance(value, bool):
return str(value).lower()
else:
return str(value)
17 changes: 17 additions & 0 deletions tests/javactl/setting/test_java_setting.py
@@ -0,0 +1,17 @@
from __future__ import division, print_function, absolute_import, unicode_literals

from mog_commons.unittest import TestCase
from javactl.setting.java_setting import JavaSetting


class TestJavaSetting(TestCase):

def test_py_to_java_str(self):
self.assertEqual(JavaSetting.py_to_java_str(True), 'true')
self.assertEqual(JavaSetting.py_to_java_str(False), 'false')
self.assertEqual(JavaSetting.py_to_java_str(None), 'None')
self.assertEqual(JavaSetting.py_to_java_str(0), '0')
self.assertEqual(JavaSetting.py_to_java_str(1000000000), '1000000000')
self.assertEqual(JavaSetting.py_to_java_str(10000000000), '10000000000')
self.assertEqual(JavaSetting.py_to_java_str(-10000000000), '-10000000000')
self.assertEqual(JavaSetting.py_to_java_str('abc'), 'abc')
2 changes: 1 addition & 1 deletion tests/javactl/setting/test_setting.py
Expand Up @@ -26,7 +26,7 @@ def test_get_args(self):
'-Dcom.sun.management.jmxremote.port=20001',
'-Dcom.sun.management.jmxremote.ssl=false',
'-Dcom.sun.management.jmxremote.authenticate=false',
'-Dcom.amazonaws.sdk.disableCertChecking=True',
'-Dcom.amazonaws.sdk.disableCertChecking=true',
'-Dfile.encoding=UTF-8',
'-Dhttp.netty.maxInitialLineLength=8192',
'-Dhttp.port=9000',
Expand Down
2 changes: 1 addition & 1 deletion tests/javactl/test_javactl.py
Expand Up @@ -62,7 +62,7 @@ def test_main(self):
' -server -Xms64M -Xmx2G -XX:MetaspaceSize=1G -XX:MaxMetaspaceSize=2G -Xmn256M -XX:MaxNewSize=256M ',
'-XX:SurvivorRatio=8 -XX:TargetSurvivorRatio=50 -Dcom.sun.management.jmxremote ',
'-Dcom.sun.management.jmxremote.port=20001 -Dcom.sun.management.jmxremote.ssl=false ',
'-Dcom.sun.management.jmxremote.authenticate=false -Dcom.amazonaws.sdk.disableCertChecking=True ',
'-Dcom.sun.management.jmxremote.authenticate=false -Dcom.amazonaws.sdk.disableCertChecking=true ',
'-Dfile.encoding=UTF-8 -Dhttp.netty.maxInitialLineLength=8192 -Dhttp.port=9000 ',
'-XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSInitiatingOccupancyOnly ',
'-XX:CMSInitiatingOccupancyFraction=70 -XX:+ScavengeBeforeFullGC -XX:+CMSScavengeBeforeRemark ',
Expand Down
2 changes: 1 addition & 1 deletion tests/resources/example.yml
Expand Up @@ -35,7 +35,7 @@ java:
ssl: false # will be `-Dcom.sun.management.jmxremote.ssl=false`
authenticate: false # will be `-Dcom.sun.management.jmxremote.authenticate=false`

env: # will be converted to `-D<key>=<value>` options
prop: # will be converted to `-D<key>=<value>` options
file.encoding: UTF-8
http.port: 9000
http.netty.maxInitialLineLength: 8192
Expand Down
2 changes: 1 addition & 1 deletion tests/resources/test_01.yml.j2
Expand Up @@ -31,7 +31,7 @@ java:
ssl: false
authenticate: false

env:
prop:
file.encoding: UTF-8
http.port: 9000
http.netty.maxInitialLineLength: 8192
Expand Down

0 comments on commit 2a81f88

Please sign in to comment.