diff options
Diffstat (limited to 'platform/remote-servers/impl/src/com/intellij/remoteServer')
15 files changed, 537 insertions, 274 deletions
diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/agent/impl/ThreadInvocationHandler.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/agent/impl/ThreadInvocationHandler.java index 3e260227abe1..71b368031233 100644 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/agent/impl/ThreadInvocationHandler.java +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/agent/impl/ThreadInvocationHandler.java @@ -10,10 +10,7 @@ import com.intellij.remoteServer.agent.impl.util.SequentialTaskExecutor; import com.intellij.util.containers.HashMap; import org.jetbrains.annotations.Nullable; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; +import java.lang.reflect.*; import java.util.Map; import java.util.concurrent.Callable; @@ -79,35 +76,20 @@ public class ThreadInvocationHandler implements InvocationHandler { return cached; } + Object result; Class<?> childClass = child.getClass(); - Class<?>[] childInterfaces = childClass.getInterfaces(); - LOG.assertTrue(childInterfaces.length == 1, "Child class is expected to implement single child interface"); - Class<?> childInterface = childInterfaces[0]; - - Class<?> callerChildInterface; - try { - callerChildInterface = myCallerClassLoader.loadClass(childInterface.getName()); - } - catch (ClassNotFoundException e) { - LOG.error(e); - return null; - } - - Object preWrappedChild; - if (myPreWrapperFactory == null) { - preWrappedChild = child; + if (childClass.isArray()) { + Class<?> componentType = childClass.getComponentType(); + int length = Array.getLength(child); + result = Array.newInstance(componentType, length); + for (int i = 0; i < length; i++) { + Array.set(result, i, createChildProxy(Array.get(child, i))); + } } else { - preWrappedChild = Proxy.newProxyInstance(myCallerClassLoader, - new Class[]{callerChildInterface}, - myPreWrapperFactory.createWrapperInvocationHandler(child)); + result = createChildProxy(child); } - Object result = Proxy.newProxyInstance(myCallerClassLoader, - new Class[]{callerChildInterface}, - new ThreadInvocationHandler(myTaskExecutor, myCallerClassLoader, preWrappedChild, - myPreWrapperFactory)); - myChild2Wrapped.put(child, result); return result; } @@ -150,4 +132,35 @@ public class ThreadInvocationHandler implements InvocationHandler { } } } + + private Object createChildProxy(Object child) { + Class<?> childClass = child.getClass(); + Class<?>[] childInterfaces = childClass.getInterfaces(); + LOG.assertTrue(childInterfaces.length == 1, "Child class is expected to implement single child interface"); + Class<?> childInterface = childInterfaces[0]; + + Class<?> callerChildInterface; + try { + callerChildInterface = myCallerClassLoader.loadClass(childInterface.getName()); + } + catch (ClassNotFoundException e) { + LOG.error(e); + return null; + } + + Object preWrappedChild; + if (myPreWrapperFactory == null) { + preWrappedChild = child; + } + else { + preWrappedChild = Proxy.newProxyInstance(myCallerClassLoader, + new Class[]{callerChildInterface}, + myPreWrapperFactory.createWrapperInvocationHandler(child)); + } + + return Proxy.newProxyInstance(myCallerClassLoader, + new Class[]{callerChildInterface}, + new ThreadInvocationHandler(myTaskExecutor, myCallerClassLoader, preWrappedChild, + myPreWrapperFactory)); + } } diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/DeployToServerState.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/DeployToServerState.java index c633976df2be..68cbafb202b6 100644 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/DeployToServerState.java +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/DeployToServerState.java @@ -67,18 +67,13 @@ public class DeployToServerState<S extends ServerConfiguration, D extends Deploy else { debugConnector = null; } - connection.computeDeployments(new Runnable() { - @Override - public void run() { - connection.deploy(new DeploymentTaskImpl(mySource, myConfiguration, project, debugConnector, myEnvironment), - new ParameterizedRunnable<String>() { - @Override - public void run(String s) { - RemoteServersView.getInstance(project).showDeployment(connection, s); - } - }); - } - }); + connection.deploy(new DeploymentTaskImpl(mySource, myConfiguration, project, debugConnector, myEnvironment), + new ParameterizedRunnable<String>() { + @Override + public void run(String s) { + RemoteServersView.getInstance(project).showDeployment(connection, s); + } + }); return null; } } diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ServerConnectionImpl.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ServerConnectionImpl.java index fe43f2aa4f4d..5c0e27634041 100644 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ServerConnectionImpl.java +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ServerConnectionImpl.java @@ -19,6 +19,7 @@ import com.intellij.remoteServer.runtime.deployment.*; import com.intellij.remoteServer.runtime.deployment.debug.DebugConnectionData; import com.intellij.remoteServer.runtime.deployment.debug.DebugConnectionDataNotAvailableException; import com.intellij.remoteServer.runtime.deployment.debug.DebugConnector; +import com.intellij.util.Consumer; import com.intellij.util.ParameterizedRunnable; import com.intellij.util.containers.ConcurrentHashMap; import org.jetbrains.annotations.NotNull; @@ -38,7 +39,7 @@ public class ServerConnectionImpl<D extends DeploymentConfiguration> implements private volatile ConnectionStatus myStatus = ConnectionStatus.DISCONNECTED; private volatile String myStatusText; private volatile ServerRuntimeInstance<D> myRuntimeInstance; - private final Map<String, Deployment> myRemoteDeployments = new HashMap<String, Deployment>(); + private final Map<String, DeploymentImpl> myRemoteDeployments = new HashMap<String, DeploymentImpl>(); private final Map<String, DeploymentImpl> myLocalDeployments = new HashMap<String, DeploymentImpl>(); private final Map<String, DeploymentLogManagerImpl> myLogManagers = new ConcurrentHashMap<String, DeploymentLogManagerImpl>(); @@ -110,7 +111,7 @@ public class ServerConnectionImpl<D extends DeploymentConfiguration> implements @Override public void connected(@NotNull ServerRuntimeInstance<D> instance) { DeploymentSource source = task.getSource(); - String deploymentName = instance.getDeploymentName(source); + String deploymentName = instance.getDeploymentName(source, task.getConfiguration()); DeploymentImpl deployment; synchronized (myLocalDeployments) { deployment = new DeploymentImpl(deploymentName, DeploymentStatus.DEPLOYING, null, null, task); @@ -149,18 +150,23 @@ public class ServerConnectionImpl<D extends DeploymentConfiguration> implements private void computeDeployments(ServerRuntimeInstance<D> instance, final Runnable onFinished) { instance.computeDeployments(new ServerRuntimeInstance.ComputeDeploymentsCallback() { - private final List<Deployment> myDeployments = new ArrayList<Deployment>(); + private final List<DeploymentImpl> myDeployments = new ArrayList<DeploymentImpl>(); @Override public void addDeployment(@NotNull String deploymentName) { - myDeployments.add(new DeploymentImpl(deploymentName, DeploymentStatus.DEPLOYED, null, null, null)); + addDeployment(deploymentName, null); + } + + @Override + public void addDeployment(@NotNull String deploymentName, @Nullable DeploymentRuntime deploymentRuntime) { + myDeployments.add(new DeploymentImpl(deploymentName, DeploymentStatus.DEPLOYED, null, deploymentRuntime, null)); } @Override public void succeeded() { synchronized (myRemoteDeployments) { myRemoteDeployments.clear(); - for (Deployment deployment : myDeployments) { + for (DeploymentImpl deployment : myDeployments) { myRemoteDeployments.put(deployment.getName(), deployment); } } @@ -183,25 +189,57 @@ public class ServerConnectionImpl<D extends DeploymentConfiguration> implements @Override public void undeploy(@NotNull Deployment deployment, @NotNull final DeploymentRuntime runtime) { final String deploymentName = deployment.getName(); - final DeploymentImpl localDeployment; + final DeploymentImpl deploymentImpl; + final Map<String, DeploymentImpl> deploymentsMap; synchronized (myLocalDeployments) { - localDeployment = myLocalDeployments.get(deploymentName); - if (localDeployment != null) { - localDeployment.changeState(DeploymentStatus.DEPLOYED, DeploymentStatus.UNDEPLOYING, null, null); + synchronized (myRemoteDeployments) { + DeploymentImpl localDeployment = myLocalDeployments.get(deploymentName); + if (localDeployment != null) { + deploymentImpl = localDeployment; + deploymentsMap = myLocalDeployments; + } + else { + DeploymentImpl remoteDeployment = myRemoteDeployments.get(deploymentName); + if (remoteDeployment != null) { + deploymentImpl = remoteDeployment; + deploymentsMap = myRemoteDeployments; + } + else { + deploymentImpl = null; + deploymentsMap = null; + } + } + if (deploymentImpl != null) { + deploymentImpl.changeState(DeploymentStatus.DEPLOYED, DeploymentStatus.UNDEPLOYING, null, null); + } } } myEventDispatcher.queueDeploymentsChanged(this); - final LoggingHandlerImpl loggingHandler = myLogManagers.get(deploymentName).getMainLoggingHandler(); - loggingHandler.printlnSystemMessage("Undeploying '" + deploymentName + "'..."); + DeploymentLogManagerImpl logManager = myLogManagers.get(deploymentName); + final LoggingHandlerImpl loggingHandler = logManager == null ? null : logManager.getMainLoggingHandler(); + final Consumer<String> logConsumer = new Consumer<String>() { + @Override + public void consume(String message) { + if (loggingHandler == null) { + LOG.info(message); + } + else { + loggingHandler.printlnSystemMessage(message); + } + } + }; + + logConsumer.consume("Undeploying '" + deploymentName + "'..."); runtime.undeploy(new DeploymentRuntime.UndeploymentTaskCallback() { @Override public void succeeded() { - loggingHandler.printlnSystemMessage("'" + deploymentName + "' has been undeployed successfully."); - synchronized (myLocalDeployments) { - if (localDeployment != null && - localDeployment.changeState(DeploymentStatus.UNDEPLOYING, DeploymentStatus.NOT_DEPLOYED, null, null)) { - myLocalDeployments.remove(deploymentName); + logConsumer.consume("'" + deploymentName + "' has been undeployed successfully."); + if (deploymentImpl != null) { + synchronized (deploymentsMap) { + if (deploymentImpl.changeState(DeploymentStatus.UNDEPLOYING, DeploymentStatus.NOT_DEPLOYED, null, null)) { + deploymentsMap.remove(deploymentName); + } } } myLogManagers.remove(deploymentName); @@ -211,10 +249,10 @@ public class ServerConnectionImpl<D extends DeploymentConfiguration> implements @Override public void errorOccurred(@NotNull String errorMessage) { - loggingHandler.printlnSystemMessage("Failed to undeploy '" + deploymentName + "': " + errorMessage); - synchronized (myLocalDeployments) { - if (localDeployment != null) { - localDeployment.changeState(DeploymentStatus.UNDEPLOYING, DeploymentStatus.DEPLOYED, errorMessage, runtime); + logConsumer.consume("Failed to undeploy '" + deploymentName + "': " + errorMessage); + if (deploymentImpl != null) { + synchronized (deploymentsMap) { + deploymentImpl.changeState(DeploymentStatus.UNDEPLOYING, DeploymentStatus.DEPLOYED, errorMessage, runtime); } } myEventDispatcher.queueDeploymentsChanged(ServerConnectionImpl.this); diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ServerConnectionManagerImpl.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ServerConnectionManagerImpl.java index 71f04e2265f1..f12e646a72b9 100644 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ServerConnectionManagerImpl.java +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ServerConnectionManagerImpl.java @@ -1,10 +1,12 @@ package com.intellij.remoteServer.impl.runtime; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.ModalityState; import com.intellij.remoteServer.configuration.RemoteServer; import com.intellij.remoteServer.configuration.ServerConfiguration; import com.intellij.remoteServer.runtime.ServerConnection; import com.intellij.remoteServer.runtime.ServerConnectionManager; +import com.intellij.util.Alarm; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -17,6 +19,9 @@ import java.util.Map; * @author nik */ public class ServerConnectionManagerImpl extends ServerConnectionManager { + + private static final int POLL_DEPLOYMENTS_DELAY = 2000; + private final Map<RemoteServer<?>, ServerConnection> myConnections = new HashMap<RemoteServer<?>, ServerConnection>(); private final ServerConnectionEventDispatcher myEventDispatcher = new ServerConnectionEventDispatcher(); @@ -29,10 +34,29 @@ public class ServerConnectionManagerImpl extends ServerConnectionManager { connection = doCreateConnection(server, this); myConnections.put(server, connection); myEventDispatcher.fireConnectionCreated(connection); + pollDeployments(connection); } return connection; } + private void pollDeployments(final ServerConnection connection) { + connection.computeDeployments(new Runnable() { + + @Override + public void run() { + new Alarm().addRequest(new Runnable() { + + @Override + public void run() { + if (connection == getConnection(connection.getServer())) { + pollDeployments(connection); + } + } + }, POLL_DEPLOYMENTS_DELAY, ModalityState.any()); + } + }); + } + @NotNull @Override public <C extends ServerConfiguration> ServerConnection createTemporaryConnection(@NotNull RemoteServer<C> server) { diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/ServersToolWindowContent.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/ServersToolWindowContent.java index df649453ee4e..f860d6dfa98c 100644 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/ServersToolWindowContent.java +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/ServersToolWindowContent.java @@ -108,7 +108,7 @@ public class ServersToolWindowContent extends JPanel implements Disposable { Set<ServersTreeStructure.RemoteServerNode> nodes = getSelectedRemoteServerNodes(); if (nodes.size() == 1) { RemoteServer<?> server = nodes.iterator().next().getValue(); - ServerConnectionManager.getInstance().getOrCreateConnection(server).computeDeployments(EmptyRunnable.INSTANCE); + ServerConnectionManager.getInstance().getOrCreateConnection(server); return true; } return false; diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/ServersTreeStructure.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/ServersTreeStructure.java index 96cd0fa87c56..4cb1c01943be 100644 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/ServersTreeStructure.java +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/ServersTreeStructure.java @@ -255,8 +255,7 @@ public class ServersTreeStructure extends AbstractTreeStructureBase { @Override public void startServer(@NotNull Executor executor) { - ServerConnection<?> connection = ServerConnectionManager.getInstance().getOrCreateConnection(getValue()); - connection.computeDeployments(EmptyRunnable.INSTANCE); + ServerConnectionManager.getInstance().getOrCreateConnection(getValue()); } @Override diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudApplicationRuntime.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudApplicationRuntime.java new file mode 100644 index 000000000000..093cfb50bcc0 --- /dev/null +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudApplicationRuntime.java @@ -0,0 +1,31 @@ +/* + * 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.util; + +import com.intellij.remoteServer.runtime.deployment.DeploymentRuntime; + +public abstract class CloudApplicationRuntime extends DeploymentRuntime { + + private final String myApplicationName; + + public CloudApplicationRuntime(String applicationName) { + myApplicationName = applicationName; + } + + public String getApplicationName() { + return myApplicationName; + } +} diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudApplicationRuntimeBase.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudApplicationRuntimeBase.java new file mode 100644 index 000000000000..a4689b16d57a --- /dev/null +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudApplicationRuntimeBase.java @@ -0,0 +1,55 @@ +/* + * 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.util; + +import com.intellij.remoteServer.agent.util.CloudAgentApplication; +import com.intellij.remoteServer.agent.util.CloudAgentDeploymentCallback; +import com.intellij.remoteServer.runtime.ServerTaskExecutor; +import com.intellij.util.ThrowableRunnable; +import org.jetbrains.annotations.NotNull; + +public abstract class CloudApplicationRuntimeBase extends CloudApplicationRuntime { + + private final ServerTaskExecutor myTaskExecutor; + + public CloudApplicationRuntimeBase(ServerTaskExecutor taskExecutor, String applicationName) { + super(applicationName); + myTaskExecutor = taskExecutor; + } + + @Override + public void undeploy(@NotNull final UndeploymentTaskCallback callback) { + myTaskExecutor.submit(new ThrowableRunnable<Exception>() { + + @Override + public void run() throws Exception { + getApplication().undeploy(new CloudAgentDeploymentCallback() { + @Override + public void succeeded() { + callback.succeeded(); + } + + @Override + public void errorOccurred(String errorMessage) { + callback.errorOccurred(errorMessage); + } + }); + } + }, callback); + } + + protected abstract CloudAgentApplication getApplication(); +} diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudApplicationRuntimeImpl.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudApplicationRuntimeImpl.java new file mode 100644 index 000000000000..a3d780ab8cc4 --- /dev/null +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudApplicationRuntimeImpl.java @@ -0,0 +1,35 @@ +/* + * 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.util; + +import com.intellij.remoteServer.agent.util.CloudAgentApplication; +import com.intellij.remoteServer.agent.util.CloudAgentBase; +import com.intellij.remoteServer.runtime.ServerTaskExecutor; + +public class CloudApplicationRuntimeImpl extends CloudApplicationRuntimeBase { + + private final CloudAgentApplication myAgentApplication; + + public CloudApplicationRuntimeImpl(ServerTaskExecutor taskExecutor, CloudAgentBase agent, String applicationName) { + super(taskExecutor, applicationName); + myAgentApplication = agent.createApplication(applicationName); + } + + @Override + protected CloudAgentApplication getApplication() { + return myAgentApplication; + } +} diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudConnectionTask.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudConnectionTask.java index bd83b9d27d48..82492e130f0e 100644 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudConnectionTask.java +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudConnectionTask.java @@ -37,7 +37,7 @@ public abstract class CloudConnectionTask< T, SC extends ServerConfigurationBase, DC extends DeploymentConfiguration, - SR extends CloudServerRuntimeInstance<DC>> extends CloudRuntimeTask<T, DC, SR> { + SR extends CloudServerRuntimeInstance<DC, ?, ?>> extends CloudRuntimeTask<T, DC, SR> { private final RemoteServer<SC> myServer; 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 index d21c319ad6ca..1ddf9b3cb7d6 100644 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudDeploymentRuntime.java +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudDeploymentRuntime.java @@ -15,75 +15,43 @@ */ package com.intellij.remoteServer.util; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.Messages; -import com.intellij.openapi.util.Ref; -import com.intellij.remoteServer.agent.util.CloudApplication; -import com.intellij.remoteServer.agent.util.CloudGitAgentDeployment; -import com.intellij.remoteServer.agent.util.CloudLoggingHandler; +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.DeploymentRuntime; import com.intellij.remoteServer.runtime.deployment.DeploymentTask; import com.intellij.remoteServer.runtime.deployment.ServerRuntimeInstance; import com.intellij.remoteServer.runtime.log.LoggingHandler; -import com.intellij.util.ThrowableRunnable; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** * @author michael.golubev */ -public abstract class CloudDeploymentRuntime extends DeploymentRuntime { +public abstract class CloudDeploymentRuntime extends CloudGitApplicationRuntime { - private final CloudMultiSourceServerRuntimeInstance myServerRuntime; private final DeploymentTask myTask; - private final CloudGitAgentDeployment myDeployment; - private final String myApplicationName; - private final String myPresentableName; - private final CloudLoggingHandler myLoggingHandler; - @Nullable private final DeploymentLogManager myLogManager; - public CloudDeploymentRuntime(CloudMultiSourceServerRuntimeInstance serverRuntime, DeploymentSource source, DeploymentTask<? extends CloudDeploymentNameConfiguration> task, @Nullable DeploymentLogManager logManager) throws ServerRuntimeException { - myServerRuntime = serverRuntime; + super(serverRuntime, + task.getConfiguration().getDeploymentSourceName(source), + logManager); myTask = task; - - myLogManager = logManager; - myLoggingHandler = logManager == null ? new CloudSilentLoggingHandlerImpl() : new CloudLoggingHandlerImpl(logManager); - - CloudDeploymentNameConfiguration deploymentConfiguration = task.getConfiguration(); - myApplicationName = deploymentConfiguration.getDeploymentSourceName(source); - - myPresentableName = source.getPresentableName(); - - myDeployment = serverRuntime.getAgent().createDeployment(myApplicationName, myLoggingHandler); - } - - protected CloudMultiSourceServerRuntimeInstance getServerRuntime() { - return myServerRuntime; } protected DeploymentTask getTask() { return myTask; } - @Nullable - protected DeploymentLogManager getLogManager() { - return myLogManager; - } - public void deploy(ServerRuntimeInstance.DeploymentOperationCallback callback) { try { - CloudApplication application = deploy(); + CloudRemoteApplication application = deploy(); - if (myLogManager != null) { - LoggingHandler loggingHandler = myLogManager.getMainLoggingHandler(); + DeploymentLogManager logManager = getLogManager(); + if (logManager != null) { + LoggingHandler loggingHandler = logManager.getMainLoggingHandler(); loggingHandler.print("Application is available at "); loggingHandler.printHyperlink(application.getWebUrl()); loggingHandler.print("\n"); @@ -96,72 +64,9 @@ public abstract class CloudDeploymentRuntime extends DeploymentRuntime { } } - @Override - public void undeploy(final @NotNull UndeploymentTaskCallback callback) { - myServerRuntime.getTaskExecutor().submit(new ThrowableRunnable<Exception>() { - - @Override - public void run() throws Exception { - try { - if (!confirmUndeploy()) { - throw new ServerRuntimeException("Undeploy cancelled"); - } - - undeploy(); - - callback.succeeded(); - } - catch (ServerRuntimeException e) { - callback.errorOccurred(e.getMessage()); - } - } - }, callback); - } - - public CloudGitAgentDeployment getDeployment() { - return myDeployment; - } - public Project getProject() { return myTask.getProject(); } - public String getApplicationName() { - return myApplicationName; - } - - public AgentTaskExecutor getAgentTaskExecutor() { - return myServerRuntime.getAgentTaskExecutor(); - } - - public CloudLoggingHandler getLoggingHandler() { - return myLoggingHandler; - } - - public boolean confirmUndeploy() { - final Ref<Boolean> confirmed = new Ref<Boolean>(false); - ApplicationManager.getApplication().invokeAndWait(new Runnable() { - - @Override - public void run() { - String title = CloudBundle.getText("cloud.undeploy.confirm.title"); - while (true) { - String password = Messages.showPasswordDialog(CloudBundle.getText("cloud.undeploy.confirm.message", myPresentableName), title); - if (password == null) { - return; - } - if (password.equals(myServerRuntime.getConfiguration().getPassword())) { - confirmed.set(true); - return; - } - Messages.showErrorDialog(CloudBundle.getText("cloud.undeploy.confirm.password.incorrect"), title); - } - } - }, ModalityState.defaultModalityState()); - return confirmed.get(); - } - - public abstract CloudApplication deploy() throws ServerRuntimeException; - - public abstract void undeploy() throws ServerRuntimeException; + public abstract CloudRemoteApplication deploy() 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 new file mode 100644 index 000000000000..990167d951e4 --- /dev/null +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudGitApplicationRuntime.java @@ -0,0 +1,124 @@ +/* + * 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.util; + +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.ModalityState; +import com.intellij.openapi.ui.Messages; +import com.intellij.openapi.util.Computable; +import com.intellij.openapi.util.Ref; +import com.intellij.remoteServer.agent.util.CloudGitAgentDeployment; +import com.intellij.remoteServer.agent.util.CloudLoggingHandler; +import com.intellij.remoteServer.runtime.deployment.DeploymentLogManager; +import com.intellij.util.ThrowableRunnable; +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 CloudLoggingHandler 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() : new CloudLoggingHandlerImpl(logManager); + myDeployment = serverRuntime.getAgent().createDeployment(applicationName, myLoggingHandler); + } + + protected CloudMultiSourceServerRuntimeInstance getServerRuntime() { + return myServerRuntime; + } + + protected DeploymentLogManager getLogManager() { + return myLogManager; + } + + protected CloudLoggingHandler getLoggingHandler() { + return myLoggingHandler; + } + + public AgentTaskExecutor getAgentTaskExecutor() { + return getServerRuntime().getAgentTaskExecutor(); + } + + public CloudGitAgentDeployment getDeployment() { + return myDeployment; + } + + @Override + public void undeploy(final @NotNull UndeploymentTaskCallback callback) { + getServerRuntime().getTaskExecutor().submit(new ThrowableRunnable<Exception>() { + + @Override + public void run() throws Exception { + 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(new Computable<Object>() { + + @Override + public Object compute() { + getDeployment().deleteApplication(); + return null; + } + }); + } + + private boolean confirmUndeploy() { + final Ref<Boolean> confirmed = new Ref<Boolean>(false); + ApplicationManager.getApplication().invokeAndWait(new Runnable() { + + @Override + public void run() { + String title = CloudBundle.getText("cloud.undeploy.confirm.title"); + while (true) { + String password = Messages.showPasswordDialog(CloudBundle.getText("cloud.undeploy.confirm.message", getApplicationName()), title); + if (password == null) { + return; + } + if (password.equals(getServerRuntime().getConfiguration().getPassword())) { + confirmed.set(true); + return; + } + Messages.showErrorDialog(CloudBundle.getText("cloud.undeploy.confirm.password.incorrect"), title); + } + } + }, ModalityState.defaultModalityState()); + 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 index 8db26a7ad661..3fd3f24b190c 100644 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudMultiSourceServerRuntimeInstance.java +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudMultiSourceServerRuntimeInstance.java @@ -4,11 +4,9 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Computable; import com.intellij.remoteServer.ServerType; -import com.intellij.remoteServer.agent.RemoteAgentManager; 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.DeploymentData; import com.intellij.remoteServer.configuration.deployment.DeploymentSource; import com.intellij.remoteServer.impl.configuration.deployment.DeployToServerRunConfiguration; import com.intellij.remoteServer.runtime.ServerConnector; @@ -31,16 +29,11 @@ public abstract class CloudMultiSourceServerRuntimeInstance< AC extends CloudAgentConfigBase, A extends CloudGitAgent<AC, ?>, SC extends AC> - extends CloudServerRuntimeInstance<DC> { + extends CloudServerRuntimeInstance<DC, A, SC> { private static final Logger LOG = Logger.getInstance("#" + CloudMultiSourceServerRuntimeInstance.class.getName()); - private final A myAgent; - private final AgentTaskExecutor myAgentTaskExecutor; - private final ServerType<?> myServerType; - private final SC myConfiguration; - private final ServerTaskExecutor myTasksExecutor; public CloudMultiSourceServerRuntimeInstance(ServerType<?> serverType, SC configuration, @@ -51,20 +44,21 @@ public abstract class CloudMultiSourceServerRuntimeInstance< String specificJarPath, Class<A> agentInterface, String agentClassName) throws Exception { + super(configuration, + tasksExecutor, + libraries, + commonJarClasses, + specificsModuleName, + specificJarPath, + agentInterface, + agentClassName); + myServerType = serverType; - myConfiguration = configuration; - myTasksExecutor = tasksExecutor; - - RemoteAgentManager agentManager = RemoteAgentManager.getInstance(); - myAgent = agentManager.createAgent(agentManager.createReflectiveThreadProxyFactory(getClass().getClassLoader()), - libraries, - commonJarClasses, - specificsModuleName, - specificJarPath, - agentInterface, - agentClassName, - getClass()); - myAgentTaskExecutor = new AgentTaskExecutor(); + } + + @Override + public A getAgent() { + return super.getAgent(); } @NotNull @@ -74,37 +68,37 @@ public abstract class CloudMultiSourceServerRuntimeInstance< } public void connect(final ServerConnector.ConnectionCallback<DC> callback) { - myAgentTaskExecutor.execute(new Computable() { - - @Override - public Object compute() { - doConnect(myConfiguration, - 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); - } - } + getAgentTaskExecutor().execute(new Computable() { + + @Override + public Object compute() { + 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); + } + } ); } @@ -112,7 +106,7 @@ public abstract class CloudMultiSourceServerRuntimeInstance< public void deploy(@NotNull final DeploymentTask<DC> task, @NotNull final DeploymentLogManager logManager, @NotNull final ServerRuntimeInstance.DeploymentOperationCallback callback) { - myTasksExecutor.submit(new ThrowableRunnable<Exception>() { + getTaskExecutor().submit(new ThrowableRunnable<Exception>() { @Override public void run() throws Exception { @@ -122,61 +116,16 @@ public abstract class CloudMultiSourceServerRuntimeInstance< } @Override - public void computeDeployments(@NotNull final ServerRuntimeInstance.ComputeDeploymentsCallback callback) { - myTasksExecutor.submit(new ThrowableRunnable<Exception>() { - @Override - public void run() throws Exception { - myAgentTaskExecutor.execute(new Computable<DeploymentData[]>() { - - @Override - public DeploymentData[] compute() { - return myAgent.getDeployments(); - } - }, - new CallbackWrapper<DeploymentData[]>() { - - @Override - public void onSuccess(DeploymentData[] deployments) { - for (DeploymentData deployment : deployments) { - callback.addDeployment(deployment.getName()); - } - callback.succeeded(); - } - - @Override - public void onError(String message) { - callback.errorOccurred(message); - } - } - ); - } - }, callback); - } - - @Override public void disconnect() { - myTasksExecutor.submit(new Runnable() { + getTaskExecutor().submit(new Runnable() { @Override public void run() { - myAgent.disconnect(); + getAgent().disconnect(); } }); } - @Override - public ServerTaskExecutor getTaskExecutor() { - return myTasksExecutor; - } - - protected final A getAgent() { - return myAgent; - } - - protected final AgentTaskExecutor getAgentTaskExecutor() { - return myAgentTaskExecutor; - } - public CloudDeploymentRuntime createDeploymentRuntime(final DeployToServerRunConfiguration<?, DC> runConfiguration) throws ServerRuntimeException { return createDeploymentRuntime(runConfiguration.getDeploymentSource(), @@ -225,8 +174,9 @@ public abstract class CloudMultiSourceServerRuntimeInstance< throw new ServerRuntimeException("Unknown deployment source"); } - public CloudConfigurationBase getConfiguration() { - return (CloudConfigurationBase)myConfiguration; + @Override + protected CloudApplicationRuntime createApplicationRuntime(String applicationName) { + return new CloudGitApplicationRuntime(this, applicationName, null); } protected abstract void doConnect(SC configuration, CloudAgentLogger logger); diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudRuntimeTask.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudRuntimeTask.java index 64194856c121..1e0326471d75 100644 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudRuntimeTask.java +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudRuntimeTask.java @@ -34,7 +34,7 @@ import java.util.concurrent.atomic.AtomicReference; public abstract class CloudRuntimeTask< T, DC extends DeploymentConfiguration, - SR extends CloudServerRuntimeInstance<DC>> { + SR extends CloudServerRuntimeInstance<DC, ?, ?>> { private static final Logger LOG = Logger.getInstance("#" + CloudRuntimeTask.class.getName()); diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudServerRuntimeInstance.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudServerRuntimeInstance.java index 89bd2179404a..65bd9066ca3b 100644 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudServerRuntimeInstance.java +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudServerRuntimeInstance.java @@ -15,14 +15,108 @@ */ package com.intellij.remoteServer.util; +import com.intellij.openapi.util.Computable; +import com.intellij.remoteServer.agent.RemoteAgentManager; +import com.intellij.remoteServer.agent.util.CloudAgent; +import com.intellij.remoteServer.agent.util.CloudAgentConfigBase; +import com.intellij.remoteServer.agent.util.CloudRemoteApplication; import com.intellij.remoteServer.configuration.deployment.DeploymentConfiguration; import com.intellij.remoteServer.runtime.ServerTaskExecutor; import com.intellij.remoteServer.runtime.deployment.ServerRuntimeInstance; +import com.intellij.util.ThrowableRunnable; +import org.jetbrains.annotations.NotNull; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; /** * @author michael.golubev */ -public abstract class CloudServerRuntimeInstance<DC extends DeploymentConfiguration> extends ServerRuntimeInstance<DC> { +public abstract class CloudServerRuntimeInstance + <DC extends DeploymentConfiguration, + A extends CloudAgent, + SC extends CloudAgentConfigBase> + extends ServerRuntimeInstance<DC> { + + private final A myAgent; + private final SC myConfiguration; + private final ServerTaskExecutor myTasksExecutor; + + private final AgentTaskExecutor myAgentTaskExecutor; + + public CloudServerRuntimeInstance(SC configuration, + ServerTaskExecutor tasksExecutor, + List<File> libraries, + List<Class<?>> commonJarClasses, + String specificsModuleName, + String specificJarPath, + Class<A> agentInterface, + String agentClassName) throws Exception { + myConfiguration = configuration; + myTasksExecutor = tasksExecutor; + + RemoteAgentManager agentManager = RemoteAgentManager.getInstance(); + myAgent = agentManager.createAgent(agentManager.createReflectiveThreadProxyFactory(getClass().getClassLoader()), + libraries, + commonJarClasses, + specificsModuleName, + specificJarPath, + agentInterface, + agentClassName, + getClass()); + + myAgentTaskExecutor = new AgentTaskExecutor(); + } + + public SC getConfiguration() { + return myConfiguration; + } + + public ServerTaskExecutor getTaskExecutor() { + return myTasksExecutor; + } + + public A getAgent() { + return myAgent; + } + + protected final AgentTaskExecutor getAgentTaskExecutor() { + return myAgentTaskExecutor; + } + + @Override + public void computeDeployments(@NotNull final ServerRuntimeInstance.ComputeDeploymentsCallback callback) { + getTaskExecutor().submit(new ThrowableRunnable<Exception>() { + + @Override + public void run() throws Exception { + try { + for (CloudApplicationRuntime application : getApplications()) { + callback.addDeployment(application.getApplicationName(), application); + } + callback.succeeded(); + } + catch (ServerRuntimeException e) { + callback.errorOccurred(e.getMessage()); + } + } + }, callback); + } + + private List<CloudApplicationRuntime> getApplications() throws ServerRuntimeException { + return getAgentTaskExecutor().execute(new Computable<List<CloudApplicationRuntime>>() { + + @Override + public List<CloudApplicationRuntime> compute() { + List<CloudApplicationRuntime> result = new ArrayList<CloudApplicationRuntime>(); + for (CloudRemoteApplication application : getAgent().getApplications()) { + result.add(createApplicationRuntime(application.getName())); + } + return result; + } + }); + } - public abstract ServerTaskExecutor getTaskExecutor(); + protected abstract CloudApplicationRuntime createApplicationRuntime(String applicationName); } |