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