Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

JSONException when trying to retrieve allocation info #83

Open
tomkeuper opened this issue Oct 23, 2024 · 6 comments
Open

JSONException when trying to retrieve allocation info #83

tomkeuper opened this issue Oct 23, 2024 · 6 comments

Comments

@tomkeuper
Copy link

After creating a server using a ServerCreationAction I want to retrieve the allocation details and store the IP and Port number.
But when trying to get this data using the AplicationServer#retrieveDefaultAllocation() method I get the following error:

Exception in thread "Thread-7" org.json.JSONException: JSONObject["data"] not found.
	at org.json.JSONObject.get(JSONObject.java:570)
	at org.json.JSONObject.getJSONArray(JSONObject.java:763)
	at com.mattmalec.pterodactyl4j.application.entities.impl.ApplicationServerImpl.getAllocations(ApplicationServerImpl.java:116)
	at com.mattmalec.pterodactyl4j.application.entities.impl.ApplicationServerImpl.retrieveDefaultAllocation(ApplicationServerImpl.java:127)
	at com.fyreblox.democreator.DemoServer.lambda$setupServer$1(DemoServer.java:126)
	at java.lang.Thread.run(Thread.java:748)

The server has been created on the node and it does have allocation details:
image

The same error also appears when trying to use the AplicationServer#getAllocations() method

@tomkeuper
Copy link
Author

tomkeuper commented Oct 23, 2024

Starting to think its an issue with ptero itself. The return value of allocations is null

{
    "object": "server",
    "attributes": {
        "id": 284,
        "external_id": null,
        "uuid": "4600605e-6e5a-4f29-b3c4-fc01b7aa1192",
        "identifier": "4600605e",
        "name": "Demo Server",
        "description": ".",
        "status": "suspended",
        "suspended": true,
        "limits": {
            "memory": 1024,
            "swap": 0,
            "disk": 3072,
            "io": 500,
            "cpu": 0,
            "threads": null,
            "oom_disabled": true
        },
        "feature_limits": {
            "databases": 0,
            "allocations": 1,
            "backups": 0
        },
        "user": 25,
        "node": 9,
        "allocation": 401,
        "nest": 1,
        "egg": 15,
        "container": {
            "startup_command": "java -Xms128M -Xmx{{SERVER_MEMORY}}M -jar {{SERVER_JARFILE}}",
            "image": "ghcr.io/pterodactyl/yolks:java_17",
            "installed": 1,
            "environment": {
                "SERVER_JARFILE": "paperclip.jar",
                "STARTUP": "java -Xms128M -Xmx{{SERVER_MEMORY}}M -jar {{SERVER_JARFILE}}",
                "P_SERVER_LOCATION": "loc1",
                "P_SERVER_UUID": "4600605e-6e5a-4f29-b3c4-fc01b7aa1192",
                "P_SERVER_ALLOCATION_LIMIT": 1
            }
        },
        "updated_at": "2024-10-23T21:14:20+00:00",
        "created_at": "2024-10-23T21:04:20+00:00",
        "relationships": {
            "allocations": {
                "object": "null_resource",
                "attributes": null
            },
            "user": {
                "object": "user",
                "attributes": {
                    "id": 25,
                    "external_id": null,
                    "uuid": "62f1bf21-52ea-4b0c-af42-3fe4754e9a61",
                    "username": "serviceaccount1",
                    "email": "il.",
                    "first_name": "Server",
                    "last_name": "Creator",
                    "language": "en",
                    "root_admin": false,
                    "2fa": false,
                    "created_at": "2024-08-17T19:15:07+00:00",
                    "updated_at": "2024-08-17T19:15:07+00:00"
                }
            },
            "subusers": {
                "object": "list",
                "data": []
            },
            "nest": {
                "object": "nest",
                "attributes": {
                    "id": 1,
                    "uuid": "b3acd942-0348-43d7-8f9f-e2f14b357c4c",
                    "author": "support@pterodactyl.io",
                    "name": "Minecraft",
                    "description": "Minecraft - the classic game from Mojang. With support for Vanilla MC, Spigot, and many others!",
                    "created_at": "2019-07-29T15:23:55+00:00",
                    "updated_at": "2019-07-29T15:23:55+00:00"
                }
            },
            "egg": {
                "object": "egg",
                "attributes": {
                    "id": 15,
                    "uuid": "23cc8edb-ab30-46e8-bcb3-a4431a4bf117",
                    "name": "mo Server",
                    "nest": 1,
                    "author": "ail.com",
                    "description": "A demo se",
                    "docker_image": "quay.io/pterodactyl/core:java",
                    "docker_images": {
                        "quay.io/pterodactyl/core:java": "quay.io/pterodactyl/core:java"
                    },
                    "config": {
                        "files": {
                            "server.properties": {
                                "parser": "properties",
                                "find": {
                                    "server-ip": "0.0.0.0",
                                    "server-port": "{{server.build.default.port}}"
                                }
                            }
                        },
                        "startup": {
                            "done": ")! For help, type "
                        },
                        "stop": "stop",
                        "logs": [],
                        "file_denylist": null,
                        "extends": null
                    },
                    "startup": "java -Xms128M -Xmx{{SERVER_MEMORY}}M -jar {{SERVER_JARFILE}}",
                    "script": {
                        "privileged": true,
                        "install": "#!/bin/ash\r\n# Server Installation Script\r\n#\r\n# Server Files: /mnt/server\r\napk add --no-cache --update curl jq\r\ncd /mnt/server\r\n\r\nrm -R *\r\necho -e \"Downloading bedwars1058.zip\"\r\ncurl -o server.zip https://fy.zip\r\n\r\necho -e \"Unzipping server.zip\"\r\nunzip -o server.zip\r\necho -e \"Downloading server.properties\"\r\ncurl -o server.properties https://fyerver/properties/server.properties",
                        "entry": "ash",
                        "container": "alpine:3.9",
                        "extends": null
                    },
                    "created_at": "2019-08-01T20:38:50+00:00",
                    "updated_at": "2019-10-11T09:35:43+00:00"
                }
            },
            "location": {
                "object": "location",
                "attributes": {
                    "id": 1,
                    "short": "loc1",
                    "long": "",
                    "updated_at": "2019-07-30T08:24:06+00:00",
                    "created_at": "2019-07-30T08:24:06+00:00"
                }
            },
            "node": {
                "object": "null_resource",
                "attributes": null
            },
            "databases": {
                "object": "null_resource",
                "attributes": null
            }
        }
    }
}

@mattmalec
Copy link
Owner

i've never seen the null_resource object before. perhaps it's something with the panel or how the database is returning the data to your panel?

@tomkeuper
Copy link
Author

Is there a way for me to check? The data on the panel itself seems fine to me
image

@tomkeuper
Copy link
Author

image
Found this in the Pterodactyl discord

@tomkeuper
Copy link
Author

After updating the API key with one that does have permissions to read allocations it works. Maybe an option to add a check if it has a null_resource type and throw an invallid permission error?

@mattmalec
Copy link
Owner

ah yep, that would make sense. it's hard to tell if null_resource is a permission error since it doesn't directly clarify that, but we should more gracefully handle that case. also worth documenting the possibility that a null_resource could be no perms

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants