You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jclouds.apache.org by ah...@gmail.com, ah...@gmail.com on 2019/04/18 18:01:53 UTC

Clouds Ec2 Provider should return RunNodesException instead of AWSResponseException when create tag fails

In the code https://github.com/jclouds/jclouds/blob/master/apis/ec2/src/main/java/org/jclouds/ec2/compute/EC2ComputeService.java#L151

If createNdoesInGroup fails to create a tag (addTagsAndNamesToInstancesInRegion fails), it currently returns AWSResponseException. The caller has no way to cleanup the the failed node as the exception doesn't have the node id field. It should return RunNodesException which has fields containing failed nodes. The caller can then remove such node and retry. To repro the issue try to create a node with name larger than 300 character, it will create nodes with empty name and possibly multiple of them if caller retries.

 @Override
   public Set<? extends NodeMetadata> createNodesInGroup(String group, int count, final Template template)
            throws RunNodesException {
      Set<? extends NodeMetadata> nodes = super.createNodesInGroup(group, count, template);
      String region = AWSUtils.getRegionFromLocationOrNull(template.getLocation());

      if (client.getTagApiForRegion(region).isPresent()) {
         Map<String, String> common = metadataAndTagsAsValuesOfEmptyString(template.getOptions());
         if (generateInstanceNames || !common.isEmpty() || !template.getOptions().getNodeNames().isEmpty()) {
            return addTagsAndNamesToInstancesInRegion(common, template.getOptions().getNodeNames(),
                    nodes, region, group);
         }
      }
      return nodes;
   }


Re: Clouds Ec2 Provider should return RunNodesException instead of AWSResponseException when create tag fails

Posted by Ignasi Barrera <na...@apache.org>.
That looks like a reasonable fix. Would you like to try opening a PR to fix
that?

On Fri, 19 Apr 2019 at 00:38, ahsankhanmail@gmail.com <
ahsankhanmail@gmail.com> wrote:

> In the code
> https://github.com/jclouds/jclouds/blob/master/apis/ec2/src/main/java/org/jclouds/ec2/compute/EC2ComputeService.java#L151
>
> If createNdoesInGroup fails to create a tag
> (addTagsAndNamesToInstancesInRegion fails), it currently returns
> AWSResponseException. The caller has no way to cleanup the the failed node
> as the exception doesn't have the node id field. It should return
> RunNodesException which has fields containing failed nodes. The caller can
> then remove such node and retry. To repro the issue try to create a node
> with name larger than 300 character, it will create nodes with empty name
> and possibly multiple of them if caller retries.
>
>  @Override
>    public Set<? extends NodeMetadata> createNodesInGroup(String group, int
> count, final Template template)
>             throws RunNodesException {
>       Set<? extends NodeMetadata> nodes = super.createNodesInGroup(group,
> count, template);
>       String region =
> AWSUtils.getRegionFromLocationOrNull(template.getLocation());
>
>       if (client.getTagApiForRegion(region).isPresent()) {
>          Map<String, String> common =
> metadataAndTagsAsValuesOfEmptyString(template.getOptions());
>          if (generateInstanceNames || !common.isEmpty() ||
> !template.getOptions().getNodeNames().isEmpty()) {
>             return addTagsAndNamesToInstancesInRegion(common,
> template.getOptions().getNodeNames(),
>                     nodes, region, group);
>          }
>       }
>       return nodes;
>    }
>
>