Closed Clayun closed 1 year ago
with ServerCreationAction#setAllocation
, as single allocation can only be linked to specific Node. You can also use ServerCreationAction#setLocation
to select random node from desired location.
is setAllocation a port?
i mean setAllocation(25565),is that right?
Get the allocation
Node serverNode = pteroApplication.retrieveNodeById(1).execute(); // Get the node with the ID 1
//Get All Allocations
List<ApplicationAllocation> nodesAllocation = serverNode.retrieveAllocations().execute(); //Gets all available allocation
List<ApplicationAllocation> freeAllocs = nodesAllocation.stream().filter(alloc -> !alloc.isAssigned()).toList(); // Filters out all already used allocations
//Get one specific
List<ApplicationAllocation> portAllocs = serverNode.retrieveAllocationsByPort(25565).execute(); //Get all allocation with that specific port
ApplicationAllocation alloc = portAllocs.get(0); //Get the first allocation of the list
//null checks
That should do the job
if i don't specific location and allocations,only specific the port,is that work?
I suppose your panel will return an error, Your server needs at least one port to bind to, The ApplicationAllocation defines the port and the server
I never used the setLocation parameter, it's optional
Thet the code I use to make my servers
ServerCreationAction creationAction = this.api.createServer()
.setCPU(eggConfig.resources().cpu())
.setMemory(eggConfig.resources().memory(), DataType.MB)
.setSwap(eggConfig.resources().swap(), DataType.MB)
.setDisk(eggConfig.resources().disk(), DataType.MB)
.setName(name)
.setDescription("Server Generated by AtlasNetwork")
.setOwner(this.api.retrieveUserById(this.config.userId()).execute())
.startOnCompletion(true)
.setEgg(egg)
.setDockerImage(eggConfig.image());
I just tried it out, and the code above can run.
I only specific the port and it works. Without a location or allocations.
.setPort(creator.getPort())
So i guess if two node has same port in one server, it will return a error
That's useful, I will use it in my code too, thanks!
just to add some clarity here, since an allocation is tied to a node, if you set a specific allocation, you can guarantee the server will deploy on that node.
however if you use the setPort and setLocation methods, those are used to find an open port across all nodes, or a random port on a specific location.
so tldr; use setAllocation when you want to bind a server to a specific port & node, use setPort when you don’t care where the server lands
When I try to create a server and specify a Node, I can't find a place to do so. How can I proceed?