Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Database Tools' integration refactoring & Open Redis cache in 'Database' tool window #9421

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies {
implementation(project(":azure-intellij-resource-connector-lib"))
// runtimeOnly project(path: ":azure-intellij-resource-connector-lib", configuration: "instrumentedJar")
implementation(project(":azure-intellij-resource-connector-lib-java"))
implementation(project(":azure-intellij-plugin-dbtools"))
// runtimeOnly project(path: ":azure-intellij-resource-connector-lib-java", configuration: "instrumentedJar")
implementation("com.microsoft.azure:azure-toolkit-cosmos-lib")
implementation("com.microsoft.azure:azure-toolkit-ide-common-lib")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.microsoft.azure.toolkit.intellij.cosmos.creation.CreateCosmosContainerAction;
import com.microsoft.azure.toolkit.intellij.cosmos.creation.CreateCosmosDBAccountAction;
import com.microsoft.azure.toolkit.intellij.cosmos.creation.CreateCosmosDatabaseAction;
import com.microsoft.azure.toolkit.intellij.dbtools.DatabasePlugin;
import com.microsoft.azure.toolkit.lib.common.action.Action;
import com.microsoft.azure.toolkit.lib.common.action.AzureActionManager;
import com.microsoft.azure.toolkit.lib.common.bundle.AzureString;
Expand Down Expand Up @@ -125,22 +126,13 @@ public void registerHandlers(AzureActionManager am) {
am.registerHandler(ResourceCommonActionsContributor.CREATE, (r, e) -> r instanceof CassandraKeyspace && ((CassandraKeyspace) r).getFormalStatus().isRunning(), (Object r, AnActionEvent e) ->
CreateCosmosContainerAction.createCassandraTable(e.getProject(), (CassandraKeyspace) r, CassandraTableDraft.CassandraTableConfig.getDefaultConfig()));

final String DATABASE_TOOLS_PLUGIN_ID = "com.intellij.database";
if (PluginManagerCore.getPlugin(PluginId.findId(DATABASE_TOOLS_PLUGIN_ID)) == null) {
final BiConsumer<CosmosDBAccount, AnActionEvent> openDatabaseHandler = (c, e) -> openDatabaseTool(e.getProject(), c);
if (!DatabasePlugin.isInstalled()) {
final BiConsumer<CosmosDBAccount, AnActionEvent> openDatabaseHandler = (c, e) -> DatabasePlugin.throwTryUltimateIfNotInstalled(c);
final boolean cassandraOn = Registry.is("azure.toolkit.cosmos_cassandra.dbtools.enabled");
am.registerHandler(CosmosActionsContributor.OPEN_DATABASE_TOOL, (r, e) -> r instanceof MongoCosmosDBAccount || (r instanceof CassandraCosmosDBAccount && cassandraOn), openDatabaseHandler);
}
}

private void openDatabaseTool(Project project, CosmosDBAccount account) {
final String DATABASE_TOOLS_PLUGIN_ID = "com.intellij.database";
final String DATABASE_PLUGIN_NOT_INSTALLED = "\"Database tools and SQL\" plugin is not installed.";
final String NOT_SUPPORT_ERROR_ACTION = "\"Database tools and SQL\" plugin is only provided in IntelliJ Ultimate edition.";
final Action<Object> tryUltimate = AzureActionManager.getInstance().getAction(IntellijActionsContributor.TRY_ULTIMATE).bind(account);
throw new AzureToolkitRuntimeException(DATABASE_PLUGIN_NOT_INSTALLED, NOT_SUPPORT_ERROR_ACTION, tryUltimate);
}

private <T extends AzResource> void openResourceConnector(@Nonnull final T resource, @Nonnull final AzureServiceResource.Definition<T> definition, Project project) {
AzureTaskManager.getInstance().runLater(() -> {
final ConnectorDialog dialog = new ConnectorDialog(project);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,12 @@

package com.microsoft.azure.toolkit.intellij.cosmos.dbtools;

import com.azure.resourcemanager.resources.fluentcore.arm.ResourceId;
import com.intellij.database.dataSource.DatabaseConnectionInterceptor;
import com.intellij.database.dataSource.DatabaseConnectionPoint;
import com.microsoft.azure.toolkit.lib.common.operation.AzureOperation;
import com.microsoft.azure.toolkit.lib.common.operation.Operation;
import com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemeter;
import com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemetry;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import com.microsoft.azure.toolkit.intellij.dbtools.TelemetryConnectionInterceptor;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CompletionStage;
import static com.microsoft.azure.toolkit.intellij.cosmos.dbtools.AzureCosmosDbAccountParamEditor.KEY_COSMOS_ACCOUNT_ID;

import static com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemeter.*;

@SuppressWarnings("UnstableApiUsage")
public class AzureCosmosDbAccountConnectionInterceptor implements DatabaseConnectionInterceptor {
@Nullable
public CompletionStage<ProtoConnection> intercept(@NotNull DatabaseConnectionInterceptor.ProtoConnection proto, boolean silent) {
final DatabaseConnectionPoint point = proto.getConnectionPoint();
final String accountId = point.getAdditionalProperty(AzureCosmosDbAccountParamEditor.KEY_COSMOS_ACCOUNT_ID);
if (StringUtils.isNotBlank(accountId) && !StringUtils.equalsIgnoreCase(accountId, AzureCosmosDbAccountParamEditor.NONE)) {
final Map<String, String> properties = new HashMap<>();
final ResourceId id = ResourceId.fromString(accountId);
properties.put("subscriptionId", id.subscriptionId());
properties.put(SERVICE_NAME, "cosmos");
properties.put(OPERATION_NAME, "connect_jdbc_from_dbtools");
properties.put(OP_NAME, "cosmos.connect_jdbc_from_dbtools");
properties.put(OP_TYPE, Operation.Type.USER);
AzureTelemeter.log(AzureTelemetry.Type.OP_END, properties);
}
return null;
public class AzureCosmosDbAccountConnectionInterceptor extends TelemetryConnectionInterceptor {
protected AzureCosmosDbAccountConnectionInterceptor() {
super(KEY_COSMOS_ACCOUNT_ID, "cosmos", "cosmos.connect_jdbc_from_dbtools");
}
}
}
Loading