Search in sources :

Example 1 with Environment

use of com.microsoft.azuretools.authmanage.Environment in project azure-tools-for-java by Microsoft.

the class HDIEnvironment method getHDIEnvironment.

public static HDIEnvironment getHDIEnvironment() {
    AzureManager azureManager = null;
    Environment env = Environment.GLOBAL;
    azureManager = AuthMethodManager.getInstance().getAzureManager();
    if (azureManager != null) {
        env = azureManager.getEnvironment();
    }
    if (Environment.GLOBAL.equals(env)) {
        return HDIEnvironment.GLOBAL;
    } else if (Environment.CHINA.equals(env)) {
        return HDIEnvironment.CHINA;
    } else if (Environment.GERMAN.equals(env)) {
        return HDIEnvironment.GERMANY;
    } else if (Environment.US_GOVERNMENT.equals(env)) {
        return HDIEnvironment.US_GOVERNMENT;
    } else {
        return HDIEnvironment.GLOBAL;
    }
}
Also used : AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) Environment(com.microsoft.azuretools.authmanage.Environment)

Example 2 with Environment

use of com.microsoft.azuretools.authmanage.Environment 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)

Example 3 with Environment

use of com.microsoft.azuretools.authmanage.Environment in project azure-tools-for-java by Microsoft.

the class HDIEnvironmentScenario method getAzureEnvironment.

@Given("send environment string '(.+)'$")
public void getAzureEnvironment(String environmentMessage) {
    switch(environmentMessage) {
        case "global":
            when(azureManagerMock.getEnvironment()).thenReturn(Environment.GLOBAL);
            break;
        case "china":
            when(azureManagerMock.getEnvironment()).thenReturn(Environment.CHINA);
            break;
        case "germany":
            when(azureManagerMock.getEnvironment()).thenReturn(Environment.GERMAN);
            break;
        case "us_government":
            when(azureManagerMock.getEnvironment()).thenReturn(Environment.US_GOVERNMENT);
    }
    Environment environment = azureManagerMock.getEnvironment();
    hdiEnvironment = new HDIEnvironment(environment);
}
Also used : Environment(com.microsoft.azuretools.authmanage.Environment) Given(cucumber.api.java.en.Given)

Aggregations

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