Search in sources :

Example 1 with AggregatedException

use of com.microsoft.azure.hdinsight.sdk.common.AggregatedException in project azure-tools-for-java by Microsoft.

the class ClusterManager method getClusterDetails.

private List<IClusterDetail> getClusterDetails(List<SubscriptionDetail> subscriptions, final Object project) throws AggregatedException {
    ExecutorService taskExecutor = Executors.newFixedThreadPool(MAX_CONCURRENT);
    final List<IClusterDetail> cachedClusterList = new ArrayList<>();
    final List<Exception> aggregateExceptions = new ArrayList<>();
    for (SubscriptionDetail subscription : subscriptions) {
        taskExecutor.execute(new CommonRunnable<SubscriptionDetail, Exception>(subscription) {

            @Override
            public void runSpecificParameter(SubscriptionDetail parameter) throws IOException, HDIException, AzureCmdException {
                IClusterOperation clusterOperation = new ClusterOperationImpl(project);
                List<ClusterRawInfo> clusterRawInfoList = clusterOperation.listCluster(parameter);
                if (clusterRawInfoList != null) {
                    for (ClusterRawInfo item : clusterRawInfoList) {
                        IClusterDetail tempClusterDetail = new ClusterDetail(parameter, item);
                        synchronized (ClusterManager.class) {
                            cachedClusterList.add(tempClusterDetail);
                        }
                    }
                }
            }

            @Override
            public void exceptionHandle(Exception e) {
                synchronized (aggregateExceptions) {
                    aggregateExceptions.add(e);
                }
            }
        });
    }
    taskExecutor.shutdown();
    try {
        taskExecutor.awaitTermination(TIME_OUT, TimeUnit.SECONDS);
    } catch (InterruptedException exception) {
        aggregateExceptions.add(exception);
    }
    if (aggregateExceptions.size() > 0) {
        throw new AggregatedException(aggregateExceptions);
    }
    return cachedClusterList;
}
Also used : ArrayList(java.util.ArrayList) AggregatedException(com.microsoft.azure.hdinsight.sdk.common.AggregatedException) IOException(java.io.IOException) HDIException(com.microsoft.azure.hdinsight.sdk.common.HDIException) AggregatedException(com.microsoft.azure.hdinsight.sdk.common.AggregatedException) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) HDIException(com.microsoft.azure.hdinsight.sdk.common.HDIException) IOException(java.io.IOException) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) ExecutorService(java.util.concurrent.ExecutorService) SubscriptionDetail(com.microsoft.azuretools.authmanage.models.SubscriptionDetail) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

AggregatedException (com.microsoft.azure.hdinsight.sdk.common.AggregatedException)1 HDIException (com.microsoft.azure.hdinsight.sdk.common.HDIException)1 SubscriptionDetail (com.microsoft.azuretools.authmanage.models.SubscriptionDetail)1 AzureCmdException (com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ExecutorService (java.util.concurrent.ExecutorService)1