Search in sources :

Example 16 with AzureToolkitRuntimeException

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

the class AuthMethodManager method getAzureClient.

@NotNull
@AzureOperation(name = "common|rest_client.create", params = { "sid" }, type = AzureOperation.Type.TASK)
public Azure getAzureClient(String sid) {
    final AzureManager manager = getAzureManager();
    if (manager != null) {
        final Azure azure = manager.getAzure(sid);
        if (azure != null) {
            return azure;
        }
    }
    final String error = "Failed to connect Azure service with current account";
    final String action = "Confirm you have already signed in with subscription: " + sid;
    final String errorCode = "001";
    throw new AzureToolkitRuntimeException(error, null, action, errorCode);
}
Also used : Azure(com.microsoft.azure.management.Azure) AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) IdentityAzureManager(com.microsoft.azuretools.sdkmanage.IdentityAzureManager) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Example 17 with AzureToolkitRuntimeException

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

the class SubscriptionManager method loadSubscriptions.

@AzureOperation(name = "account|subscription.load_cache", type = AzureOperation.Type.TASK)
public static List<SubscriptionDetail> loadSubscriptions() {
    System.out.println("SubscriptionManager.loadSubscriptions()");
    try {
        String json = AzureStoreManager.getInstance().getIdeStore().getProperty(TelemetryConstants.ACCOUNT, "subscription_details");
        if (StringUtils.isBlank(json)) {
            final FileStorage file = new FileStorage(FILE_NAME_SUBSCRIPTIONS_DETAILS, CommonSettings.getSettingsBaseDir());
            final byte[] data = file.read();
            json = new String(data, StandardCharsets.UTF_8);
            file.removeFile();
            AzureStoreManager.getInstance().getIdeStore().setProperty(TelemetryConstants.ACCOUNT, "subscriptions_json", json);
        }
        if (json.isEmpty()) {
            System.out.println("subscription details is empty");
            return Collections.emptyList();
        }
        final SubscriptionDetail[] sda = JsonHelper.deserialize(SubscriptionDetail[].class, json);
        return new ArrayList<>(Arrays.asList(sda));
    } catch (final IOException e) {
        final String error = "Failed to load local cached subscriptions";
        final String action = "Retry later or logout to clear local cached subscriptions";
        throw new AzureToolkitRuntimeException(error, e);
    }
}
Also used : ArrayList(java.util.ArrayList) SubscriptionDetail(com.microsoft.azuretools.authmanage.models.SubscriptionDetail) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) IOException(java.io.IOException) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 18 with AzureToolkitRuntimeException

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

the class IntellijDatasourceService method showDataSourceManagerDialog.

private void showDataSourceManagerDialog(Object dbPsiFacade, Object registry, DatasourceProperties properties) {
    try {
        Class dataSourceManagerDialogClazz = Class.forName("com.intellij.database.view.ui.DataSourceManagerDialog");
        MethodUtils.invokeStaticMethod(dataSourceManagerDialogClazz, "showDialog", dbPsiFacade, registry);
    } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
        throw new AzureToolkitRuntimeException(String.format(ERROR_MESSAGE_PATTERN, properties.getName()), ERROR_ACTION);
    }
}
Also used : AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 19 with AzureToolkitRuntimeException

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

the class IntellijDatasourceService method openDataSourceManagerDialog.

public void openDataSourceManagerDialog(Project project, DatasourceProperties properties) {
    if (PluginManagerCore.getPlugin(PluginId.findId(DATABASE_TOOLS_PLUGIN_ID)) == null) {
        throw new AzureToolkitRuntimeException(NOT_SUPPORT_ERROR_MESSAGE, NOT_SUPPORT_ERROR_ACTION);
    }
    Object registry = getDataSourceRegistry(project, properties);
    Object dbPsiFacade = getDbPsiFacade(project, properties);
    try {
        Object builder = MethodUtils.invokeMethod(registry, "getBuilder");
        MethodUtils.invokeMethod(builder, true, "withName", properties.getName());
        MethodUtils.invokeMethod(builder, true, "withDriverClass", properties.getDriverClassName());
        MethodUtils.invokeMethod(builder, true, "withUrl", properties.getUrl());
        MethodUtils.invokeMethod(builder, true, "withUser", properties.getUsername());
        MethodUtils.invokeMethod(builder, true, "commit");
    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
        throw new AzureToolkitRuntimeException(String.format(ERROR_MESSAGE_PATTERN, properties.getName()), ERROR_ACTION);
    }
    showDataSourceManagerDialog(dbPsiFacade, registry, properties);
}
Also used : AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 20 with AzureToolkitRuntimeException

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

the class FunctionNode method trigger.

@AzureOperation(name = "function|trigger.start.detail", params = { "this.functionApp.name()" }, type = AzureOperation.Type.SERVICE)
private void trigger() {
    final FunctionEntity.BindingEntity trigger = functionEntity.getTrigger();
    final String triggerType = Optional.ofNullable(trigger).map(functionTrigger -> functionTrigger.getProperty("type")).orElse(null);
    if (StringUtils.isEmpty(triggerType)) {
        final String error = String.format("failed to get trigger type of function[%s].", functionApp.name());
        final String action = "confirm trigger type is configured.";
        throw new AzureToolkitRuntimeException(error, action);
    }
    switch(triggerType.toLowerCase()) {
        case "httptrigger":
            triggerHttpTrigger(trigger);
            break;
        case "timertrigger":
            // no input for timer trigger
            functionApp.triggerFunction(this.name, new Object());
            break;
        default:
            final String input = DefaultLoader.getUIHelper().showInputDialog(tree.getParent(), "Please set the input value: ", String.format("Trigger function %s", this.name), null);
            functionApp.triggerFunction(this.name, new TriggerRequest(input));
            break;
    }
}
Also used : AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation) Node(com.microsoft.tooling.msservices.serviceexplorer.Node) RequiredArgsConstructor(lombok.RequiredArgsConstructor) AzureOperationBundle(com.microsoft.azure.toolkit.lib.common.operation.AzureOperationBundle) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) AppInsightsConstants(com.microsoft.azuretools.telemetry.AppInsightsConstants) TRIGGER_FUNCTION(com.microsoft.azuretools.telemetry.TelemetryConstants.TRIGGER_FUNCTION) WrappedTelemetryNodeActionListener(com.microsoft.tooling.msservices.serviceexplorer.WrappedTelemetryNodeActionListener) EnumUtils(org.apache.commons.lang3.EnumUtils) AuthorizationLevel(com.microsoft.azure.functions.annotation.AuthorizationLevel) Map(java.util.Map) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) DefaultLoader(com.microsoft.tooling.msservices.components.DefaultLoader) Nonnull(javax.annotation.Nonnull) NodeActionListener(com.microsoft.tooling.msservices.serviceexplorer.NodeActionListener) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) TelemetryProperties(com.microsoft.azuretools.telemetry.TelemetryProperties) IFunctionApp(com.microsoft.azure.toolkit.lib.appservice.service.IFunctionApp) Optional(java.util.Optional) Utils(com.microsoft.azure.toolkit.lib.appservice.utils.Utils) FUNCTION(com.microsoft.azuretools.telemetry.TelemetryConstants.FUNCTION) OperatingSystem(com.microsoft.azure.toolkit.lib.appservice.model.OperatingSystem) NodeActionEvent(com.microsoft.tooling.msservices.serviceexplorer.NodeActionEvent) FunctionEntity(com.microsoft.azure.toolkit.lib.appservice.entity.FunctionEntity) AzureTaskManager(com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager) FunctionEntity(com.microsoft.azure.toolkit.lib.appservice.entity.FunctionEntity) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

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