softlayer-java icon indicating copy to clipboard operation
softlayer-java copied to clipboard

SL Machines being indicated as released but are not actually released in the portal

Open deepashreeraghu opened this issue 8 years ago • 8 comments

We tried to release these 4 machines which are in Active state in SL. "chs-hosts-stdv2-mgmt-4167.prod.bluemix.net", "chs-hosts-stdv2-data-5076.prod.bluemix.net", "chs-hosts-stdv2-data-5077.prod.bluemix.net", "chs-hosts-stdv2-data-5078.prod.bluemix.net"

This is the SL API which was invoked and it returned a true. Because of which our system considered machines to be accepted for release.

SoftLayer_Virtual_Guest::deleteObject(https://softlayer.github.io/reference/services/SoftLayer_Virtual_Guest/deleteObject) is invoked to delete a host. com.softlayer.api.service.virtual.Guest.Service guestService = com.softlayer.api.service.virtual.Guest.service(client, nodeId); boolean result = guestService.deleteObject();

Once the request has been accepted, then we tried to run this API to check if the node was deleted: Service guestService = Guest.service(client, nodeId);

But it could not fetch the node id and returned the following error : 2018-04-24T06:47:50.43+0000 [APP/PROC/WEB/0] ERR [ERROR ] Unable to find object with id of '50074231'. 2018-04-24T06:47:50.43+0000 [APP/PROC/WEB/0] ERR Unable to find object with id of '50074231'.(code: SoftLayer_Exception_ObjectNotFound, status: 404) 2018-04-24T06:47:50.62+0000 [APP/PROC/WEB/0] ERR [ERROR ] Unable to find object with id of '50098757'. 2018-04-24T06:47:50.62+0000 [APP/PROC/WEB/0] ERR Unable to find object with id of '50098757'.(code: SoftLayer_Exception_ObjectNotFound, status: 404) 2018-04-24T06:47:50.87+0000 [APP/PROC/WEB/0] ERR [ERROR ] Unable to find object with id of '50105353'. 2018-04-24T06:47:50.87+0000 [APP/PROC/WEB/0] ERR Unable to find object with id of '50105353'.(code: SoftLayer_Exception_ObjectNotFound, status: 404)

As the node could not be fetched, it was considered to be deleted. But if checked on the portal the machines still exists.

When we fired a curl with the same id to fetch details it says that the host is active : curl --user : https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/50074231 | json_reformat { "accountId": 288698, "createDate": "2018-02-25T19:45:17+05:30", "dedicatedAccountHostOnlyFlag": false, "domain": "prod.bluemix.net", "fullyQualifiedDomainName": "chs-hosts-stdv2-mgmt-4167.prod.bluemix.net", "hostname": "chs-hosts-stdv2-mgmt-4167", "id": 50074231, "lastPowerStateId": null, "lastVerifiedDate": null, "maxCpu": 4, "maxCpuUnits": "CORE", "maxMemory": 16384, "metricPollDate": null, "modifyDate": "2018-02-25T19:47:39+05:30", "provisionDate": "2018-02-25T19:47:39+05:30", "startCpus": 4, "statusId": 1001, "typeId": 1, "uuid": "44a7859f-1662-427d-af47-d2b24f438221", "globalIdentifier": "b1dbb648-5673-404c-8b89-9c478bbb231c", "managedResourceFlag": false, "primaryBackendIpAddress": "10.186.64.12", "primaryIpAddress": "169.60.167.25", "status": { "keyName": "ACTIVE", "name": "Active" } }

Can you please provide us a fool proof method of releasing machines. Due the above we have more than 200 machines in released state in our DB but actually those machines are still active in SL.

deepashreeraghu avatar Apr 24 '18 08:04 deepashreeraghu

I tested it by using code lines you provided, and the deleteObject worked for me, the VSIs were deleted after some minutes.

I recommend canceling them through their billing item ids, the method is SoftLayer_Billing_Item::cancelItem, it is the most effective way to reclaim the VSIs.

Below is a sample code you can use to test it.

import com.softlayer.api.ApiClient;
import com.softlayer.api.RestApiClient;
import com.softlayer.api.service.virtual.Guest;
import com.softlayer.api.service.billing.Item;

public class CancelByBillingItemId {
    public static void main(String[] args) {
        // Declare username and api key
        String username = "set me";
        String apiKey = "set me";

        // Virtual guest id
        Long guestId = new Long(52055555);
        
        // Get Api Client and service
        ApiClient client = new RestApiClient().withCredentials(username, apiKey);
        Guest.Service guestService = Guest.service(client, guestId);

        try{
            // Retrieve the billing item
            Item billingItem = guestService.getBillingItem();
        
            // Cancel the VSI through the billing item id
            Item.Service billingService = Item.service(client, billingItem.getId());
            boolean isCancelled = billingService.cancelItem(true, true, "No longer needed", "customerNote");
            System.out.println("VirtualGuest was canceled: " + isCancelled);

        } catch (Exception e) {
            System.out.println("Error: " + e);
        }
    }
}

acamacho82 avatar Apr 24 '18 16:04 acamacho82

@deepashreeraghu I see a few calls to Virtual_Guest::deleteObject in our logs, but none for the IDs you mentioned above.

Are you able to cancel these with a simple "curl -X DELETE https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/50074231 " ?

" curl https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/50074231/deleteObject" should also work, but will need to be a GET request

My guess would be the user you are using with the java client might not have access to view or cancel these virtual guests.

allmightyspiff avatar Apr 24 '18 19:04 allmightyspiff

Thanks for the approaches, let us try this out and get back.

deepashreeraghu avatar Apr 25 '18 10:04 deepashreeraghu

Is there a way to track the status of the cancellation also? with billingService.cancelItem(true, true, "No longer needed", "customerNote") , we are only sure that cancellation was accepted, but we also want to follow through cancellation status until VM is deleted successfully.

bhankrisgm avatar May 15 '18 09:05 bhankrisgm

@bhankrisgm when the cancellation is accepted the system opens a cancellation ticket and starts transactions to reclaim the device, you can retrieve that information by using the methods getOpenCancellationTicket and getActiveTransaction .

The VSI is completely deleted when the ticket is closed and there aren't pending transactions. You could use operations like loops, threads, sleep, or wait to track that information but keep in mind you will not be able to retrieve a message like "Completed" when all pending transactions were completed, you will get the error SoftLayer_Exception_ObjectNotFound instead because the VSI is not listed anymore.

Some times you will notice that in the portal page the VSI is still listed, this could be due to the cookies and cache which have not been updated yet.

acamacho82 avatar May 15 '18 20:05 acamacho82

One minor clarification required on cancelAssociatedBillingItems parameter of billingService.cancelItem(). Does cancelAssociatedBillingItems =True imply that it cancels all associated Virtual Machines or just single VM ?

Suppose we had placed order 2 VMs in single order ,does VMs have same value for billingItem.getId()? I hope calling billingService.cancelItem(true, true, "No longer needed", "customerNote"); does not cancel both VMs?

The description of the 'cancelAssociatedBillingItems' seems to be incomplete in https://softlayer.github.io/reference/services/SoftLayer_Billing_Item/cancelItem/ :

cancelAssociatedBillingItems | boolean | This only applies to servers and virtual servers and will

bhankrisgm avatar May 29 '18 06:05 bhankrisgm

No, it doesn't. The billing item id is unique and it is linked to only one device or item, it means that each VSI will have its own billingItemId no matter that they had been created with a single order, and the cancellation will be effective only for the VSI you have selected.

The associated billing items are those ones that belong to the items you selected during the order (cpu, ram, disk, monitor, etc).

It seems that this is not required now, because I tested the cancelAssociatedBillingItems flag and the VSI is is cancelled with all its children billing items (ram, cpu, disk,etc) either it was set true or false. And I think this current behavior is correct because if FALSE is effective the system would continue to charge for those items that were not claimed.

acamacho82 avatar May 29 '18 19:05 acamacho82

There hasn't been any updates on this issue in a few years, so going ahead and closing.

camporter avatar Mar 24 '20 22:03 camporter