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

    https://github.com/apache/brooklyn-server/pull/501#discussion_r93615497
  
    --- Diff: 
locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java
 ---
    @@ -1484,6 +1493,48 @@ public Template buildTemplate(ComputeService 
computeService, ConfigBag config, C
             return template;
         }
     
    +
    +    /**
    +     * See {@link https://issues.apache.org/jira/browse/JCLOUDS-1108}.
    +     * 
    +     * In jclouds 1.9.x and 2.0.0, google-compute-engine hardwareId must 
be in the long form. For 
    +     * example {@code 
https://www.googleapis.com/compute/v1/projects/jclouds-gce/zones/us-central1-a/machineTypes/n1-standard-1}.
    +     * It is much nicer to support the short-form (e.g. {@code 
n1-standard-1}), and to construct 
    +     * the long-form from this.
    +     * 
    +     * The "zone" in the long-form needs to match the region (see {@link 
#getRegion()}).
    +     * 
    +     * The ideal would be for jclouds to do this. But that isn't available 
yet - in the mean time,
    +     * we can make life easier for our users with the code below.
    +     * 
    +     * Second best would have been handling this in {@link 
TemplateBuilderCustomizers#hardwareId()}. 
    +     * However, that code doesn't have enough context to know what to do 
(easily!). It is passed
    +     * {@code apply(TemplateBuilder tb, ConfigBag props, Object v)}, so 
doesn't even know which 
    +     * provider it is being called for (without doing ugly/brittle digging 
in the {@code props}
    +     * that it is given).
    +     * 
    +     * Therefore we do the transform here.
    +     */
    +    private String transformHardwareId(String hardwareId, ConfigBag 
config) {
    +        String provider = getProvider();
    +        String region = getRegion();
    +        if (Strings.isBlank(region)) region = config.get(CLOUD_REGION_ID);
    +        
    +        if (!"google-compute-engine".equals(provider)) {
    +            return hardwareId;
    +        }
    +        if (hardwareId == null || 
hardwareId.toLowerCase().startsWith("http") || hardwareId.contains("/")) {
    --- End diff --
    
    Agreed - given it's a private method, we can be stricter about what is 
passed in (e.g. throw `NullPointerException` on null) particularly as the one 
caller guards the call with `Strings.isNonBlank(config.get(HARDWARE_ID))`.


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to