Skip to content
This repository was archived by the owner on May 25, 2021. It is now read-only.
This repository was archived by the owner on May 25, 2021. It is now read-only.

Server State - Null Ptr or "UNKNOWN_ATTRIBUTE" #6

@michaelfclarke

Description

@michaelfclarke

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."
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions