use of com.microsoft.tooling.msservices.helpers.azure.rest.RestServiceManagerBaseImpl in project azure-tools-for-java by Microsoft.
the class ClusterOperationImpl method listCluster.
/**
* list hdinsight cluster
*
* @param subscription
* @return cluster raw data info
* @throws IOException
*/
public List<ClusterRawInfo> listCluster(final SubscriptionDetail subscription) throws AzureCmdException {
try {
String response = requestWithToken(subscription.getTenantId(), (accessToken) -> {
Environment environment = AuthMethodManager.getInstance().getAzureManager().getEnvironment();
String managementUrl = Environment.valueOf(environment.getName()).getAzureEnvironment().resourceManagerEndpoint();
return AzureAADHelper.executeRequest(managementUrl, String.format("/subscriptions/%s/providers/Microsoft.HDInsight/clusters?api-version=%s", subscription.getSubscriptionId(), VERSION), RestServiceManager.ContentType.Json, "GET", null, accessToken, new RestServiceManagerBaseImpl());
});
return new AuthenticationErrorHandler<List<ClusterRawInfo>>() {
@Override
public List<ClusterRawInfo> execute(String response) {
Type clustersInfoType = new TypeToken<ClustersCollection>() {
}.getType();
ClustersCollection clustersCollection = new Gson().fromJson(response, clustersInfoType);
return clustersCollection.getValue();
}
}.run(response);
} catch (Throwable th) {
throw new AzureCmdException("Error listing HDInsight clusters", th);
}
}
Aggregations