mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
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
This commit is contained in:
committed by
intellij-monorepo-bot
parent
2f40767949
commit
5bc4359d00
-192
@@ -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<DC, ?, ?, ?>>
|
||||
extends CloudModuleBuilderContribution {
|
||||
|
||||
private CloudNotifier myNotifier;
|
||||
|
||||
public CloudModuleBuilderSourceContribution(CloudModuleBuilder moduleBuilder, ServerType<SC> cloudType) {
|
||||
super(moduleBuilder, cloudType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureModule(final Module module) {
|
||||
final CloudModuleBuilder moduleBuilder = getModuleBuilder();
|
||||
RemoteServer<SC> account = (RemoteServer<SC>)moduleBuilder.getAccount();
|
||||
final AC applicationConfiguration = (AC)moduleBuilder.getApplicationConfiguration();
|
||||
|
||||
DC deploymentConfiguration = createDeploymentConfiguration();
|
||||
|
||||
if (applicationConfiguration.isExisting()) {
|
||||
deploymentConfiguration.setDefaultDeploymentName(false);
|
||||
deploymentConfiguration.setDeploymentName(applicationConfiguration.getExistingAppName());
|
||||
}
|
||||
|
||||
final DeployToServerRunConfiguration<SC, DC> runConfiguration
|
||||
= CloudRunConfigurationUtil.createRunConfiguration(account, module, deploymentConfiguration);
|
||||
|
||||
final ServerType<?> cloudType = account.getType();
|
||||
final Project project = module.getProject();
|
||||
new CloudConnectionTask<Object, SC, DC, SR>(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<SC, DC, SR, AC> createApplicationConfigurable(@Nullable Project project,
|
||||
Disposable parentDisposable);
|
||||
|
||||
protected abstract DC createDeploymentConfiguration();
|
||||
|
||||
protected abstract void doConfigureModule(AC applicationConfiguration,
|
||||
DeployToServerRunConfiguration<SC, DC> runConfiguration,
|
||||
boolean firstAttempt,
|
||||
SR serverRuntime) throws ServerRuntimeException;
|
||||
}
|
||||
-158
@@ -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<DC, ?, ?, ?>,
|
||||
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<SC> getAccount() {
|
||||
return (RemoteServer<SC>)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<Collection<Deployment>>("Loading existing applications list") {
|
||||
|
||||
@Override
|
||||
protected void run(final ServerConnection<DC> connection,
|
||||
final Semaphore semaphore,
|
||||
final AtomicReference<Collection<Deployment>> result) {
|
||||
connection.connectIfNeeded(new ServerConnector.ConnectionCallback<DC>() {
|
||||
|
||||
@Override
|
||||
public void connected(@NotNull ServerRuntimeInstance<DC> 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<Deployment> run(SR serverRuntimeInstance) throws ServerRuntimeException {
|
||||
return null;
|
||||
}
|
||||
}.performAsync();
|
||||
}
|
||||
|
||||
private void setupExistingApplications(Collection<Deployment> 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<T> extends CloudConnectionTask<T, SC, DC, SR> {
|
||||
|
||||
public ConnectionTask(String title) {
|
||||
super(myProject, title, CloudSourceApplicationConfigurable.this.getAccount());
|
||||
}
|
||||
}
|
||||
}
|
||||
-36
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
<extensionPoint name="remoteServer.type" interface="com.intellij.remoteServer.ServerType"/>
|
||||
<extensionPoint name="remoteServer.deploymentSource.type" interface="com.intellij.remoteServer.configuration.deployment.DeploymentSourceType"/>
|
||||
|
||||
<extensionPoint name="remoteServer.util.CloudDeploymentRuntimeProvider"
|
||||
interface="com.intellij.remoteServer.util.CloudDeploymentRuntimeProvider"/>
|
||||
<extensionPoint name="remoteServer.runConfigurationExtension"
|
||||
interface="com.intellij.remoteServer.impl.configuration.deployment.DeployToServerRunConfigurationExtension"/>
|
||||
</extensionPoints>
|
||||
|
||||
-55
@@ -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<D extends DeploymentConfiguration, S extends ServerConfiguration>
|
||||
extends DeploymentConfigurator<D, S> {
|
||||
|
||||
private final Project myProject;
|
||||
private final ServerType<S> myServerType;
|
||||
|
||||
public CloudDeploymentConfiguratorBase(Project project, ServerType<S> serverType) {
|
||||
myProject = project;
|
||||
myServerType = serverType;
|
||||
}
|
||||
|
||||
public static List<CloudDeploymentRuntimeProvider> getDeploymentRuntimeProviders(ServerType<?> serverType) {
|
||||
List<CloudDeploymentRuntimeProvider> 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<DeploymentSource> getAvailableDeploymentSources() {
|
||||
if (myProject.isDefault()) return Collections.emptyList();
|
||||
List<DeploymentSource> result = new ArrayList<>();
|
||||
for (CloudDeploymentRuntimeProvider provider : getDeploymentRuntimeProviders(myServerType)) {
|
||||
result.addAll(provider.getDeploymentSources(myProject));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Project getProject() {
|
||||
return myProject;
|
||||
}
|
||||
}
|
||||
-72
@@ -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<? extends CloudDeploymentNameConfiguration> 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;
|
||||
}
|
||||
-44
@@ -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<CloudDeploymentRuntimeProvider> EP_NAME
|
||||
= ExtensionPointName.create("com.intellij.remoteServer.util.CloudDeploymentRuntimeProvider");
|
||||
|
||||
ServerType<?> getServerType();
|
||||
|
||||
Collection<DeploymentSource> getDeploymentSources(Project project);
|
||||
|
||||
CloudDeploymentRuntime createDeploymentRuntime(DeploymentSource source,
|
||||
CloudMultiSourceServerRuntimeInstance serverRuntime,
|
||||
DeploymentTask<? extends CloudDeploymentNameConfiguration> deploymentTask,
|
||||
DeploymentLogManager logManager)
|
||||
throws ServerRuntimeException;
|
||||
}
|
||||
-109
@@ -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<Boolean> 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();
|
||||
}
|
||||
}
|
||||
-177
@@ -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<AC, ?>,
|
||||
SC extends AC>
|
||||
extends CloudServerRuntimeInstance<DC, A, SC> {
|
||||
|
||||
private static final Logger LOG = Logger.getInstance(CloudMultiSourceServerRuntimeInstance.class);
|
||||
|
||||
private final ServerType<?> myServerType;
|
||||
|
||||
public CloudMultiSourceServerRuntimeInstance(ServerType<?> serverType,
|
||||
SC configuration,
|
||||
ServerTaskExecutor tasksExecutor,
|
||||
List<File> libraries,
|
||||
List<Class<?>> commonJarClasses,
|
||||
String specificsModuleName,
|
||||
String specificJarPath,
|
||||
Class<A> 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<DC> 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<DC> 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<?, DC> 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<DC>() {
|
||||
|
||||
@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<DC> 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user