Juan Hernandez has uploaded a new change for review. Change subject: codegen: Use the same broker naming rules than the Java SDK ......................................................................
codegen: Use the same broker naming rules than the Java SDK This patch changes the generator of the Python SDK so that it uses the same rules to calculate the names of the broker classes. This is an step towards merging both SDK generators. Change-Id: I45a315bc48be0a8ca6dacd03c1f3dfff7cea6f8f Signed-off-by: Juan Hernandez <[email protected]> --- M generator/src/main/java/org/ovirt/engine/sdk/generator/rsdl/BrokerRules.java 1 file changed, 138 insertions(+), 13 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine-sdk refs/changes/21/38221/1 diff --git a/generator/src/main/java/org/ovirt/engine/sdk/generator/rsdl/BrokerRules.java b/generator/src/main/java/org/ovirt/engine/sdk/generator/rsdl/BrokerRules.java index 68e1f4f..92d3a29 100644 --- a/generator/src/main/java/org/ovirt/engine/sdk/generator/rsdl/BrokerRules.java +++ b/generator/src/main/java/org/ovirt/engine/sdk/generator/rsdl/BrokerRules.java @@ -18,10 +18,13 @@ import org.ovirt.engine.sdk.generator.utils.Tree; +import java.util.HashMap; +import java.util.Map; + import static java.util.stream.Collectors.joining; /** - * This class contains methods that implement various rules and calculations associated to broker class names, like + * This class contains methods that implement various rules and calculations associated with broker class names, like * calculating the name of the broker class corresponding to a location. */ public class BrokerRules { @@ -33,27 +36,149 @@ * @return the name of the broker class, or {@code null} if it can't be determined */ public static String getBrokerType(Tree<Location> tree) { + // First we need to check if there is an exception for the given location: + String path = tree.getPath().stream().skip(1).collect(joining("/")); + String exception = BROKER_TYPE_EXCEPTIONS.get(path); + if (exception != null) { + return exception; + } + // The name of a broker type is calculated concatenating the names of all the parent entity resources (not the // collections, as they are redundant) and the name of the resource itself: return tree.getBranch().stream() .skip(1) .filter(x -> LocationRules.isEntity(x) || x == tree) - .map(BrokerRules::getCapitalizedName) + .map(SchemaRules::getSchemaType) .collect(joining()); } /** - * Returns the capitalized name of a location. For example, if the name of the location is {@code cluster} it will - * return {@code Cluster}. - * - * @param tree the location to check - * @return the capitalized name of the location + * These exceptions are needed for backwards compatibility, as the previous version of the generator used an + * algorithm to calculate singulars from plurals and the other way around. This algorithm isn't used any longer, but + * the resulting class names can't be changed. */ - private static String getCapitalizedName(Tree<Location> tree) { - String name = LocationRules.getName(tree); - if (name != null && !name.isEmpty()) { - name = Character.toUpperCase(name.charAt(0)) + name.substring(1); - } - return name; + private static final Map<String, String> BROKER_TYPE_EXCEPTIONS = new HashMap<>(); + + static { + // These exceptions are needed for backwards compatibility. + BROKER_TYPE_EXCEPTIONS.put( + "capabilities/{capabilitie:id}", + "VersionCaps" + ); + BROKER_TYPE_EXCEPTIONS.put( + "clusters/{cluster:id}/glustervolumes/{glustervolume:id}/bricks/{brick:id}", + "ClusterGlusterVolumeGlusterBrick" + ); + BROKER_TYPE_EXCEPTIONS.put( + "clusters/{cluster:id}/glustervolumes/{glustervolume:id}/bricks/{brick:id}/statistics", + "ClusterGlusterVolumeGlusterBrickStatistics" + ); + BROKER_TYPE_EXCEPTIONS.put( + "clusters/{cluster:id}/glustervolumes/{glustervolume:id}/bricks/{brick:id}/statistics/{statistic:id}", + "ClusterGlusterVolumeGlusterBrickStatistic" + ); + BROKER_TYPE_EXCEPTIONS.put( + "clusters/{cluster:id}/glustervolumes/{glustervolume:id}/bricks", + "ClusterGlusterVolumeGlusterBricks" + ); + BROKER_TYPE_EXCEPTIONS.put( + "datacenters/{datacenter:id}/clusters/{cluster:id}/glustervolumes/{glustervolume:id}/bricks/{brick:id}", + "DataCenterClusterGlusterVolumeGlusterBrick" + ); + BROKER_TYPE_EXCEPTIONS.put( + "datacenters/{datacenter:id}/clusters/{cluster:id}/glustervolumes/{glustervolume:id}/bricks/{brick:id}/statistics", + "DataCenterClusterGlusterVolumeGlusterBrickStatistics" + ); + BROKER_TYPE_EXCEPTIONS.put( + "datacenters/{datacenter:id}/clusters/{cluster:id}/glustervolumes/{glustervolume:id}/bricks/{brick:id}/statistics/{statistic:id}", + "DataCenterClusterGlusterVolumeGlusterBrickStatistic" + ); + BROKER_TYPE_EXCEPTIONS.put( + "datacenters/{datacenter:id}/clusters/{cluster:id}/glustervolumes/{glustervolume:id}/bricks", + "DataCenterClusterGlusterVolumeGlusterBricks" + ); + BROKER_TYPE_EXCEPTIONS.put( + "hosts/{host:id}/nics", + "HostNICs" + ); + BROKER_TYPE_EXCEPTIONS.put( + "hosts/{host:id}/nics/{nic:id}", + "HostNIC" + ); + BROKER_TYPE_EXCEPTIONS.put( + "hosts/{host:id}/nics/{nic:id}/labels", + "HostNICLabels" + ); + BROKER_TYPE_EXCEPTIONS.put( + "hosts/{host:id}/nics/{nic:id}/labels/{label:id}", + "HostNICLabel" + ); + BROKER_TYPE_EXCEPTIONS.put( + "hosts/{host:id}/nics/{nic:id}/statistics", + "HostNICStatistics" + ); + BROKER_TYPE_EXCEPTIONS.put( + "hosts/{host:id}/nics/{nic:id}/statistics/{statistic:id}", + "HostNICStatistic" + ); + BROKER_TYPE_EXCEPTIONS.put( + "instancetypes/{instancetype:id}/nics", + "InstanceTypeNICs" + ); + BROKER_TYPE_EXCEPTIONS.put( + "schedulingpolicies/{schedulingpolicie:id}/balances/{balance:id}", + "SchedulingPolicyBalance" + ); + BROKER_TYPE_EXCEPTIONS.put( + "schedulingpolicies/{schedulingpolicie:id}/balances", + "SchedulingPolicyBalances" + ); + BROKER_TYPE_EXCEPTIONS.put( + "schedulingpolicies/{schedulingpolicie:id}/filters/{filter:id}", + "SchedulingPolicyFilter" + ); + BROKER_TYPE_EXCEPTIONS.put( + "schedulingpolicies/{schedulingpolicie:id}/filters", + "SchedulingPolicyFilters" + ); + BROKER_TYPE_EXCEPTIONS.put( + "schedulingpolicies/{schedulingpolicie:id}", + "SchedulingPolicy" + ); + BROKER_TYPE_EXCEPTIONS.put( + "schedulingpolicies/{schedulingpolicie:id}/weights", + "SchedulingPolicyWeights" + ); + BROKER_TYPE_EXCEPTIONS.put( + "schedulingpolicies/{schedulingpolicie:id}/weights/{weight:id}", + "SchedulingPolicyWeight" + ); + BROKER_TYPE_EXCEPTIONS.put( + "templates/{template:id}/nics", + "TemplateNICs" + ); + BROKER_TYPE_EXCEPTIONS.put( + "vms/{vm:id}/nics", + "VMNICs" + ); + BROKER_TYPE_EXCEPTIONS.put( + "vms/{vm:id}/numanodes/{numanode:id}", + "VMVirtualNumaNode" + ); + BROKER_TYPE_EXCEPTIONS.put( + "vms/{vm:id}/numanodes", + "VMVirtualNumaNodes" + ); + + // These exceptions are needed to handle the special case of host storage, as the name of the collection and + // the name of the entity are the same, and both will result in the decorator name "HostStorage". + BROKER_TYPE_EXCEPTIONS.put( + "hosts/{host:id}/storage/{storage:id}", + "HostStorage" + ); + BROKER_TYPE_EXCEPTIONS.put( + "hosts/{host:id}/storage", + "HostStorages" + ); } } -- To view, visit https://gerrit.ovirt.org/38221 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I45a315bc48be0a8ca6dacd03c1f3dfff7cea6f8f Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine-sdk Gerrit-Branch: master Gerrit-Owner: Juan Hernandez <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
