You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cloudstack.apache.org by jburwell <gi...@git.apache.org> on 2015/12/04 06:18:38 UTC

[GitHub] cloudstack pull request: CLOUDSTACK-9095 : Hypervisor changes to s...

Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/1142#discussion_r46650119
  
    --- Diff: plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java ---
    @@ -1276,6 +1277,53 @@ public String toString() {
             }
         }
     
    +    public static class MetadataDef {
    +        Map<String, Object> customNodes = new HashMap<>();
    +
    +        public <T> T getMetadataNode(Class<T> fieldClass) {
    +            T field = (T) customNodes.get(fieldClass.getName());
    +            if (field == null) {
    +                try {
    +                    field = fieldClass.newInstance();
    +                    customNodes.put(field.getClass().getName(), field);
    +                } catch (InstantiationException e) {
    +                } catch (IllegalAccessException e) {
    +                }
    +            }
    +            return field;
    +        }
    +
    +        @Override
    +        public String toString() {
    +            StringBuilder fsBuilder = new StringBuilder();
    +            fsBuilder.append("<metadata>\n");
    +            for (Object field : customNodes.values()) {
    +                fsBuilder.append(field.toString());
    +            }
    +            fsBuilder.append("</metadata>\n");
    +            return fsBuilder.toString();
    +        }
    +    }
    +
    +    public static class NuageExtensionDef {
    +        private Map<String, String> addresses = Maps.newHashMap();
    +
    +        public void addNuageExtension(String macAddress, String vrIp) {
    +            addresses.put(macAddress, vrIp);
    +        }
    +
    +        @Override
    +        public String toString() {
    +            StringBuilder fsBuilder = new StringBuilder();
    +            for (Map.Entry<String, String> address : addresses.entrySet()) {
    +                fsBuilder.append("<nuage-extension>\n");
    +                fsBuilder.append("  <interface mac='" + address.getKey() + "' vsp-vr-ip='" + address.getValue() + "'></interface>\n");
    --- End diff --
    
    Performing string append operations when using a ``StringBuilder`` defeats purpose of the class.  Please change to the following to avoid unnecessary string re-allocation:
    ```
    fsBuilder.append("  <interface mac='")
                  .append(address.getKey() )
                  .append("' vsp-vr-ip='")
                  .append(address.getValue())
                  .append("'></interface>\n");
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---