Bug 1320711

Summary: Async Bind by product ID Job throws ClassCastException
Product: [Community] Candlepin Reporter: Michael Stead <mstead>
Component: candlepinAssignee: Michael Stead <mstead>
Status: CLOSED CURRENTRELEASE QA Contact: Katello QA List <katello-qa-list>
Severity: high Docs Contact:
Priority: high    
Version: 2.0CC: bcourt, redakkan
Target Milestone: ---Keywords: Triaged
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2019-09-24 14:16:25 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description Michael Stead 2016-03-23 19:12:08 UTC
Description of problem:

When issuing an async bind by product ID, the created job fails with a ClassCastException.


Version-Release number of selected component (if applicable):
2.0 and 0.9.54

How reproducible:
100%

Steps to Reproduce:
1.Make a request to bind a consumer asynchronously by product ID via the API.

curl -k -u admin:admin -X POST "https://localhost:8443/candlepin/consumers/2a9ad1cf-a56a-45cd-adac-c644702ff068/entitlements?product=awesomeos-server-basic&async=true"
{
  "id" : "bind_by_products_39d22a55-2e90-42e2-a756-5d132a8b672e",
  "state" : "CREATED",
  "startTime" : null,
  "finishTime" : null,
  "result" : null,
  "principalName" : "admin",
  "targetType" : "consumer",
  "targetId" : "2a9ad1cf-a56a-45cd-adac-c644702ff068",
  "ownerId" : "admin",
  "resultData" : null,
  "statusPath" : "/jobs/bind_by_products_39d22a55-2e90-42e2-a756-5d132a8b672e",
  "done" : false,
  "group" : "async group",
  "created" : "2016-03-23T19:02:51+0000",
  "updated" : "2016-03-23T19:02:51+0000"
}

2. Using the job_id from the results from step 1, fetch the job status:

curl -k -u admin:admin "https://localhost:8443/candlepin/jobs/bind_by_products_39d22a55-2e90-42e2-a756-5d132a8b672e"
{
  "id" : "bind_by_products_39d22a55-2e90-42e2-a756-5d132a8b672e",
  "state" : "FAILED",
  "startTime" : "2016-03-23T19:02:51+0000",
  "finishTime" : null,
  "result" : "java.util.ArrayList cannot be cast to java.util.HashSet",
  "principalName" : "admin",
  "targetType" : "consumer",
  "targetId" : "2a9ad1cf-a56a-45cd-adac-c644702ff068",
  "ownerId" : "admin",
  "resultData" : null,
  "statusPath" : "/jobs/bind_by_products_39d22a55-2e90-42e2-a756-5d132a8b672e",
  "done" : true,
  "group" : "async group",
  "created" : "2016-03-23T19:02:51+0000",
  "updated" : "2016-03-23T19:02:51+0000"
}


3. Note that the status state is FAILED and the result is "java.util.ArrayList cannot be cast to java.util.HashSet"

4. Tailing /var/log/candlepin.log the following exception is logged:

2016-03-23 16:02:51,507 [thread=QuartzScheduler_Worker-7] [job=bind_by_products_39d22a55-2e90-42e2-a756-5d132a8b672e, org=] ERROR org.candlepin.pinsetter.tasks.EntitleByProductsJob - EntitlerJob encountered a problem.
java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.util.HashSet
	at org.candlepin.pinsetter.tasks.EntitleByProductsJob.toExecute(EntitleByProductsJob.java:63) ~[EntitleByProductsJob.class:na]
	at org.candlepin.pinsetter.tasks.KingpinJob.execute(KingpinJob.java:84) [KingpinJob.class:na]
	at org.quartz.core.JobRunShell.run(JobRunShell.java:202) [quartz-2.2.1.jar:na]
	at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573) [quartz-2.2.1.jar:na]
2016-03-23 16:02:51,507 [thread=QuartzScheduler_Worker-7] [job=bind_by_products_39d22a55-2e90-42e2-a756-5d132a8b672e, org=] INFO  org.candlepin.pinsetter.tasks.KingpinJob - Job completed: time=6
2016-03-23 16:02:51,527 [thread=QuartzScheduler_Worker-7] [job=bind_by_products_39d22a55-2e90-42e2-a756-5d132a8b672e, org=] ERROR org.candlepin.pinsetter.core.PinsetterJobListener - Job [bind_by_products_39d22a55-2e90-42e2-a756-5d132a8b672e] failed.
org.quartz.JobExecutionException: java.util.ArrayList cannot be cast to java.util.HashSet
	at org.candlepin.pinsetter.tasks.EntitleByProductsJob.toExecute(EntitleByProductsJob.java:74) ~[EntitleByProductsJob.class:na]
	at org.candlepin.pinsetter.tasks.KingpinJob.execute(KingpinJob.java:84) ~[KingpinJob.class:na]
	at org.quartz.core.JobRunShell.run(JobRunShell.java:202) ~[quartz-2.2.1.jar:na]
	at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573) [quartz-2.2.1.jar:na]
Caused by: java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.util.HashSet
	at org.candlepin.pinsetter.tasks.EntitleByProductsJob.toExecute(EntitleByProductsJob.java:63) ~[EntitleByProductsJob.class:na]
	... 3 common frames omitted


Expected results:
Job state should be FINISHED with result 'Entitlement created for owner'

Comment 1 Michael Stead 2016-03-23 19:14:28 UTC
This appears to have been broken for quite a while and hasn't been reported. I'm assuming this is because the feature is not being used.

Comment 2 Michael Stead 2016-03-23 19:22:13 UTC
Fix Pending Review:

master: https://github.com/candlepin/candlepin/pull/1155

Comment 3 Rehana 2016-05-19 09:43:47 UTC
retested with ;

[root@F21-candlepin po]#  git show | head -1commit 9a6c89d622d570e6c29e076790b88a95f83b7cdb

[root@F21-candlepin po]# git branch
* master


[root@F21-candlepin po]# curl -k -u admin:admin -X POST "https://localhost:8443/candlepin/consumers/3004e709-669b-47e6-8910-310e0067327c/entitlements?product=awesomeos-server-basic&async=true" | python -mjson.tool
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   447    0   447    0     0   2974      0 --:--:-- --:--:-- --:--:--  2980
{
    "created": "2016-05-19T09:19:30+0000",
    "done": false,
    "finishTime": null,
    "group": "async group",
    "id": "bind_by_products_ed4c014e-fa7d-437f-b264-644e38dc6104",
    "ownerId": "admin",
    "principalName": "admin",
    "result": null,
    "resultData": null,
    "startTime": null,
    "state": "CREATED",
    "statusPath": "/jobs/bind_by_products_ed4c014e-fa7d-437f-b264-644e38dc6104",
    "targetId": "3004e709-669b-47e6-8910-310e0067327c",
    "targetType": "consumer",
    "updated": "2016-05-19T09:19:30+0000"
}
[root@F21-candlepin po]# curl -k -u admin:admin "https://localhost:8443/candlepin/jobs/bind_by_products_e891d0a9-2cbf-4685-aa3f-53addccbaaf6" | python -mjson.tool
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   526    0   526    0     0   8222      0 --:--:-- --:--:-- --:--:--  8349
{
    "created": "2016-05-19T09:17:51+0000",
    "done": true,
    "finishTime": "2016-05-19T09:17:52+0000",
    "group": "async group",
    "id": "bind_by_products_e891d0a9-2cbf-4685-aa3f-53addccbaaf6",
    "ownerId": "admin",
    "principalName": "admin",
    "result": "Entitlements created for owner",
    "resultData": "[cloaked]",
    "startTime": "2016-05-19T09:17:51+0000",
    "state": "FINISHED",
    "statusPath": "/jobs/bind_by_products_e891d0a9-2cbf-4685-aa3f-53addccbaaf6",
    "targetId": "3004e709-669b-47e6-8910-310e0067327c",
    "targetType": "consumer",
    "updated": "2016-05-19T09:17:52+0000"
}

^^ State is now marked as "FINISHED" with the result "Entitlements created for owner", and no error was seen in the candlepin log.

[root@F21-candlepin po]# tail -f /var/log/candlepin/candlepin.log 
2016-05-19 14:49:34,444 [thread=http-bio-8443-exec-1] [req=d263adf1-818d-42cf-8e90-01225d75631d, org=] INFO  org.candlepin.common.filter.LoggingFilter - Request: verb=GET, uri=/candlepin/
2016-05-19 14:49:34,446 [thread=http-bio-8443-exec-1] [req=d263adf1-818d-42cf-8e90-01225d75631d, org=] INFO  org.candlepin.common.filter.LoggingFilter - Response: status=200, content-type="application/json", time=2
2016-05-19 14:49:34,460 [thread=http-bio-8443-exec-10] [req=3dd9dddf-200d-4568-9209-5980c7c22b76, org=] INFO  org.candlepin.common.filter.LoggingFilter - Request: verb=GET, uri=/candlepin/consumers/3004e709-669b-47e6-8910-310e0067327c/content_overrides
2016-05-19 14:49:34,517 [thread=http-bio-8443-exec-10] [req=3dd9dddf-200d-4568-9209-5980c7c22b76, org=] INFO  org.candlepin.common.filter.LoggingFilter - Response: status=200, content-type="application/json", time=57
2016-05-19 14:49:34,543 [thread=http-bio-8443-exec-3] [req=fac2f3e0-6db9-4e7c-ba38-655f94fca4dc, org=] INFO  org.candlepin.common.filter.LoggingFilter - Request: verb=GET, uri=/candlepin/consumers/3004e709-669b-47e6-8910-310e0067327c
2016-05-19 14:49:34,958 [thread=http-bio-8443-exec-3] [req=fac2f3e0-6db9-4e7c-ba38-655f94fca4dc, org=admin] INFO  org.candlepin.common.filter.LoggingFilter - Response: status=200, content-type="application/json", time=415
2016-05-19 14:49:34,975 [thread=http-bio-8443-exec-11] [req=92c03d60-0b48-48b8-b267-03aec31ee328, org=] INFO  org.candlepin.common.filter.LoggingFilter - Request: verb=GET, uri=/candlepin/consumers/3004e709-669b-47e6-8910-310e0067327c/content_overrides
2016-05-19 14:49:35,022 [thread=http-bio-8443-exec-11] [req=92c03d60-0b48-48b8-b267-03aec31ee328, org=] INFO  org.candlepin.common.filter.LoggingFilter - Response: status=200, content-type="application/json", time=47
2016-05-19 14:49:41,523 [thread=http-bio-8443-exec-5] [req=7a846a41-c66d-4392-a0c0-f8ebcde187fe, org=] INFO  org.candlepin.common.filter.LoggingFilter - Request: verb=GET, uri=/candlepin/jobs/bind_by_products_e891d0a9-2cbf-4685-aa3f-53addccbaaf6
2016-05-19 14:49:41,526 [thread=http-bio-8443-exec-5] [req=7a846a41-c66d-4392-a0c0-f8ebcde187fe, org=] INFO  org.candlepin.common.filter.LoggingFilter - Response: status=200, content-type="application/json", time=3

Marking as Verified!!!