Skip to content
This repository was archived by the owner on Aug 6, 2025. It is now read-only.

Commit 27d2e20

Browse files
authored
Fix digitalocean2 NumberFormatException (#216)
Changed org.jclouds.digitalocean2.domain.Action.id from int to long in order to fit large numbers sent in responses. This appears to be a misinterpretation of DigitalOceans ApiDocs, because in these docs, they fail to specify the size of their "integer" type. Therefore, I looked into their official GO Api sources. There, they use the int type, which is platform dependant and usually has 64 bits. Therefore our digitalocean2 provider, should be refactored, changing all Ids from int/Integer to long/Long.
1 parent 9ced58a commit 27d2e20

File tree

8 files changed

+19
-19
lines changed

8 files changed

+19
-19
lines changed

providers/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/config/DigitalOcean2ComputeServiceContextModule.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ protected Predicate<Integer> provideDropletTerminatedPredicate(final DigitalOcea
123123

124124
@Provides
125125
@Named(TIMEOUT_IMAGE_AVAILABLE)
126-
protected Predicate<Integer> provideImageAvailablePredicate(final DigitalOcean2Api api, Timeouts timeouts,
126+
protected Predicate<Long> provideImageAvailablePredicate(final DigitalOcean2Api api, Timeouts timeouts,
127127
PollPeriod pollPeriod) {
128128
return retry(new ActionDonePredicate(api), timeouts.imageAvailable, pollPeriod.pollInitialPeriod,
129129
pollPeriod.pollMaxPeriod);
@@ -138,14 +138,14 @@ protected Predicate<Region> provideRegionAvailablePredicate(final DigitalOcean2A
138138
}
139139

140140
@Provides
141-
protected Predicate<Integer> provideActionCompletedPredicate(final DigitalOcean2Api api, Timeouts timeouts,
141+
protected Predicate<Long> provideActionCompletedPredicate(final DigitalOcean2Api api, Timeouts timeouts,
142142
PollPeriod pollPeriod) {
143143
return retry(new ActionDonePredicate(api), timeouts.imageAvailable, pollPeriod.pollInitialPeriod,
144144
pollPeriod.pollMaxPeriod);
145145
}
146146

147147
@VisibleForTesting
148-
static class ActionDonePredicate implements Predicate<Integer> {
148+
static class ActionDonePredicate implements Predicate<Long> {
149149

150150
private final DigitalOcean2Api api;
151151

@@ -154,7 +154,7 @@ public ActionDonePredicate(DigitalOcean2Api api) {
154154
}
155155

156156
@Override
157-
public boolean apply(Integer input) {
157+
public boolean apply(Long input) {
158158
checkNotNull(input, "action id cannot be null");
159159
Action current = api.actionApi().get(input);
160160
switch (current.status()) {

providers/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/extensions/DigitalOcean2ImageExtension.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ public class DigitalOcean2ImageExtension implements ImageExtension {
6060
protected Logger logger = Logger.NULL;
6161

6262
private final DigitalOcean2Api api;
63-
private final Predicate<Integer> imageAvailablePredicate;
63+
private final Predicate<Long> imageAvailablePredicate;
6464
private final Predicate<Integer> nodeRunningPredicate;
6565
private final Function<ImageInRegion, Image> imageTransformer;
6666
private final ListeningExecutorService userExecutor;
6767

6868
@Inject DigitalOcean2ImageExtension(DigitalOcean2Api api,
69-
@Named(TIMEOUT_IMAGE_AVAILABLE) Predicate<Integer> imageAvailablePredicate,
69+
@Named(TIMEOUT_IMAGE_AVAILABLE) Predicate<Long> imageAvailablePredicate,
7070
@Named(TIMEOUT_NODE_RUNNING) Predicate<Integer> nodeRunningPredicate,
7171
Function<ImageInRegion, Image> imageTransformer,
7272
@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor) {

providers/digitalocean2/src/main/java/org/jclouds/digitalocean2/domain/Action.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static Status fromValue(String value) {
4949
}
5050
}
5151

52-
public abstract int id();
52+
public abstract long id();
5353
public abstract Status status();
5454
public abstract String type();
5555
public abstract Date startedAt();
@@ -61,7 +61,7 @@ public static Status fromValue(String value) {
6161

6262
@SerializedNames({ "id", "status", "type", "started_at", "completed_at", "resource_id", "resource_type",
6363
"region", "region_slug" })
64-
public static Action create(int id, Status status, String type, Date startedAt, Date completedAt, long resourceId,
64+
public static Action create(long id, Status status, String type, Date startedAt, Date completedAt, long resourceId,
6565
String resourceType, Region region, String regionSlug) {
6666
return new AutoValue_Action(id, status, type, startedAt, completedAt, resourceId, resourceType, region,
6767
regionSlug);

providers/digitalocean2/src/main/java/org/jclouds/digitalocean2/domain/DropletCreate.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ public abstract static class Links {
3535

3636
@AutoValue
3737
public abstract static class ActionLink {
38-
public abstract int id();
38+
public abstract long id();
3939
public abstract String rel();
4040
public abstract URI href();
4141

4242
@SerializedNames({"id", "rel", "href"})
43-
public static ActionLink create(int id, String rel, URI href) {
43+
public static ActionLink create(long id, String rel, URI href) {
4444
return new AutoValue_DropletCreate_Links_ActionLink(id, rel, href);
4545
}
4646

providers/digitalocean2/src/main/java/org/jclouds/digitalocean2/features/ActionApi.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ protected IterableWithMarker<Action> fetchPageUsingOptions(ListOptions options,
107107
@Path("/{id}")
108108
@Fallback(NullOnNotFoundOr404.class)
109109
@Nullable
110-
Action get(@PathParam("id") int id);
110+
Action get(@PathParam("id") long id);
111111

112112
}
113113

providers/digitalocean2/src/test/java/org/jclouds/digitalocean2/compute/config/ActionDonePredicateTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ public void testActionStatusOk() {
4646
replay(actionApi, api);
4747

4848
ActionDonePredicate predicate = new ActionDonePredicate(api);
49-
assertTrue(predicate.apply(1));
50-
assertFalse(predicate.apply(2));
49+
assertTrue(predicate.apply(1L));
50+
assertFalse(predicate.apply(2L));
5151
}
5252

5353
public void testActionStatusError() {
@@ -61,7 +61,7 @@ public void testActionStatusError() {
6161
ActionDonePredicate predicate = new ActionDonePredicate(api);
6262

6363
try {
64-
predicate.apply(1);
64+
predicate.apply(1L);
6565
fail("Method should have thrown an IllegalStateException");
6666
} catch (IllegalStateException ex) {
6767
assertEquals(ex.getMessage(), "Resource is in invalid status: ERRORED");

providers/digitalocean2/src/test/java/org/jclouds/digitalocean2/internal/BaseDigitalOcean2ApiLiveTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
public class BaseDigitalOcean2ApiLiveTest extends BaseApiLiveTest<DigitalOcean2Api> {
4747

48-
private Predicate<Integer> actionCompleted;
48+
private Predicate<Long> actionCompleted;
4949
private Predicate<Integer> nodeTerminated;
5050
private Predicate<Integer> nodeStopped;
5151
private Predicate<Integer> nodeRunning;
@@ -64,7 +64,7 @@ public BaseDigitalOcean2ApiLiveTest() {
6464

6565
@Override protected DigitalOcean2Api create(Properties props, Iterable<Module> modules) {
6666
Injector injector = newBuilder().modules(modules).overrides(props).buildInjector();
67-
actionCompleted = injector.getInstance(Key.get(new TypeLiteral<Predicate<Integer>>(){}));
67+
actionCompleted = injector.getInstance(Key.get(new TypeLiteral<Predicate<Long>>(){}));
6868
nodeTerminated = injector.getInstance(Key.get(new TypeLiteral<Predicate<Integer>>(){},
6969
Names.named(TIMEOUT_NODE_TERMINATED)));
7070
nodeStopped = injector.getInstance(Key.get(new TypeLiteral<Predicate<Integer>>(){},
@@ -79,7 +79,7 @@ public BaseDigitalOcean2ApiLiveTest() {
7979
.build();
8080
}
8181

82-
protected void assertActionCompleted(int actionId) {
82+
protected void assertActionCompleted(long actionId) {
8383
assertTrue(actionCompleted.apply(actionId), String.format("Action %s did not complete in the configured timeout", actionId));
8484
}
8585

providers/digitalocean2/src/test/resources/droplet-create-res.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
"links": {
2727
"actions": [
2828
{
29-
"id": 35383956,
29+
"id": 2512718872,
3030
"rel": "create",
31-
"href": "https://api.digitalocean.com/v2/actions/35383956"
31+
"href": "https://api.digitalocean.com/v2/actions/2512718872"
3232
}
3333
]
3434
}

0 commit comments

Comments
 (0)