Search in sources :

Example 6 with AzureToolkitRuntimeException

use of com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException in project azure-tools-for-java by Microsoft.

the class FunctionDeploymentState method listFunctions.

// todo: Move to toolkit lib as shared task
private List<FunctionEntity> listFunctions(final IFunctionApp functionApp) {
    final int[] count = { 0 };
    final IAzureMessager azureMessager = AzureMessager.getMessager();
    return Mono.fromCallable(() -> {
        final AzureString message = count[0]++ == 0 ? AzureString.fromString(SYNCING_TRIGGERS) : AzureString.format(SYNCING_TRIGGERS_WITH_RETRY, count[0], LIST_TRIGGERS_MAX_RETRY);
        azureMessager.info(message);
        return Optional.ofNullable(functionApp.listFunctions(true)).filter(CollectionUtils::isNotEmpty).orElseThrow(() -> new AzureToolkitRuntimeException(NO_TRIGGERS_FOUNDED));
    }).subscribeOn(Schedulers.boundedElastic()).retryWhen(Retry.fixedDelay(LIST_TRIGGERS_MAX_RETRY - 1, Duration.ofSeconds(LIST_TRIGGERS_RETRY_PERIOD_IN_SECONDS))).block();
}
Also used : IAzureMessager(com.microsoft.azure.toolkit.lib.common.messager.IAzureMessager) CollectionUtils(org.apache.commons.collections4.CollectionUtils) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString)

Example 7 with AzureToolkitRuntimeException

use of com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException in project azure-tools-for-java by Microsoft.

the class FunctionDeploymentState method prepareStagingFolder.

@AzureOperation(name = "function.prepare_staging_folder_detail", params = { "stagingFolder.getName()", "this.deployModel.getFunctionAppConfig().getName()" }, type = AzureOperation.Type.TASK)
private void prepareStagingFolder(File stagingFolder, RunProcessHandler processHandler, @NotNull final Operation operation) {
    AzureTaskManager.getInstance().read(() -> {
        final Path hostJsonPath = FunctionUtils.getDefaultHostJson(project);
        final PsiMethod[] methods = FunctionUtils.findFunctionsByAnnotation(functionDeployConfiguration.getModule());
        final Path folder = stagingFolder.toPath();
        try {
            final Map<String, FunctionConfiguration> configMap = FunctionUtils.prepareStagingFolder(folder, hostJsonPath, functionDeployConfiguration.getModule(), methods);
            operation.trackProperty(TelemetryConstants.TRIGGER_TYPE, StringUtils.join(FunctionUtils.getFunctionBindingList(configMap), ","));
        } catch (final AzureExecutionException | IOException e) {
            final String error = String.format("failed prepare staging folder[%s]", folder);
            throw new AzureToolkitRuntimeException(error, e);
        }
    });
}
Also used : Path(java.nio.file.Path) PsiMethod(com.intellij.psi.PsiMethod) AzureExecutionException(com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException) FunctionConfiguration(com.microsoft.azure.toolkit.lib.legacy.function.configurations.FunctionConfiguration) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) IOException(java.io.IOException) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 8 with AzureToolkitRuntimeException

use of com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException in project azure-tools-for-java by Microsoft.

the class AuthMethodManager method persistAuthMethodDetails.

@AzureOperation(name = "account|auth_setting.persist", type = AzureOperation.Type.TASK)
public void persistAuthMethodDetails() {
    waitInitFinish();
    try {
        System.out.println("saving authMethodDetails...");
        String sd = JsonHelper.serialize(authMethodDetails);
        AzureStoreManager.getInstance().getIdeStore().setProperty(ACCOUNT, AUTH_METHOD_DETAIL, sd);
    } catch (final IOException e) {
        final String error = "Failed to persist auth method settings while updating";
        final String action = "Retry later";
        throw new AzureToolkitRuntimeException(error, e, action);
    }
}
Also used : AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) IOException(java.io.IOException) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 9 with AzureToolkitRuntimeException

use of com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException in project azure-tools-for-java by Microsoft.

the class SubscriptionManager method setSubscriptionDetails.

public void setSubscriptionDetails(List<SubscriptionDetail> subscriptionDetails) {
    System.out.println(Thread.currentThread().getId() + " SubscriptionManager.setSubscriptionDetails()");
    synchronized (this) {
        try {
            saveSubscriptions(subscriptionDetails);
            notifyAllListeners(CollectionUtils.isEmpty(subscriptionDetails));
        } catch (final IOException e) {
            final String error = "Failed to update local subscriptions cache while updating";
            final String action = "Retry later";
            throw new AzureToolkitRuntimeException(error, e, action);
        }
    }
}
Also used : AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) IOException(java.io.IOException)

Example 10 with AzureToolkitRuntimeException

use of com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException in project azure-tools-for-java by Microsoft.

the class DefaultMachineStore method load.

public void load() {
    try {
        if (Files.exists(Paths.get(dataFile))) {
            String json = FileUtils.readFileToString(new File(dataFile), "utf8");
            Type type = new TypeToken<Map<String, String>>() {
            }.getType();
            map = JsonUtils.getGson().fromJson(json, type);
        }
    } catch (Exception ex) {
        throw new AzureToolkitRuntimeException("Cannot load property.", ex);
    }
}
Also used : Type(java.lang.reflect.Type) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException)

Aggregations

AzureToolkitRuntimeException (com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException)29 AzureOperation (com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)13 IOException (java.io.IOException)13 AzureString (com.microsoft.azure.toolkit.lib.common.bundle.AzureString)9 File (java.io.File)5 AzureExecutionException (com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException)4 AzureTask (com.microsoft.azure.toolkit.lib.common.task.AzureTask)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 HashMap (java.util.HashMap)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 Operation (com.microsoft.azuretools.telemetrywrapper.Operation)3 Path (java.nio.file.Path)3 PsiMethod (com.intellij.psi.PsiMethod)2 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)2 MsalClientException (com.microsoft.aad.msal4j.MsalClientException)2 AuthorizationLevel (com.microsoft.azure.functions.annotation.AuthorizationLevel)2 AppServiceFile (com.microsoft.azure.toolkit.lib.appservice.model.AppServiceFile)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 DeserializationFeature (com.fasterxml.jackson.databind.DeserializationFeature)1