Search in sources :

Example 1 with HDIException

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

the class SparkSubmitModel method tryToCreateBatchSparkDebugJob.

public SparkBatchRemoteDebugJob tryToCreateBatchSparkDebugJob(@NotNull final IClusterDetail selectedClusterDetail) throws HDIException, IOException {
    SparkBatchSubmission.getInstance().setCredentialsProvider(selectedClusterDetail.getHttpUserName(), selectedClusterDetail.getHttpPassword());
    try {
        SparkBatchRemoteDebugJob debugJob = SparkBatchRemoteDebugJob.factory(SparkSubmitHelper.getLivyConnectionURL(selectedClusterDetail), submissionParameter, SparkBatchSubmission.getInstance());
        debugJob.createBatchSparkJobWithDriverDebugging();
        return debugJob;
    } catch (URISyntaxException ex) {
        throw new HDIException("Bad Livy Connection URL " + SparkSubmitHelper.getLivyConnectionURL(selectedClusterDetail), ex);
    } catch (IOException ex) {
        HDInsightUtil.showErrorMessageOnSubmissionMessageWindow(project, String.format("Error : Failed to submit to spark cluster. error message : %s.", ex.getMessage()));
        throw ex;
    }
}
Also used : URISyntaxException(java.net.URISyntaxException) HDIException(com.microsoft.azure.hdinsight.sdk.common.HDIException) IOException(java.io.IOException)

Example 2 with HDIException

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

the class WebHDFSUtils method uploadFileToADLS.

public static void uploadFileToADLS(@NotNull IHDIStorageAccount storageAccount, @NotNull File localFile, @NotNull String remotePath, boolean overWrite) throws Exception {
    com.microsoft.azuretools.sdkmanage.AzureManager manager = AuthMethodManager.getInstance().getAzureManager();
    String tid = manager.getSubscriptionManager().getSubscriptionTenant(storageAccount.getSubscriptionId());
    String accessToken = manager.getAccessToken(tid);
    // TODO: accountFQDN should work for Mooncake
    String storageName = storageAccount.getName();
    ADLStoreClient client = ADLStoreClient.createClient(String.format("%s.azuredatalakestore.net", storageName), accessToken);
    OutputStream stream = null;
    try {
        stream = client.createFile(remotePath, IfExists.OVERWRITE);
        IOUtils.copy(new FileInputStream(localFile), stream);
        stream.flush();
        stream.close();
    } catch (ADLException e) {
        // we just popup the exception message for customers to guide customers login under interactive model
        if (e.httpResponseCode == 403 || HttpStatusCode.valueOf(e.httpResponseMessage) == HttpStatusCode.FORBIDDEN) {
            throw new HDIException("Forbidden. Attached Azure DataLake Store is not supported in Automated login model. Please logout first and try Interactive login model", 403);
        }
    } finally {
        IOUtils.closeQuietly(stream);
    }
}
Also used : ADLStoreClient(com.microsoft.azure.datalake.store.ADLStoreClient) OutputStream(java.io.OutputStream) AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) HDIException(com.microsoft.azure.hdinsight.sdk.common.HDIException) FileInputStream(java.io.FileInputStream) ADLException(com.microsoft.azure.datalake.store.ADLException)

Example 3 with HDIException

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

the class AddHDInsightAdditionalClusterImpl method getStorageAccount.

public static HDStorageAccount getStorageAccount(String clusterName, String storageName, String storageKey, String userName, String password) throws HDIException, AzureCmdException {
    String responseMessage = getMessageByAmbari(clusterName, userName, password);
    responseMessage = responseMessage.replace(" ", "");
    if (StringHelper.isNullOrWhiteSpace(responseMessage)) {
        throw new HDIException("Failed to get storage account");
    }
    Matcher matcher = PATTERN_DEFAULT_STORAGE.matcher(responseMessage);
    String defaultContainer = "";
    if (matcher.find()) {
        defaultContainer = matcher.group(1);
    }
    if (StringHelper.isNullOrWhiteSpace(defaultContainer)) {
        throw new HDIException("Failed to get default container for storage account");
    }
    HDStorageAccount account = new HDStorageAccount(null, storageName + BLOB_URL_SUFFIX, storageKey, true, defaultContainer);
    //getting container to check the storage key is correct or not
    try {
        StorageClientSDKManager.getManager().getBlobContainers(account.getConnectionString());
    } catch (AzureCmdException e) {
        throw new AzureCmdException("Invalid Storage Key");
    }
    return account;
}
Also used : Matcher(java.util.regex.Matcher) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) HDIException(com.microsoft.azure.hdinsight.sdk.common.HDIException) HDStorageAccount(com.microsoft.azure.hdinsight.sdk.storage.HDStorageAccount)

Example 4 with HDIException

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

the class MultiRestTask method call.

@Override
public List<String> call() throws Exception {
    CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credentialsProvider).build();
    List<String> results = new ArrayList<>();
    for (String path : paths) {
        HttpGet httpGet = new HttpGet(path);
        httpGet.addHeader("Content-Type", "application/json");
        CloseableHttpResponse response = httpclient.execute(httpGet);
        int code = response.getStatusLine().getStatusCode();
        if (code == 200 || code == 201) {
            results.add(EntityUtils.toString(response.getEntity()));
        } else {
            throw new HDIException(response.getStatusLine().getReasonPhrase(), code);
        }
    }
    return results;
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpGet(org.apache.http.client.methods.HttpGet) ArrayList(java.util.ArrayList) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) HDIException(com.microsoft.azure.hdinsight.sdk.common.HDIException)

Example 5 with HDIException

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

the class RestTask method call.

@Override
public String call() throws Exception {
    CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credentialsProvider).build();
    HttpGet httpGet = new HttpGet(path);
    httpGet.addHeader("Content-Type", "application/json");
    CloseableHttpResponse response = httpclient.execute(httpGet);
    HttpResponseWithoutHeader header = getResultFromHttpResponse(response);
    if (header.getStatusCode() == 200 || header.getStatusCode() == 201) {
        return header.getMessage();
    } else {
        throw new HDIException(header.getReason(), header.getStatusCode());
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpResponseWithoutHeader(com.microsoft.azure.hdinsight.common.HttpResponseWithoutHeader) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) HDIException(com.microsoft.azure.hdinsight.sdk.common.HDIException)

Aggregations

HDIException (com.microsoft.azure.hdinsight.sdk.common.HDIException)10 IOException (java.io.IOException)4 AzureCmdException (com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)3 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)3 HttpGet (org.apache.http.client.methods.HttpGet)3 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)3 URISyntaxException (java.net.URISyntaxException)2 ArrayList (java.util.ArrayList)2 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)2 DomElement (com.gargoylesoftware.htmlunit.html.DomElement)1 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)1 ADLException (com.microsoft.azure.datalake.store.ADLException)1 ADLStoreClient (com.microsoft.azure.datalake.store.ADLStoreClient)1 HttpResponseWithoutHeader (com.microsoft.azure.hdinsight.common.HttpResponseWithoutHeader)1 IClusterDetail (com.microsoft.azure.hdinsight.sdk.cluster.IClusterDetail)1 AggregatedException (com.microsoft.azure.hdinsight.sdk.common.AggregatedException)1 AuthenticationException (com.microsoft.azure.hdinsight.sdk.common.AuthenticationException)1 HDStorageAccount (com.microsoft.azure.hdinsight.sdk.storage.HDStorageAccount)1 SubscriptionDetail (com.microsoft.azuretools.authmanage.models.SubscriptionDetail)1 AzureManager (com.microsoft.azuretools.sdkmanage.AzureManager)1