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;
}
}
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);
}
}
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);
}
Aggregations