Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

SL-API issue pagination of virtual machines with masks #52

Open
isrfig opened this issue May 17, 2018 · 4 comments
Open

SL-API issue pagination of virtual machines with masks #52

isrfig opened this issue May 17, 2018 · 4 comments

Comments

@isrfig
Copy link

isrfig commented May 17, 2018

The issue we're facing is to retrieve the relational properties of a list of SoftLayer_Virtual_Guest using pagination. We use masks to get the relational properties like power state, os, datacenter data etc.... of a virtual machine as there are many vms in a particular account the api throws an out of memory error, the service.getObject method ignores pagination, so I used service.getVirtualGuests() which the pagination works but only brings the local properties of the vm, if I put a mask to get the relational properties in the service, service.getVirtualGuests() thows another error, one way I found to do this is use service.getVirtualGuests() to get the basic info and then use Guest.Service virtualGuestsService = Guest.service(client, guest.getId()); with a mask to get the relational properties for each vm in a loop, but this will generate thousands of api calls, so Im not sure if this is the best/correct approach, the best would be if I could use service.getVirtualGuests() with the mask to get the relational properties, attached is a sample code.
vm-pagination.txt

@acamacho82
Copy link
Contributor

acamacho82 commented May 17, 2018

Yeah I got the same behavior, there is no way to set resultLimits and masks in order to be used in the same method.

Result limit is being ignored with the following code:

service.setResultLimit(new ResultLimit(offset, limit));
service.withMask().virtualGuests().powerState().name();
List<Guest> listGuests = service.getObject().getVirtualGuests();

And on this case, when removing getObject(), the object-mask doesn't work.

service.setResultLimit(new ResultLimit(offset, limit));
service.withMask().virtualGuests().powerState().name();
List<Guest> listGuests = service.getVirtualGuests();

It seems that it could be fixed here #19

@isrfig the workaround you are using isn't the best on this case but I think it is still correct. In other cases this approach is the best solution because some relational properties have a lot of data and/or the mask is to long in depth (for example, to retrieve detailed information of items of all invoices in the account)

@allmightyspiff
Copy link
Member

This may just be a bug with the java-client, I think the SLAPI itself supports resultLimits and objectMasks.

I'll mark this as a bug for future development. I don't have an ETA, so your work around might be best.

Just keep in mind there is a rate limit imposed by the API, so you may have to watch out for a rate limit exception and be prepared to sleep for a second before continuing.

@allmightyspiff
Copy link
Member

allmightyspiff commented Jun 14, 2018

@isrfig instead of using withMask() you can set the object mask manually with setMask(string) which can be used to work around this bug until we figure out a more clever solution.

ApiClient client = new RestApiClient().withCredentials(user, apiKey);
((RestApiClient) client).setLoggingEnabled(true);
Account.Service accountService = Account.service(client);
accountService.setResultLimit(new ResultLimit(10));

accountService.setMask("mask[id, hostname, powerState[name]]");
    for (Guest bd : accountService.getVirtualGuests()) {
    System.out.println("BD: " + bd.getId() + " - " + bd.getHostname());
}

@camporter
Copy link
Member

The result limit is not being ignored in the initial case. The result limit applies to the base object being queried. In the case of a getObject request, it won't do anything, as the virtual guests are masked off the account which is result limited, not the virtual guests.

The string-based mask is an available workaround for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants