cloudfoundry-community / spring-cloud-s3-service-connector

Apache License 2.0
5 stars 2 forks source link

Cannot cast object BaseServiceInfo to S3ServiceInfo #7

Open Omnipresent opened 7 years ago

Omnipresent commented 7 years ago

I'm getting the following error on these lines of code

            BaseServiceInfo baseServiceInfo = cloud.getServiceInfo("upload-rw")
            log.info("This is the id: " + baseServiceInfo.getId())
            S3ServiceInfo serviceInfo = (S3ServiceInfo) baseServiceInfo
OUT org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 
     'org.springframework.cloud.service.BaseServiceInfo@4ad8f682' with class      
      'org.springframework.cloud.service.BaseServiceInfo' to class 
       'org.cloudfoundry.community.service.storage.S3ServiceInfo'

The log.info line actually does show the name of the service.

I'm getting this error in CloudFoundry while deploying at a customer site. Surprisingly this error doesn't happen when I deploy the same application locally on my PCFDev.

I see that S3ServiceInfo extends BaseServiceInfo so I don't see a reason for this error.

Are there any steps I can take to better troubleshoot this?

One difference I see in my local CF is when I run cf env myapp I see the following:

{
 "VCAP_SERVICES": {
  "amazon-s3": [
   {
    "credentials": {
     "access_key_id": "redacted",
     "bucket": "redacted",
     "host": "s3.amazonaws.com",
     "secret_access_key": "redacted",
     "uri": "redacted",
     "username": "redacted"
    },
    "label": "amazon-s3",
    "name": "upload-rw",
    "plan": "basic",
    "provider": null,
    "syslog_drain_url": null,

However, at customer site I see the following for the same cf env myapp command:

{
 "VCAP_SERVICES": {
  "aws-s3": [
   {
    "credentials": {
     "access_key_id": "redacted",
     "bucket": "redacted",
     "region": "us-east-1",
     "secret_access_key": "redacted"
    },
    "label": "aws-s3",
    "name": "upload-rw",
    "plan": "standard",
    "provider": null,
    "syslog_drain_url": null,

Notice the difference in label from amazon-s3 to aws-s3 and username property missing.

Would this cause the error that I'm getting? If so, is there a way I can still do to get the information like below?

S3ServiceInfo serviceInfo = (S3ServiceInfo) cloud.getServiceInfo("upload-rw")
def props =  [serviceInfo.getAccessKeyId(), serviceInfo.getSecretAccessKey()]
Tanvishah1 commented 6 years ago

Even I am getting the same issue. Did you get any solution for this? @Omnipresent