-
Notifications
You must be signed in to change notification settings - Fork 2
Server State - Null Ptr or "UNKNOWN_ATTRIBUTE" #6
Description
I am trying to use the API to create a server, by cloning a template.
I believe I am doing the "right" thing, based on this documentation: https://www.upcloud.com/api/1.2.6/8-servers/#create-server
Essentially this is the code I have:
ServerApi serverAPI = new ServerApi(client);
Server server = new Server();
server.setZone("uk-lon1");
server.setTitle(fullServerName);
server.setHostname(fullServerName);
server.setCoreNumber(new BigDecimal(2));
server.setMemoryAmount(new BigDecimal(2048));
ServerStorageDevices devices = new ServerStorageDevices();
StorageDevice sd = new StorageDevice();
sd.setAction("clone");
sd.setStorage("014a041c-7eb3-48fb-9c7c-e09e70c8274f");
sd.setTitle(fullServerName);
sd.setSize(new BigDecimal(50));
sd.setTier("maxiops");
sd.setPartOfPlan(PartOfPlanEnum.YES);
devices.addStorageDeviceItem(sd);
server.setStorageDevices(devices);
server.setBootOrder(BootOrderEnum.DISK);
server.passwordDelivery(PasswordDeliveryEnum.NONE);
CreateServerRequest createServerRequest = new CreateServerRequest();
createServerRequest.setServer(server);
return serverAPI.createServer(createServerRequest);
However, there is an issue when actually sending the request to the RESTful API. If I do not include a ServerState value on the Server object, I get a Null Pointer Exception:
2018-03-07 15:35:33,292 ERROR [http-nio-8086-exec-6] () Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
java.lang.NullPointerException
at com.upcloud.client.models.ServerState$Adapter.write(ServerState.java:63)
at com.upcloud.client.models.ServerState$Adapter.write(ServerState.java:60)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:99)
...
If I include a ServerState on the Server object, I get an "UNKNOWN_ATTRIBUTE" response from the server:
2018-03-07 15:06:12,453 INFO [http-nio-8086-exec-5] () Request Content-type: application/json
Bad Request
{
"error" : {
"error_code" : "UNKNOWN_ATTRIBUTE",
"error_message" : "The request body contains an unknown attribute state."
}
}