-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add dc.Spec.Config validation for properties that are not available i…
…n defined version
- Loading branch information
Showing
14 changed files
with
920 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[[source]] | ||
url = "https://pypi.org/simple" | ||
verify_ssl = true | ||
name = "pypi" | ||
|
||
[packages] | ||
javalang = "*" | ||
|
||
[dev-packages] | ||
|
||
[requires] | ||
python_version = "3.9" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env bash | ||
OUTPUTFILE=../../apis/cassandra/v1beta1/cassandra_config_generated.go | ||
curl -sL https://raw.githubusercontent.com/apache/cassandra/cassandra-4.0/src/java/org/apache/cassandra/config/Config.java --output Config-40.java | ||
curl -sL https://raw.githubusercontent.com/apache/cassandra/cassandra-3.11/src/java/org/apache/cassandra/config/Config.java --output Config-311.java | ||
curl -sL https://raw.githubusercontent.com/apache/cassandra/trunk/src/java/org/apache/cassandra/config/Config.java --output Config-trunk.java | ||
pipenv run python parse.py > $OUTPUTFILE | ||
go fmt $OUTPUTFILE | ||
rm -f *.java |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# This script generates golang structs for Cassandra configurations | ||
import javalang | ||
from pathlib import Path | ||
from typing import List | ||
|
||
def parse_file(file: str): | ||
config_file = Path(file).read_text() | ||
tree = javalang.parse.parse(config_file) | ||
for path, node in tree.filter(javalang.tree.ClassDeclaration): | ||
if node.name == "Config": | ||
for field in node.fields: | ||
if 'public' in field.modifiers and not 'static' in field.modifiers: | ||
for declarator in field.declarators: | ||
print(f'"{declarator.name}": true,') | ||
# for annotation in field.annotations: | ||
# if annotation.name == "Deprecated": | ||
# print('Deprecated!') | ||
|
||
def generate_configs(versions: List[str]): | ||
print(""" | ||
//go:build !ignore_autogenerated | ||
// +build !ignore_autogenerated | ||
// Code is generated with hack/config. DO NOT EDIT. | ||
package v1beta1 | ||
import ( | ||
"strconv" | ||
"strings" | ||
) | ||
type CassandraConfigValues struct { | ||
accepted map[string]interface{} | ||
} | ||
func (c *CassandraConfigValues) HasProperty(propertyName string) bool { | ||
_, found := c.accepted[propertyName] | ||
return found | ||
} | ||
func GetCassandraConfigValues(serverVersion string) (*CassandraConfigValues, error) { | ||
versionParts := strings.Split(serverVersion, ".") | ||
serverMajorVersion, err := strconv.ParseInt(versionParts[0], 10, 8) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if serverMajorVersion == 3 { | ||
// Return configuration for 3.11, regardless of the real version (we don't support <3.11) | ||
return &config311, nil | ||
} | ||
if serverMajorVersion == 4 { | ||
serverMinorVersion, err := strconv.ParseInt(versionParts[1], 10, 8) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if serverMinorVersion == 0 { | ||
// Return config40 | ||
return &config40, nil | ||
} | ||
} | ||
// Something brand new.. | ||
return &configtrunk, nil | ||
} | ||
var( | ||
""") | ||
|
||
for ver in versions: | ||
create_config_values(ver) | ||
|
||
print(')') | ||
|
||
def create_config_values(version: str): | ||
print(f""" | ||
config{version} = CassandraConfigValues{{ | ||
accepted: map[string]interface{{}}{{""") | ||
parse_file(f'Config-{version}.java') | ||
print(""" | ||
}, | ||
} | ||
""") | ||
|
||
generate_configs(['311', '40', 'trunk']) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters