Skip to content

Commit

Permalink
added documentation template
Browse files Browse the repository at this point in the history
  • Loading branch information
mdumandag committed Apr 14, 2020
1 parent 4956a2f commit 0a352af
Show file tree
Hide file tree
Showing 9 changed files with 1,304 additions and 18 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ where
* `py` : Python
* `ts` : Typescript
* `go` : Go
* `md` : Markdown (Documentation)

`java` is the default value if no language is specified.

Expand Down
29 changes: 19 additions & 10 deletions generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,28 @@
print("Hazelcast Client Binary Protocol version %s" % (protocol_versions[-1]))
env = create_environment(lang, namespace_arg)

codec_template = env.get_template("codec-template.%s.j2" % lang_str_arg)

generate_codecs(protocol_defs, codec_template, codec_output_dir, lang)
print('Generated codecs are at \'%s\'' % os.path.abspath(codec_output_dir))
if lang != SupportedLanguages.MD:
codec_template = env.get_template("codec-template.%s.j2" % lang_str_arg)
generate_codecs(protocol_defs, codec_template, codec_output_dir, lang)
print('Generated codecs are at \'%s\'' % os.path.abspath(codec_output_dir))

if custom_protocol_defs is not None:
custom_codec_template = env.get_template("custom-codec-template.%s.j2" % lang_str_arg)
relative_custom_codec_output_dir = out_dir_arg if out_dir_arg is not None else custom_codec_output_directories[lang]
custom_codec_output_dir = os.path.join(root_dir, relative_custom_codec_output_dir)
generate_custom_codecs(custom_protocol_defs, custom_codec_template, custom_codec_output_dir, file_extensions[lang])
print('Generated custom codecs are at \'%s\'' % custom_codec_output_dir)
if lang != SupportedLanguages.MD:
custom_codec_template = env.get_template("custom-codec-template.%s.j2" % lang_str_arg)
if out_dir_arg:
relative_custom_codec_output_dir = out_dir_arg
else:
relative_custom_codec_output_dir = custom_codec_output_directories[lang]
custom_codec_output_dir = os.path.join(root_dir, relative_custom_codec_output_dir)
generate_custom_codecs(custom_protocol_defs, custom_codec_template, custom_codec_output_dir,
file_extensions[lang])
print('Generated custom codecs are at \'%s\'' % custom_codec_output_dir)
else:
documentation_template = env.get_template('documentation-template.j2')
generate_documentation(protocol_defs, custom_protocol_defs, documentation_template, codec_output_dir,
file_extensions[lang])

if not no_binary_arg:
if not no_binary_arg and lang != SupportedLanguages.MD:
relative_test_output_dir = test_out_dir_arg if test_out_dir_arg is not None else test_output_directories[lang]
relative_binary_output_dir = bin_out_dir_arg if bin_out_dir_arg is not None else binary_output_directories[lang]
test_output_dir = os.path.join(root_dir, relative_test_output_dir)
Expand Down
Empty file added md/__init__.py
Empty file.
1,260 changes: 1,260 additions & 0 deletions md/documentation-template.j2

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion protocol-definitions/ContinuousQuery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ methods:
nullable: false
since: 2.0
doc: |
Source that dispathces this batch event.
Source that dispatches this batch event.
- name: partitionId
type: int
nullable: false
Expand Down
4 changes: 2 additions & 2 deletions protocol-definitions/Map.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2677,15 +2677,15 @@ methods:
Updates TTL (time to live) value of the entry specified by {@code key} with a new TTL value.
New TTL value is valid from this operation is invoked, not from the original creation of the entry.
If the entry does not exist or already expired, then this call has no effect.
<p>
The entry will expire and get evicted after the TTL. If the TTL is 0,
then the entry lives forever. If the TTL is negative, then the TTL
from the map configuration will be used (default: forever).
If there is no entry with key {@code key}, this call has no effect.
<b>Warning:</b>
<p>
Time resolution for TTL is seconds. The given TTL value is rounded to the next closest second value.
request:
retryable: false
Expand Down
4 changes: 2 additions & 2 deletions protocol-definitions/PNCounter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ methods:
since: 2.0
doc: |
Query operation to retrieve the current value of the PNCounter.
<p>
The invocation will return the replica timestamps (vector clock) which
can then be sent with the next invocation to keep session consistency
guarantees.
Expand Down Expand Up @@ -61,7 +61,7 @@ methods:
doc: |
Adds a delta to the PNCounter value. The delta may be negative for a
subtraction.
<p>
The invocation will return the replica timestamps (vector clock) which
can then be sent with the next invocation to keep session consistency
guarantees.
Expand Down
4 changes: 2 additions & 2 deletions protocol-definitions/Ringbuffer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ methods:
since: 2.0
doc: |
Returns number of items in the ringbuffer. If no ttl is set, the size will always be equal to capacity after the
head completed the first looparound the ring. This is because no items are getting retired.
head completed the first loop around the ring. This is because no items are getting retired.
request:
retryable: true
partitionIdentifier: name
Expand Down Expand Up @@ -129,7 +129,7 @@ methods:
will return the sequence of the written item. If there is no space, it depends on the overflow policy what happens:
OverflowPolicy OVERWRITE we just overwrite the oldest item in the ringbuffer and we violate the ttl
OverflowPolicy FAIL we return -1. The reason that FAIL exist is to give the opportunity to obey the ttl.
<p/>
This sequence will always be unique for this Ringbuffer instance so it can be used as a unique id generator if you are
publishing items on this Ringbuffer. However you need to take care of correctly determining an initial id when any node
uses the ringbuffer for the first time. The most reliable way to do that is to write a dummy item into the ringbuffer and
Expand Down
18 changes: 17 additions & 1 deletion util.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ def generate_custom_codecs(services, template, output_dir, extension):
print("[%s] contains missing type mapping so ignoring it." % codec_file_name)


def generate_documentation(services, custom_definitions, template, output_dir, extension):
os.makedirs(output_dir, exist_ok=True)
content = template.render(services=services, custom_definitions=custom_definitions)
file_name = os.path.join(output_dir, 'documentation.' + extension)
with open(file_name, 'w', newline='\n') as file:
file.writelines(content)


def item_type(lang_name, param_type):
if param_type.startswith("List_") or param_type.startswith("ListCN_"):
return lang_name(param_type.split('_', 1)[1])
Expand Down Expand Up @@ -327,6 +335,7 @@ class SupportedLanguages(Enum):
# PY = 'py'
# TS = 'ts'
# GO = 'go'
MD = 'md'


codec_output_directories = {
Expand All @@ -336,6 +345,7 @@ class SupportedLanguages(Enum):
# SupportedLanguages.PY: 'hazelcast/protocol/codec/',
# SupportedLanguages.TS: 'src/codec/',
# SupportedLanguages.GO: 'internal/proto/'
SupportedLanguages.MD: 'documentation'
}

custom_codec_output_directories = {
Expand All @@ -354,28 +364,34 @@ class SupportedLanguages(Enum):
# SupportedLanguages.PY: 'py',
# SupportedLanguages.TS: 'ts',
# SupportedLanguages.GO: 'go'
SupportedLanguages.MD: 'md'
}

language_specific_funcs = {
'lang_types_encode': {
SupportedLanguages.JAVA: java_types_encode,
SupportedLanguages.CS: cs_types_encode,
SupportedLanguages.MD: lambda x: x,
},
'lang_types_decode': {
SupportedLanguages.JAVA: java_types_decode,
SupportedLanguages.CS: cs_types_decode,
SupportedLanguages.MD: lambda x: x,
},
'lang_name': {
SupportedLanguages.JAVA: java_name,
SupportedLanguages.CS: cs_name,
SupportedLanguages.MD: lambda x: x,
},
'param_name': {
SupportedLanguages.JAVA: param_name,
SupportedLanguages.CS: param_name,
SupportedLanguages.MD: lambda x: x,
},
'escape_keyword': {
SupportedLanguages.JAVA: lambda x: x,
SupportedLanguages.CS: cs_escape_keyword,
SupportedLanguages.MD: lambda x: x,
},
}

Expand Down Expand Up @@ -407,10 +423,10 @@ def create_environment(lang, namespace):
env.globals["item_type"] = item_type
env.globals["key_type"] = key_type
env.globals["value_type"] = value_type
env.globals["namespace"] = namespace
env.globals["lang_types_encode"] = language_specific_funcs['lang_types_encode'][lang]
env.globals["lang_types_decode"] = language_specific_funcs['lang_types_decode'][lang]
env.globals["lang_name"] = language_specific_funcs['lang_name'][lang]
env.globals["namespace"] = namespace
env.globals["param_name"] = language_specific_funcs['param_name'][lang]
env.globals["escape_keyword"] = language_specific_funcs['escape_keyword'][lang]

Expand Down

0 comments on commit 0a352af

Please sign in to comment.