Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Commit

Permalink
Updating config transformer for Admin API v1.
Browse files Browse the repository at this point in the history
  • Loading branch information
bkap committed Aug 1, 2016
1 parent 974882e commit 2f16d99
Show file tree
Hide file tree
Showing 7 changed files with 442 additions and 273 deletions.
28 changes: 21 additions & 7 deletions convert_yaml.py
Expand Up @@ -19,24 +19,38 @@
convert_yaml.py app.yaml > app.json
"""

import argparse
import json
import os
import sys

import yaml

from yaml_conversion import yaml_schema
from yaml_conversion import yaml_schema_v1
from yaml_conversion import yaml_schema_v1beta


API_VERSION_SCHEMAS = {
'v1beta4': yaml_schema_v1beta,
'v1beta5': yaml_schema_v1beta,
'v1': yaml_schema_v1
}


def main():
if len(sys.argv) != 2:
sys.stderr.write(
'Usage: {0} <input_file.yaml>\n'.format(os.path.basename(sys.argv[0])))
sys.exit(1)
parser = argparse.ArgumentParser(description='Convert between legacy YAML '
'and public JSON representations of App '
'Engine versions')
parser.add_argument('input_file')
parser.add_argument('--api_version', dest='api_version', default='v1beta5',
choices=sorted(API_VERSION_SCHEMAS.keys()))

with open(sys.argv[1]) as input_file:
args = parser.parse_args()

with open(args.input_file) as input_file:
input_yaml = yaml.safe_load(input_file)

yaml_schema = API_VERSION_SCHEMAS[args.api_version]

converted_yaml = yaml_schema.SCHEMA.ConvertValue(input_yaml)
json.dump(converted_yaml, sys.stdout, indent=2, sort_keys=True)

Expand Down
70 changes: 70 additions & 0 deletions yaml_conversion/converters.py
Expand Up @@ -49,6 +49,34 @@
'apiEndpoint': _SCRIPT_FIELDS,
}

_REQUEST_UTILIZATION_SCALING_FIELDS = (
'targetRequestCountPerSec',
'targetConcurrentRequests',
'targetRequestCountPerSecond',
)

_DISK_UTILIZATION_SCALING_FIELDS = (
'targetWriteBytesPerSec',
'targetWriteOpsPerSec',
'targetReadBytesPerSec',
'targetReadOpsPerSec',
'targetWriteBytesPerSecond',
'targetWriteOpsPerSecond',
'targetReadBytesPerSecond',
'targetReadOpsPerSecond',
)

_NETWORK_UTILIZATION_SCALING_FIELDS = (
'targetSentBytesPerSec',
'targetSentPacketsPerSec',
'targetReceivedBytesPerSec',
'targetReceivedPacketsPerSec',
'targetSentBytesPerSecond',
'targetSentPacketsPerSecond',
'targetReceivedBytesPerSecond',
'targetReceivedPacketsPerSecond',
)


def EnumConverter(prefix):
"""Create conversion function which translates from string to enum value.
Expand Down Expand Up @@ -186,6 +214,48 @@ def ExpirationToDuration(value):
return '%ss' % delta


def ConvertAutomaticScaling(automatic_scaling):
"""Moves several VM-specific automatic scaling parameters to submessages.
For example:
Input {
"targetSentPacketsPerSec": 10,
"targetReadOpsPerSec": 2,
"targetRequestCountPerSec": 3
}
Output {
"networkUtilization": {
"targetSentPacketsPerSec": 10
},
"diskUtilization": {
"targetReadOpsPerSec": 2
},
"requestUtilization": {
"targetRequestCountPerSec": 3
}
}
Args:
automatic_scaling: Result of converting automatic_scaling according to
schema.
Returns:
AutomaticScaling which has moved network/disk utilization related fields to
submessage.
"""
def MoveFieldsTo(field_names, target_field_name):
target = {}
for field_name in field_names:
if field_name in automatic_scaling:
target[field_name] = automatic_scaling[field_name]
del automatic_scaling[field_name]
if target:
automatic_scaling[target_field_name] = target
MoveFieldsTo(_REQUEST_UTILIZATION_SCALING_FIELDS, 'requestUtilization')
MoveFieldsTo(_DISK_UTILIZATION_SCALING_FIELDS, 'diskUtilization')
MoveFieldsTo(_NETWORK_UTILIZATION_SCALING_FIELDS, 'networkUtilization')
return automatic_scaling


def ConvertUrlHandler(handler):
"""Rejiggers the structure of the url handler based on its type.
Expand Down

0 comments on commit 2f16d99

Please sign in to comment.