Azure / azure-libraries-for-java

Azure Management Libraries for Java
https://docs.microsoft.com/en-us/java/azure/
MIT License
94 stars 97 forks source link

[BUG] Exception in Azure.cdnProfiles().list() #1365

Closed ikalligeros closed 3 years ago

ikalligeros commented 3 years ago

Describe the bug While trying to get the list of CdnProfiles for a specific azure account, an exception is thrown

Exception or Stack Trace

com.fasterxml.jackson.databind.exc.InvalidTypeIdException: Could not resolve type id 'ModifyResponseHeader' as a subtype of `com.microsoft.azure.management.cdn.DeliveryRuleAction`: known type ids = [CacheExpiration, DeliveryRuleAction] (for POJO property 'actions')
at [Source: (String)"{"value":[{"id":"/subscriptions/<subscriptionId-dedacted>/resourcegroups/<resourceGroup-dedacted>/providers/Microsoft.Cdn/profiles/<profile-dedacted>/endpoints/<endpoint-dedacted>","type":"Microsoft.Cdn/profiles/endpoints","name":"<endpoint-dedacted>","location":"Global","tags":{"environment":"<dedacted>","owner":"<dedacted>","environmenttype":"Production","company":"<dedacted>","businessunit":"<dedacted>"},"properties":{"hostName":"<dedacted>","originHostHeader":"<dedacted>"[truncated 15515 chars]; line: 1, column: 16015] (through reference chain: com.microsoft.azure.management.cdn.implementation.PageImpl["value"]->java.util.ArrayList[0]->com.microsoft.azure.management.cdn.implementation.EndpointInner["properties.deliveryPolicy"]->com.microsoft.azure.management.cdn.EndpointPropertiesUpdateParametersDeliveryPolicy["rules"]->java.util.ArrayList[0]->com.microsoft.azure.management.cdn.DeliveryRule["actions"]->java.util.ArrayList[0])

To Reproduce Unfortunately, this exception occurs on a specific account CDN profile configuration. Not sure how to provide more info without giving away publicly info on this configuration

Code Snippet

// Create an Azure REST API client
def azure  = Azure
        .configure()
        .withLogLevel(LogLevel.BASIC)
        .authenticate(credentials)
        .withDefaultSubscription()

// Find user's CDN profile
def cdnProfile = azure.cdnProfiles().list().find{ it.name() == config.profileName }   <---- Exception in list()

Expected behavior Expected behavior that we are seeing on other azure accounts is to actually get the list of CDN profiles without issues

Screenshots No screenshots available

Setup (please complete the following information):

Additional context It seems that this azure account had some old CDN configuration which returns this ModifyResponseHeader in the JSON payload and SDK 1.38.1 doesn't support. When we downgraded to version 1.4.0 this problem was solved.

Information Checklist Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

weidongxu-microsoft commented 3 years ago

I think I get the cause. New cdn service version leaks its implementation to old cdn version. Old version only have type "CacheExpiration", while new version have 6 more types.

weidongxu-microsoft commented 3 years ago

Next release would take a few weeks.

You can try new SDK at https://aka.ms/azsdk/java/mgmt. Most code should be compatible (except a few lines on authentication the client), and it should already solved the problem. https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/azure-resourcemanager-cdn/src/main/java/com/azure/resourcemanager/cdn/models/DeliveryRuleAction.java#L21-L29

ikalligeros commented 3 years ago

Thank you very much @weidongxu-microsoft for the quick follow up! I also tried to find the new types including the ModifyResponseHeader but i was looking in the wrong place... (azure-mgmt-cdn jars). Thanks for the hint. We will probably move our implementation in the resourcemanager CDN package.

weidongxu-microsoft commented 3 years ago

Sure. There is a migration guide in the readme (https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/MIGRATION_GUIDE.md)

If you having issue during migration, do let us know.

ikalligeros commented 3 years ago

Migration was smooth! I figured out the usage of ClientSecretCredentialBuilder instead of the previous ApplicationTokenCredentials. All good!!

weidongxu-microsoft commented 3 years ago

Let us know your feedback on the new Java SDK. https://microsoft.qualtrics.com/jfe/form/SV_ehN0lIk2FKEBkwd?Q_CHL=ISSUES

ikalligeros commented 3 years ago

Let us know your feedback on the new Java SDK. https://microsoft.qualtrics.com/jfe/form/SV_ehN0lIk2FKEBkwd?Q_CHL=ISSUES

Done :)

nickzhums commented 3 years ago

@ikalligeros Thank you very much for providing the feedback. I saw that your response said initially you didn't know which library to use (old vs new), is there anything we can do to make it better to discover?