From 19a38e2a641b56ae6d5dc27f5e4e9dc91efdedb1 Mon Sep 17 00:00:00 2001 From: Michael Golubev Date: Fri, 19 Feb 2016 19:04:18 +0100 Subject: [PATCH] IDEA-151921 - Docker Compose: show composed services / containers in separate subtree --- .../remoteServer/runtime/Deployment.java | 6 +- .../runtime/deployment/DeploymentRuntime.java | 6 + .../deployment/ServerRuntimeInstance.java | 8 +- .../impl/runtime/ServerConnectionImpl.java | 8 +- .../runtime/deployment/DeploymentImpl.java | 10 +- .../deployment/LocalDeploymentImpl.java | 3 +- .../runtime/ui/ServersToolWindowContent.java | 3 +- .../runtime/ui/tree/ServersTreeStructure.java | 118 +++++------------- .../util/CloudApplicationRuntime.java | 5 - .../util/CloudServerRuntimeInstance.java | 5 +- 10 files changed, 52 insertions(+), 120 deletions(-) diff --git a/platform/remote-servers/api/src/com/intellij/remoteServer/runtime/Deployment.java b/platform/remote-servers/api/src/com/intellij/remoteServer/runtime/Deployment.java index 288298aa147b..5a8bfdc06716 100644 --- a/platform/remote-servers/api/src/com/intellij/remoteServer/runtime/Deployment.java +++ b/platform/remote-servers/api/src/com/intellij/remoteServer/runtime/Deployment.java @@ -27,6 +27,9 @@ public interface Deployment { @Nullable DeploymentRuntime getRuntime(); + @Nullable + DeploymentRuntime getParentRuntime(); + @Nullable DeploymentTask getDeploymentTask(); @@ -37,7 +40,4 @@ public interface Deployment { @NotNull ServerConnection getConnection(); - - @Nullable - String getGroup(); } diff --git a/platform/remote-servers/api/src/com/intellij/remoteServer/runtime/deployment/DeploymentRuntime.java b/platform/remote-servers/api/src/com/intellij/remoteServer/runtime/deployment/DeploymentRuntime.java index 7a6cbd177b70..c153558dfe51 100644 --- a/platform/remote-servers/api/src/com/intellij/remoteServer/runtime/deployment/DeploymentRuntime.java +++ b/platform/remote-servers/api/src/com/intellij/remoteServer/runtime/deployment/DeploymentRuntime.java @@ -2,6 +2,7 @@ package com.intellij.remoteServer.runtime.deployment; import com.intellij.remoteServer.runtime.RemoteOperationCallback; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * @author nik @@ -13,6 +14,11 @@ public abstract class DeploymentRuntime { public abstract void undeploy(@NotNull UndeploymentTaskCallback callback); + @Nullable + public DeploymentRuntime getParent() { + return null; + } + public interface UndeploymentTaskCallback extends RemoteOperationCallback { void succeeded(); } diff --git a/platform/remote-servers/api/src/com/intellij/remoteServer/runtime/deployment/ServerRuntimeInstance.java b/platform/remote-servers/api/src/com/intellij/remoteServer/runtime/deployment/ServerRuntimeInstance.java index 8abd4933338f..5cbc1bd558c6 100644 --- a/platform/remote-servers/api/src/com/intellij/remoteServer/runtime/deployment/ServerRuntimeInstance.java +++ b/platform/remote-servers/api/src/com/intellij/remoteServer/runtime/deployment/ServerRuntimeInstance.java @@ -35,11 +35,6 @@ public abstract class ServerRuntimeInstance { return getDeploymentName(source, configuration); } - @Nullable - public String getDeploymentGroup(@NotNull DeploymentSource source, D configuration) { - return null; - } - public abstract void disconnect(); public interface DeploymentOperationCallback extends RemoteOperationCallback { @@ -54,8 +49,7 @@ public abstract class ServerRuntimeInstance { Deployment addDeployment(@NotNull String deploymentName, @Nullable DeploymentRuntime deploymentRuntime, @Nullable DeploymentStatus deploymentStatus, - @Nullable String deploymentStatusText, - @Nullable String deploymentGroup); + @Nullable String deploymentStatusText); void succeeded(); } 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 a654869857cc..0a8ed6672f66 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 @@ -188,15 +188,14 @@ public class ServerConnectionImpl implements @Override public void addDeployment(@NotNull String deploymentName, @Nullable DeploymentRuntime deploymentRuntime) { - addDeployment(deploymentName, deploymentRuntime, null, null, null); + addDeployment(deploymentName, deploymentRuntime, null, null); } @Override public Deployment addDeployment(@NotNull String deploymentName, @Nullable DeploymentRuntime deploymentRuntime, @Nullable DeploymentStatus deploymentStatus, - @Nullable String deploymentStatusText, - @Nullable String deploymentGroup) { + @Nullable String deploymentStatusText) { DeploymentImpl result; if (deploymentStatus == null) { deploymentStatus = DeploymentStatus.DEPLOYED; @@ -209,8 +208,7 @@ public class ServerConnectionImpl implements deploymentStatus, deploymentStatusText, deploymentRuntime, - null, - deploymentGroup); + null); } else if (!result.getStatus().isTransition()) { result.changeState(result.getStatus(), deploymentStatus, deploymentStatusText, deploymentRuntime); diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/deployment/DeploymentImpl.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/deployment/DeploymentImpl.java index e5848003554e..c12a69371263 100644 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/deployment/DeploymentImpl.java +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/deployment/DeploymentImpl.java @@ -19,7 +19,6 @@ public class DeploymentImpl implements Deploy private final ServerConnectionImpl myConnection; private final String myName; private final DeploymentTask myDeploymentTask; - private final String myGroup; private volatile DeploymentState myState; private String myPresentableName; @@ -28,12 +27,10 @@ public class DeploymentImpl implements Deploy @NotNull DeploymentStatus status, @Nullable String statusText, @Nullable DeploymentRuntime runtime, - @Nullable DeploymentTask deploymentTask, - @Nullable String group) { + @Nullable DeploymentTask deploymentTask) { myConnection = connection; myName = name; myDeploymentTask = deploymentTask; - myGroup = group; myState = new DeploymentState(status, statusText, runtime); } @@ -89,8 +86,9 @@ public class DeploymentImpl implements Deploy @Nullable @Override - public String getGroup() { - return myGroup; + public DeploymentRuntime getParentRuntime() { + DeploymentRuntime runtime = getRuntime(); + return runtime == null ? null : runtime.getParent(); } public boolean changeState(@NotNull DeploymentStatus oldStatus, @NotNull DeploymentStatus newStatus, @Nullable String statusText, diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/deployment/LocalDeploymentImpl.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/deployment/LocalDeploymentImpl.java index 046dab2782e5..352b12c92d3f 100644 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/deployment/LocalDeploymentImpl.java +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/deployment/LocalDeploymentImpl.java @@ -40,8 +40,7 @@ public class LocalDeploymentImpl extends Depl status, statusText, runtime, - deploymentTask, - instance.getDeploymentGroup(deploymentTask.getSource(), deploymentTask.getConfiguration())); + deploymentTask); myServerInstance = instance; } 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 f0a0ad2fea2e..63566d069159 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 @@ -216,8 +216,7 @@ public class ServersToolWindowContent extends JPanel implements Disposable, Serv @Override protected boolean isAutoExpandNode(NodeDescriptor nodeDescriptor) { return (nodeDescriptor instanceof ServersTreeStructure.RemoteServerNode - || nodeDescriptor instanceof ServersTreeStructure.DeploymentNodeImpl - || nodeDescriptor instanceof ServersTreeStructure.GroupNode) + || nodeDescriptor instanceof ServersTreeStructure.DeploymentNodeImpl) && (!myCollapsedTreeNodeValues.contains(((AbstractTreeNode)nodeDescriptor).getValue())); } }; 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 f286fc96969d..807680d89bb8 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 @@ -20,7 +20,6 @@ import com.intellij.openapi.ui.popup.ListPopup; import com.intellij.openapi.ui.popup.PopupStep; import com.intellij.openapi.ui.popup.util.BaseListPopupStep; import com.intellij.openapi.util.Condition; -import com.intellij.openapi.util.Factory; import com.intellij.openapi.util.text.StringUtil; import com.intellij.remoteServer.ServerType; import com.intellij.remoteServer.configuration.RemoteServer; @@ -49,7 +48,10 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.event.MouseEvent; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; /** * @author michael.golubev @@ -63,9 +65,6 @@ public class ServersTreeStructure extends AbstractTreeStructureBase { private final RemoteServersViewContribution myContribution; private final ServersTreeNodeSelector myNodeSelector; - private final Map> myServer2DeploymentGroups - = new HashMap>(); - public ServersTreeStructure(@NotNull Project project, @NotNull RemoteServersViewContribution contribution, @NotNull ServersTreeNodeSelector nodeSelector) { @@ -169,39 +168,11 @@ public class ServersTreeStructure extends AbstractTreeStructureBase { return Collections.emptyList(); } - Map group2node = new HashMap(); final List children = new ArrayList(); for (Deployment deployment : connection.getDeployments()) { - final String groupName = deployment.getGroup(); - if (groupName == null) { + if (deployment.getParentRuntime() == null) { children.add(createDeploymentNode(connection, this, deployment)); } - else { - Map groups - = ContainerUtil.getOrCreate(myServer2DeploymentGroups, getServer(), new Factory>() { - @Override - public Map create() { - return new HashMap(); - } - }); - - final DeploymentGroup group - = ContainerUtil.getOrCreate(groups, groupName, new Factory() { - @Override - public DeploymentGroup create() { - return new DeploymentGroup(groupName); - } - }); - - ContainerUtil.getOrCreate(group2node, group, new Factory() { - @Override - public GroupNode create() { - GroupNode result = new GroupNode(connection, RemoteServerNode.this, group); - children.add(result); - return result; - } - }); - } } return children; } @@ -428,15 +399,36 @@ public class ServersTreeStructure extends AbstractTreeStructureBase { @NotNull @Override public Collection getChildren() { - DeploymentLogManagerImpl logManager = (DeploymentLogManagerImpl)getConnection().getLogManager(getDeployment()); + List result = new ArrayList(); + collectDeploymentChildren(result); + collectLogChildren(result); + return result; + } + + protected void collectDeploymentChildren(List children) { + ServerConnection connection = getConnection(); + if (connection == null) { + return; + } + for (Deployment deployment : connection.getDeployments()) { + DeploymentRuntime parent = deployment.getParentRuntime(); + if (parent != null && parent == getDeployment().getRuntime()) { + children.add(createDeploymentNode(connection, myServerNode, deployment)); + } + } + } + + protected void collectLogChildren(List children) { + ServerConnection connection = getConnection(); + if (connection == null) { + return; + } + DeploymentLogManagerImpl logManager = (DeploymentLogManagerImpl)connection.getLogManager(getDeployment()); if (logManager != null) { - List nodes = new ArrayList(); for (LoggingHandlerBase loggingComponent : logManager.getAdditionalLoggingHandlers()) { - nodes.add(new DeploymentLogNode(loggingComponent, this)); + children.add(new DeploymentLogNode(loggingComponent, this)); } - return nodes; } - return Collections.emptyList(); } @Override @@ -484,52 +476,4 @@ public class ServersTreeStructure extends AbstractTreeStructureBase { return myDeploymentNode.getId() + ";log:" + getLogName(); } } - - private static class DeploymentGroup { - - private final String myName; - - private DeploymentGroup(String name) { - myName = name; - } - - public String getName() { - return myName; - } - } - - public class GroupNode extends AbstractTreeNode implements ServersTreeNode { - - @NotNull private final ServerConnection myConnection; - @NotNull private final RemoteServerNode myServerNode; - - public GroupNode(@NotNull ServerConnection connection, @NotNull RemoteServerNode serverNode, @NotNull DeploymentGroup group) { - super(doGetProject(), group); - myConnection = connection; - myServerNode = serverNode; - } - - @NotNull - public DeploymentGroup getGroup() { - return getValue(); - } - - @NotNull - @Override - public Collection getChildren() { - List children = new ArrayList(); - for (Deployment deployment : myConnection.getDeployments()) { - if (StringUtil.equals(getGroup().getName(), deployment.getGroup())) { - children.add(createDeploymentNode(myConnection, myServerNode, deployment)); - } - } - return children; - } - - @Override - protected void update(PresentationData presentation) { - presentation.setIcon(myServerNode.getServer().getType().getIcon()); - presentation.setPresentableText(getGroup().getName()); - } - } } 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 index 44a7bf3385e1..1bc9f8620253 100644 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudApplicationRuntime.java +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudApplicationRuntime.java @@ -72,11 +72,6 @@ public abstract class CloudApplicationRuntime extends DeploymentRuntime { protected abstract ServerType getCloudType(); - @Nullable - public String getGroup() { - return null; - } - protected abstract class LoggingTask { public void perform(final Project project, final Runnable onDone) { 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 7b5be53aa87f..1472e08106e6 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 @@ -100,8 +100,7 @@ public abstract class CloudServerRuntimeInstance = callback.addDeployment(application.getApplicationName(), application, application.getStatus(), - application.getStatusText(), - application.getGroup()); + application.getStatusText()); application.setDeploymentModel(deployment); } callback.succeeded(); @@ -113,7 +112,7 @@ public abstract class CloudServerRuntimeInstance }, callback); } - private List getApplications() throws ServerRuntimeException { + protected List getApplications() throws ServerRuntimeException { return getAgentTaskExecutor().execute(new Computable>() { @Override