Search in sources :

Example 1 with RestServiceManagerBaseImpl

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);
    }
}
Also used : Type(java.lang.reflect.Type) RestServiceManagerBaseImpl(com.microsoft.tooling.msservices.helpers.azure.rest.RestServiceManagerBaseImpl) TypeToken(com.google.common.reflect.TypeToken) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) Environment(com.microsoft.azuretools.authmanage.Environment) Gson(com.google.gson.Gson) List(java.util.List)

Aggregations

TypeToken (com.google.common.reflect.TypeToken)1 Gson (com.google.gson.Gson)1 Environment (com.microsoft.azuretools.authmanage.Environment)1 AzureCmdException (com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)1 RestServiceManagerBaseImpl (com.microsoft.tooling.msservices.helpers.azure.rest.RestServiceManagerBaseImpl)1 Type (java.lang.reflect.Type)1 List (java.util.List)1