From 5bc4359d00899e61a79ef20ba75ec00bdcf7ff18 Mon Sep 17 00:00:00 2001 From: Michael Golubev Date: Mon, 20 Apr 2020 19:43:38 +0200 Subject: [PATCH] Remote servers cleanup: remove common util code previously used by Heroku / OpenShift - remove "remoteServer.util.CloudDeploymentRuntimeProvider" extension point and its boiler plates - obsolete, the old implementations eliminated (docker / openshift / heroku) GitOrigin-RevId: 1d0ed8e0629c28cd72fc7f1cf65e9585a4aadba3 --- .../CloudModuleBuilderSourceContribution.java | 192 ------------------ .../CloudSourceApplicationConfigurable.java | 158 -------------- .../CloudSourceApplicationConfiguration.java | 36 ---- .../resources/messages/CloudBundle.properties | 3 - .../impl/src/META-INF/RemoteServers.xml | 2 - .../util/CloudDeploymentConfiguratorBase.java | 55 ----- .../util/CloudDeploymentRuntime.java | 72 ------- .../util/CloudDeploymentRuntimeProvider.java | 44 ---- .../util/CloudGitApplicationRuntime.java | 109 ---------- ...CloudMultiSourceServerRuntimeInstance.java | 177 ---------------- 10 files changed, 848 deletions(-) delete mode 100644 java/remote-servers/impl/src/com/intellij/remoteServer/impl/module/CloudModuleBuilderSourceContribution.java delete mode 100644 java/remote-servers/impl/src/com/intellij/remoteServer/impl/module/CloudSourceApplicationConfigurable.java delete mode 100644 java/remote-servers/impl/src/com/intellij/remoteServer/impl/module/CloudSourceApplicationConfiguration.java delete mode 100644 platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudDeploymentConfiguratorBase.java delete mode 100644 platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudDeploymentRuntime.java delete mode 100644 platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudDeploymentRuntimeProvider.java delete mode 100644 platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudGitApplicationRuntime.java delete mode 100644 platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudMultiSourceServerRuntimeInstance.java diff --git a/java/remote-servers/impl/src/com/intellij/remoteServer/impl/module/CloudModuleBuilderSourceContribution.java b/java/remote-servers/impl/src/com/intellij/remoteServer/impl/module/CloudModuleBuilderSourceContribution.java deleted file mode 100644 index bc616a3bbe89..000000000000 --- a/java/remote-servers/impl/src/com/intellij/remoteServer/impl/module/CloudModuleBuilderSourceContribution.java +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright 2000-2014 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.remoteServer.impl.module; - -import com.intellij.ide.util.newProjectWizard.StepSequence; -import com.intellij.ide.util.newProjectWizard.modes.CreateFromSourcesMode; -import com.intellij.ide.util.projectWizard.AbstractStepWithProgress; -import com.intellij.ide.util.projectWizard.ModuleWizardStep; -import com.intellij.ide.util.projectWizard.ProjectBuilder; -import com.intellij.ide.util.projectWizard.WizardContext; -import com.intellij.openapi.Disposable; -import com.intellij.openapi.module.Module; -import com.intellij.openapi.progress.ProgressIndicator; -import com.intellij.openapi.progress.ProgressManager; -import com.intellij.openapi.progress.Task; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.roots.ui.configuration.DefaultModulesProvider; -import com.intellij.openapi.roots.ui.configuration.ModulesProvider; -import com.intellij.openapi.ui.MessageType; -import com.intellij.openapi.util.Disposer; -import com.intellij.remoteServer.CloudBundle; -import com.intellij.remoteServer.ServerType; -import com.intellij.remoteServer.configuration.RemoteServer; -import com.intellij.remoteServer.impl.configuration.deployment.DeployToServerRunConfiguration; -import com.intellij.remoteServer.util.*; -import com.intellij.remoteServer.util.ssh.SshKeyChecker; -import com.intellij.util.containers.ContainerUtil; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - - -public abstract class CloudModuleBuilderSourceContribution< - SC extends CloudConfigurationBase, - DC extends CloudDeploymentNameConfiguration, - AC extends CloudSourceApplicationConfiguration, - SR extends CloudMultiSourceServerRuntimeInstance> - extends CloudModuleBuilderContribution { - - private CloudNotifier myNotifier; - - public CloudModuleBuilderSourceContribution(CloudModuleBuilder moduleBuilder, ServerType cloudType) { - super(moduleBuilder, cloudType); - } - - @Override - public void configureModule(final Module module) { - final CloudModuleBuilder moduleBuilder = getModuleBuilder(); - RemoteServer account = (RemoteServer)moduleBuilder.getAccount(); - final AC applicationConfiguration = (AC)moduleBuilder.getApplicationConfiguration(); - - DC deploymentConfiguration = createDeploymentConfiguration(); - - if (applicationConfiguration.isExisting()) { - deploymentConfiguration.setDefaultDeploymentName(false); - deploymentConfiguration.setDeploymentName(applicationConfiguration.getExistingAppName()); - } - - final DeployToServerRunConfiguration runConfiguration - = CloudRunConfigurationUtil.createRunConfiguration(account, module, deploymentConfiguration); - - final ServerType cloudType = account.getType(); - final Project project = module.getProject(); - new CloudConnectionTask(project, - CloudBundle.message("cloud.support", cloudType.getPresentableName()), - account) { - - boolean myFirstAttempt = true; - - @Override - protected Object run(SR serverRuntime) throws ServerRuntimeException { - doConfigureModule(applicationConfiguration, runConfiguration, myFirstAttempt, serverRuntime); - return null; - } - - @Override - protected void runtimeErrorOccurred(@NotNull String errorMessage) { - myFirstAttempt = false; - new SshKeyChecker().checkServerError(errorMessage, getNotifier(), project, this); - } - - @Override - protected void postPerform(Object result) { - detectModuleStructure(module, moduleBuilder.getContentEntryPath()); - } - - @Override - protected boolean shouldStartInBackground() { - return false; - } - }.performAsync(); - } - - private CloudNotifier getNotifier() { - if (myNotifier == null) { - myNotifier = new CloudNotifier(getCloudType().getPresentableName()); - } - return myNotifier; - } - - private void detectModuleStructure(Module module, final String contentPath) { - final Project project = module.getProject(); - - final CreateFromSourcesMode mode = new CreateFromSourcesMode() { - - @Override - public boolean isAvailable(WizardContext context) { - return true; - } - - @Override - public void addSteps(WizardContext context, ModulesProvider modulesProvider, StepSequence sequence, String specific) { - super.addSteps(context, modulesProvider, sequence, specific); - myProjectBuilder.setFileToImport(contentPath); - } - }; - - final WizardContext context = new WizardContext(project, null); - - final StepSequence stepSequence = mode.getSteps(context, DefaultModulesProvider.createForProject(context.getProject())); - if (stepSequence == null) { - return; - } - - Disposer.register(project, new Disposable() { - - @Override - public void dispose() { - for (ModuleWizardStep step : stepSequence.getAllSteps()) { - step.disposeUIResources(); - } - } - }); - - ProgressManager.getInstance() - .run(new Task.Backgroundable(project, CloudBundle.message("detect.module.structure", getCloudType().getPresentableName()), false) { - - @Override - public void run(@NotNull ProgressIndicator indicator) { - for (ModuleWizardStep step = ContainerUtil.getFirstItem(stepSequence.getSelectedSteps()); - step != null; - step = stepSequence.getNextStep(step)) { - if (step instanceof AbstractStepWithProgress) { - ((AbstractStepWithProgress)step).performStep(); - } - else { - step.updateDataModel(); - } - } - CloudAccountSelectionEditor.unsetAccountOnContext(context, getCloudType()); - } - - @Override - public boolean shouldStartInBackground() { - return false; - } - - @Override - public void onSuccess() { - ProjectBuilder moduleBuilder = mode.getModuleBuilder(); - if (moduleBuilder == null) { - return; - } - moduleBuilder.commit(project); - getNotifier().showMessage(CloudBundle.message("cloud.support.added", getCloudType().getPresentableName()), MessageType.INFO); - } - }); - } - - @Override - protected abstract CloudSourceApplicationConfigurable createApplicationConfigurable(@Nullable Project project, - Disposable parentDisposable); - - protected abstract DC createDeploymentConfiguration(); - - protected abstract void doConfigureModule(AC applicationConfiguration, - DeployToServerRunConfiguration runConfiguration, - boolean firstAttempt, - SR serverRuntime) throws ServerRuntimeException; -} diff --git a/java/remote-servers/impl/src/com/intellij/remoteServer/impl/module/CloudSourceApplicationConfigurable.java b/java/remote-servers/impl/src/com/intellij/remoteServer/impl/module/CloudSourceApplicationConfigurable.java deleted file mode 100644 index 554f2ae5eb8e..000000000000 --- a/java/remote-servers/impl/src/com/intellij/remoteServer/impl/module/CloudSourceApplicationConfigurable.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright 2000-2014 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.remoteServer.impl.module; - -import com.intellij.openapi.Disposable; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Disposer; -import com.intellij.remoteServer.configuration.RemoteServer; -import com.intellij.remoteServer.runtime.Deployment; -import com.intellij.remoteServer.runtime.ServerConnection; -import com.intellij.remoteServer.runtime.ServerConnector; -import com.intellij.remoteServer.runtime.deployment.ServerRuntimeInstance; -import com.intellij.remoteServer.util.*; -import com.intellij.util.concurrency.Semaphore; -import com.intellij.util.ui.UIUtil; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; -import java.util.Collection; -import java.util.concurrent.atomic.AtomicReference; - - -public abstract class CloudSourceApplicationConfigurable< - SC extends CloudConfigurationBase, - DC extends CloudDeploymentNameConfiguration, - SR extends CloudMultiSourceServerRuntimeInstance, - AC extends CloudApplicationConfiguration> extends CloudApplicationConfigurable { - - private final Project myProject; - private final Disposable myParentDisposable; - - private DelayedRunner myRunner; - - private RemoteServer myAccount; - - public CloudSourceApplicationConfigurable(@Nullable Project project, Disposable parentDisposable) { - myProject = project; - myParentDisposable = parentDisposable; - } - - @Override - public void setAccount(RemoteServer account) { - myAccount = account; - clearCloudData(); - } - - protected RemoteServer getAccount() { - return (RemoteServer)myAccount; - } - - @Override - public JComponent getComponent() { - JComponent result = getMainPanel(); - if (myRunner == null) { - myRunner = new DelayedRunner(result) { - - private RemoteServer myPreviousAccount; - - @Override - protected boolean wasChanged() { - boolean result = myPreviousAccount != myAccount; - if (result) { - myPreviousAccount = myAccount; - } - return result; - } - - @Override - protected void run() { - loadCloudData(); - } - }; - Disposer.register(myParentDisposable, myRunner); - } - return result; - } - - protected void clearCloudData() { - getExistingComboBox().removeAllItems(); - } - - protected void loadCloudData() { - new ConnectionTask>("Loading existing applications list") { - - @Override - protected void run(final ServerConnection connection, - final Semaphore semaphore, - final AtomicReference> result) { - connection.connectIfNeeded(new ServerConnector.ConnectionCallback() { - - @Override - public void connected(@NotNull ServerRuntimeInstance serverRuntimeInstance) { - connection.computeDeployments(() -> { - result.set(connection.getDeployments()); - semaphore.up(); - UIUtil.invokeLaterIfNeeded(() -> { - if (!Disposer.isDisposed(myParentDisposable)) { - setupExistingApplications(result.get()); - } - }); - }); - } - - @Override - public void errorOccurred(@NotNull String errorMessage) { - runtimeErrorOccurred(errorMessage); - semaphore.up(); - } - }); - } - - @Override - protected Collection run(SR serverRuntimeInstance) throws ServerRuntimeException { - return null; - } - }.performAsync(); - } - - private void setupExistingApplications(Collection deployments) { - JComboBox existingComboBox = getExistingComboBox(); - existingComboBox.removeAllItems(); - for (Deployment deployment : deployments) { - existingComboBox.addItem(deployment.getPresentableName()); - } - } - - protected Project getProject() { - return myProject; - } - - protected abstract JComboBox getExistingComboBox(); - - protected abstract JComponent getMainPanel(); - - @Override - public abstract AC createConfiguration(); - - protected abstract class ConnectionTask extends CloudConnectionTask { - - public ConnectionTask(String title) { - super(myProject, title, CloudSourceApplicationConfigurable.this.getAccount()); - } - } -} diff --git a/java/remote-servers/impl/src/com/intellij/remoteServer/impl/module/CloudSourceApplicationConfiguration.java b/java/remote-servers/impl/src/com/intellij/remoteServer/impl/module/CloudSourceApplicationConfiguration.java deleted file mode 100644 index db322dba2055..000000000000 --- a/java/remote-servers/impl/src/com/intellij/remoteServer/impl/module/CloudSourceApplicationConfiguration.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2000-2014 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.remoteServer.impl.module; - - -public abstract class CloudSourceApplicationConfiguration extends CloudApplicationConfiguration { - - private final boolean myExisting; - private final String myExistingAppName; - - protected CloudSourceApplicationConfiguration(boolean existing, String existingAppName) { - myExisting = existing; - myExistingAppName = existingAppName; - } - - public boolean isExisting() { - return myExisting; - } - - public String getExistingAppName() { - return myExistingAppName; - } -} diff --git a/platform/remote-servers/api/resources/messages/CloudBundle.properties b/platform/remote-servers/api/resources/messages/CloudBundle.properties index eb0c21b814a6..6d2dfab32273 100644 --- a/platform/remote-servers/api/resources/messages/CloudBundle.properties +++ b/platform/remote-servers/api/resources/messages/CloudBundle.properties @@ -1,6 +1,3 @@ -cloud.undeploy.confirm.title=Confirm delete application -cloud.undeploy.confirm.message=Are you sure to delete the application \"{0}\"?\nPlease enter your account password to confirm -cloud.undeploy.confirm.password.incorrect=Password incorrect\! failed.add.remote=Failed to add {0} repository as remote failed.reset.remote=Failed to set {0} repository as remote cloning.existing.application=Cloning existing {0} application diff --git a/platform/remote-servers/impl/src/META-INF/RemoteServers.xml b/platform/remote-servers/impl/src/META-INF/RemoteServers.xml index 8486c1fa9679..26f86d8925fd 100644 --- a/platform/remote-servers/impl/src/META-INF/RemoteServers.xml +++ b/platform/remote-servers/impl/src/META-INF/RemoteServers.xml @@ -5,8 +5,6 @@ - diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudDeploymentConfiguratorBase.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudDeploymentConfiguratorBase.java deleted file mode 100644 index 0f951b7bd319..000000000000 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudDeploymentConfiguratorBase.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.intellij.remoteServer.util; - -import com.intellij.openapi.project.Project; -import com.intellij.remoteServer.ServerType; -import com.intellij.remoteServer.configuration.ServerConfiguration; -import com.intellij.remoteServer.configuration.deployment.DeploymentConfiguration; -import com.intellij.remoteServer.configuration.deployment.DeploymentConfigurator; -import com.intellij.remoteServer.configuration.deployment.DeploymentSource; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -/** - * @author michael.golubev - */ -public abstract class CloudDeploymentConfiguratorBase - extends DeploymentConfigurator { - - private final Project myProject; - private final ServerType myServerType; - - public CloudDeploymentConfiguratorBase(Project project, ServerType serverType) { - myProject = project; - myServerType = serverType; - } - - public static List getDeploymentRuntimeProviders(ServerType serverType) { - List result = new ArrayList<>(); - for (CloudDeploymentRuntimeProvider provider : CloudDeploymentRuntimeProvider.EP_NAME.getExtensions()) { - ServerType providerServerType = provider.getServerType(); - if (providerServerType == null || providerServerType == serverType) { - result.add(provider); - } - } - return result; - } - - @NotNull - @Override - public List getAvailableDeploymentSources() { - if (myProject.isDefault()) return Collections.emptyList(); - List result = new ArrayList<>(); - for (CloudDeploymentRuntimeProvider provider : getDeploymentRuntimeProviders(myServerType)) { - result.addAll(provider.getDeploymentSources(myProject)); - } - return result; - } - - @NotNull - public Project getProject() { - return myProject; - } -} diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudDeploymentRuntime.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudDeploymentRuntime.java deleted file mode 100644 index 1ddf9b3cb7d6..000000000000 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudDeploymentRuntime.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2000-2013 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.remoteServer.util; - -import com.intellij.openapi.project.Project; -import com.intellij.remoteServer.agent.util.CloudRemoteApplication; -import com.intellij.remoteServer.configuration.deployment.DeploymentSource; -import com.intellij.remoteServer.runtime.deployment.DeploymentLogManager; -import com.intellij.remoteServer.runtime.deployment.DeploymentTask; -import com.intellij.remoteServer.runtime.deployment.ServerRuntimeInstance; -import com.intellij.remoteServer.runtime.log.LoggingHandler; -import org.jetbrains.annotations.Nullable; - -/** - * @author michael.golubev - */ -public abstract class CloudDeploymentRuntime extends CloudGitApplicationRuntime { - - private final DeploymentTask myTask; - - public CloudDeploymentRuntime(CloudMultiSourceServerRuntimeInstance serverRuntime, - DeploymentSource source, - DeploymentTask task, - @Nullable DeploymentLogManager logManager) throws ServerRuntimeException { - super(serverRuntime, - task.getConfiguration().getDeploymentSourceName(source), - logManager); - myTask = task; - } - - protected DeploymentTask getTask() { - return myTask; - } - - public void deploy(ServerRuntimeInstance.DeploymentOperationCallback callback) { - try { - CloudRemoteApplication application = deploy(); - - DeploymentLogManager logManager = getLogManager(); - if (logManager != null) { - LoggingHandler loggingHandler = logManager.getMainLoggingHandler(); - loggingHandler.print("Application is available at "); - loggingHandler.printHyperlink(application.getWebUrl()); - loggingHandler.print("\n"); - } - - callback.succeeded(this); - } - catch (ServerRuntimeException e) { - callback.errorOccurred(e.getMessage()); - } - } - - public Project getProject() { - return myTask.getProject(); - } - - public abstract CloudRemoteApplication deploy() throws ServerRuntimeException; -} diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudDeploymentRuntimeProvider.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudDeploymentRuntimeProvider.java deleted file mode 100644 index e8aafc739c14..000000000000 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudDeploymentRuntimeProvider.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2000-2013 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.remoteServer.util; - -import com.intellij.openapi.extensions.ExtensionPointName; -import com.intellij.openapi.project.Project; -import com.intellij.remoteServer.ServerType; -import com.intellij.remoteServer.configuration.deployment.DeploymentSource; -import com.intellij.remoteServer.runtime.deployment.DeploymentLogManager; -import com.intellij.remoteServer.runtime.deployment.DeploymentTask; - -import java.util.Collection; - -/** - * @author michael.golubev - */ -public interface CloudDeploymentRuntimeProvider { - - ExtensionPointName EP_NAME - = ExtensionPointName.create("com.intellij.remoteServer.util.CloudDeploymentRuntimeProvider"); - - ServerType getServerType(); - - Collection getDeploymentSources(Project project); - - CloudDeploymentRuntime createDeploymentRuntime(DeploymentSource source, - CloudMultiSourceServerRuntimeInstance serverRuntime, - DeploymentTask deploymentTask, - DeploymentLogManager logManager) - throws ServerRuntimeException; -} diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudGitApplicationRuntime.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudGitApplicationRuntime.java deleted file mode 100644 index eaa1dbaeb7d5..000000000000 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudGitApplicationRuntime.java +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -package com.intellij.remoteServer.util; - -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.ui.Messages; -import com.intellij.openapi.util.Ref; -import com.intellij.remoteServer.CloudBundle; -import com.intellij.remoteServer.ServerType; -import com.intellij.remoteServer.agent.util.CloudAgentLoggingHandler; -import com.intellij.remoteServer.agent.util.CloudGitAgentDeployment; -import com.intellij.remoteServer.runtime.ServerTaskExecutor; -import com.intellij.remoteServer.runtime.deployment.DeploymentLogManager; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public class CloudGitApplicationRuntime extends CloudApplicationRuntime { - - private final CloudMultiSourceServerRuntimeInstance myServerRuntime; - private final DeploymentLogManager myLogManager; - private final CloudAgentLoggingHandler myLoggingHandler; - - private final CloudGitAgentDeployment myDeployment; - - public CloudGitApplicationRuntime(CloudMultiSourceServerRuntimeInstance serverRuntime, - String applicationName, - @Nullable DeploymentLogManager logManager) { - super(applicationName); - myServerRuntime = serverRuntime; - myLogManager = logManager; - myLoggingHandler = logManager == null ? new CloudSilentLoggingHandlerImpl(null) : new CloudLoggingHandlerImpl(logManager); - myDeployment = serverRuntime.getAgent().createDeployment(applicationName, myLoggingHandler); - } - - public CloudMultiSourceServerRuntimeInstance getServerRuntime() { - return myServerRuntime; - } - - public DeploymentLogManager getLogManager() { - return myLogManager; - } - - protected CloudAgentLoggingHandler getLoggingHandler() { - return myLoggingHandler; - } - - @Override - public AgentTaskExecutor getAgentTaskExecutor() { - return getServerRuntime().getAgentTaskExecutor(); - } - - @Override - public ServerTaskExecutor getTaskExecutor() { - return getServerRuntime().getTaskExecutor(); - } - - @Override - protected ServerType getCloudType() { - return getServerRuntime().getCloudType(); - } - - public CloudGitAgentDeployment getDeployment() { - return myDeployment; - } - - @Override - public void undeploy(final @NotNull UndeploymentTaskCallback callback) { - getTaskExecutor().submit(() -> { - try { - if (!confirmUndeploy()) { - throw new ServerRuntimeException("Undeploy cancelled"); - } - - undeploy(); - - callback.succeeded(); - } - catch (ServerRuntimeException e) { - callback.errorOccurred(e.getMessage()); - } - }, callback); - } - - - public void undeploy() throws ServerRuntimeException { - getAgentTaskExecutor().execute(() -> { - getDeployment().deleteApplication(); - return null; - }); - } - - private boolean confirmUndeploy() { - final Ref confirmed = new Ref<>(false); - ApplicationManager.getApplication().invokeAndWait(() -> { - String title = CloudBundle.message("cloud.undeploy.confirm.title"); - while (true) { - String password = Messages.showPasswordDialog(CloudBundle.message("cloud.undeploy.confirm.message", getApplicationName()), title); - if (password == null) { - return; - } - if (password.equals(getServerRuntime().getConfiguration().getPasswordSafe())) { - confirmed.set(true); - return; - } - Messages.showErrorDialog(CloudBundle.message("cloud.undeploy.confirm.password.incorrect"), title); - } - }); - return confirmed.get(); - } -} diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudMultiSourceServerRuntimeInstance.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudMultiSourceServerRuntimeInstance.java deleted file mode 100644 index cfc56c09f206..000000000000 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudMultiSourceServerRuntimeInstance.java +++ /dev/null @@ -1,177 +0,0 @@ -package com.intellij.remoteServer.util; - -import com.intellij.execution.runners.ExecutionEnvironment; -import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.project.Project; -import com.intellij.remoteServer.ServerType; -import com.intellij.remoteServer.agent.util.CloudAgentConfigBase; -import com.intellij.remoteServer.agent.util.CloudAgentLogger; -import com.intellij.remoteServer.agent.util.CloudGitAgent; -import com.intellij.remoteServer.agent.util.CloudRemoteApplication; -import com.intellij.remoteServer.configuration.deployment.DeploymentSource; -import com.intellij.remoteServer.impl.configuration.deployment.DeployToServerRunConfiguration; -import com.intellij.remoteServer.runtime.ServerConnector; -import com.intellij.remoteServer.runtime.ServerTaskExecutor; -import com.intellij.remoteServer.runtime.deployment.DeploymentLogManager; -import com.intellij.remoteServer.runtime.deployment.DeploymentTask; -import com.intellij.remoteServer.runtime.deployment.ServerRuntimeInstance; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.io.File; -import java.util.List; - -/** - * @author michael.golubev - */ -public abstract class CloudMultiSourceServerRuntimeInstance< - DC extends CloudDeploymentNameConfiguration, - AC extends CloudAgentConfigBase, - A extends CloudGitAgent, - SC extends AC> - extends CloudServerRuntimeInstance { - - private static final Logger LOG = Logger.getInstance(CloudMultiSourceServerRuntimeInstance.class); - - private final ServerType myServerType; - - public CloudMultiSourceServerRuntimeInstance(ServerType serverType, - SC configuration, - ServerTaskExecutor tasksExecutor, - List libraries, - List> commonJarClasses, - String specificsModuleName, - String specificJarPath, - Class agentInterface, - String agentClassName) throws Exception { - super(configuration, - tasksExecutor, - libraries, - commonJarClasses, - specificsModuleName, - specificJarPath, - agentInterface, - agentClassName); - - myServerType = serverType; - } - - @Override - public A getAgent() { - return super.getAgent(); - } - - @NotNull - @Override - public String getDeploymentName(@NotNull DeploymentSource source, @NotNull DC configuration) { - return CloudDeploymentNameProvider.DEFAULT_NAME_PROVIDER.getDeploymentName(source); - } - - public void connect(final ServerConnector.ConnectionCallback callback) { - getAgentTaskExecutor().execute(() -> { - doConnect(getConfiguration(), - new CloudAgentLogger() { - - @Override - public void debugEx(Exception e) { - LOG.debug(e); - } - - @Override - public void debug(String message) { - LOG.debug(message); - } - }); - return null; - }, new CallbackWrapper() { - - @Override - public void onSuccess(Object result) { - callback.connected(CloudMultiSourceServerRuntimeInstance.this); - } - - @Override - public void onError(String message) { - callback.errorOccurred(message); - } - } - ); - } - - @Override - public void deploy(@NotNull final DeploymentTask task, - @NotNull final DeploymentLogManager logManager, - @NotNull final ServerRuntimeInstance.DeploymentOperationCallback callback) { - getTaskExecutor().submit(() -> createDeploymentRuntime(task, logManager).deploy(callback), callback); - } - - @Override - public void disconnect() { - getTaskExecutor().submit(() -> getAgent().disconnect()); - } - - public CloudDeploymentRuntime createDeploymentRuntime(final DeployToServerRunConfiguration runConfiguration) - throws ServerRuntimeException { - return createDeploymentRuntime(runConfiguration.getDeploymentSource(), - runConfiguration.getDeploymentConfiguration(), - runConfiguration.getProject()); - } - - public CloudDeploymentRuntime createDeploymentRuntime(final DeploymentSource source, final DC configuration, final Project project) - throws ServerRuntimeException { - return createDeploymentRuntime(new DeploymentTask() { - - @NotNull - @Override - public DeploymentSource getSource() { - return source; - } - - @NotNull - @Override - public DC getConfiguration() { - return configuration; - } - - @NotNull - @Override - public Project getProject() { - return project; - } - - @Override - public boolean isDebugMode() { - return false; - } - - @NotNull - @Override - public ExecutionEnvironment getExecutionEnvironment() { - throw new UnsupportedOperationException(); - } - }, null); - } - - private CloudDeploymentRuntime createDeploymentRuntime(DeploymentTask deploymentTask, - @Nullable DeploymentLogManager logManager) throws ServerRuntimeException { - DeploymentSource source = deploymentTask.getSource(); - for (CloudDeploymentRuntimeProvider provider : CloudDeploymentConfiguratorBase.getDeploymentRuntimeProviders(myServerType)) { - CloudDeploymentRuntime result = provider.createDeploymentRuntime(source, this, deploymentTask, logManager); - if (result != null) { - return result; - } - } - throw new ServerRuntimeException("Unknown deployment source"); - } - - @Override - protected CloudApplicationRuntime createApplicationRuntime(CloudRemoteApplication application) { - return new CloudGitApplicationRuntime(this, application.getName(), null); - } - - protected abstract void doConnect(SC configuration, CloudAgentLogger logger); - - public ServerType getCloudType() { - return myServerType; - } -}