Skip to content

Commit

Permalink
fix: dont refresh tree if binary is not downloaded (redhat-developer#802
Browse files Browse the repository at this point in the history
)

Signed-off-by: Andre Dietisheim <[email protected]>
  • Loading branch information
adietish committed May 6, 2024
1 parent 370056c commit e90fc66
Show file tree
Hide file tree
Showing 14 changed files with 115 additions and 74 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ dependencies {
'io.fabric8:openshift-client:6.12.0',
'org.apache.commons:commons-compress:1.26.1',
'org.apache.commons:commons-exec:1.4.0',
'com.redhat.devtools.intellij:intellij-common:1.9.5',
'com.redhat.devtools.intellij:intellij-common:1.9.6-SNAPSHOT',
'io.jsonwebtoken:jjwt-impl:0.12.5',
'io.jsonwebtoken:jjwt-jackson:0.12.5',
'org.keycloak:keycloak-installed-adapter:24.0.3',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void actionPerformed(AnActionEvent anActionEvent, TreePath path, Object s

protected Helm getHelm(AnActionEvent anActionEvent) {
try {
return ActionUtils.getApplicationRootNode(anActionEvent).getHelm(true).getNow(null);
return ActionUtils.getApplicationRootNode(anActionEvent).getHelm(true);
} catch (Exception e) {
LOGGER.warn("Could not get helm: " + e.getMessage(), e);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void actionPerformed(AnActionEvent anActionEvent, TreePath path, Object s

protected Odo getOdo(AnActionEvent anActionEvent) {
try {
return ActionUtils.getApplicationRootNode(anActionEvent).getOdo().getNow(null);
return ActionUtils.getApplicationRootNode(anActionEvent).getOdo();
} catch(Exception e) {
LOGGER.warn("Could not get odo: " + e.getMessage(), e);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static void execute(ParentableNode<?> node) {
if (node == null) {
return;
}
Odo odo = node.getRoot().getOdo().getNow(null);
Odo odo = node.getRoot().getOdo();
if (odo == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public boolean isVisible(Object selected) {
boolean visible = super.isVisible(selected);
if (visible) {
ComponentNode componentNode = (ComponentNode) selected;
Odo odo = componentNode.getRoot().getOdo().getNow(null);
Odo odo = componentNode.getRoot().getOdo();
if (odo == null) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void actionPerformedOnSelectedObject(AnActionEvent anActionEvent, Object
return;
}
ApplicationsRootNode rootNode = parentableNode.getRoot();
Odo odo = rootNode.getOdo().getNow(null);
Odo odo = rootNode.getOdo();
if (odo == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static void execute(ParentableNode<?> node) {
return;
}
ApplicationsRootNode rootNode = node.getRoot();
Odo odo = rootNode.getOdo().getNow(null);
Odo odo = rootNode.getOdo();
if (odo == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class CreateProjectAction extends LoggedInClusterAction {


public static void execute(ApplicationsRootNode rootNode) {
Odo odo = rootNode.getOdo().getNow(null);
Odo odo = rootNode.getOdo();
if (odo == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,18 @@
import com.redhat.devtools.intellij.common.utils.ConfigWatcher;
import com.redhat.devtools.intellij.common.utils.ExecHelper;
import io.fabric8.kubernetes.api.model.Config;
import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.function.BiConsumer;
import org.jboss.tools.intellij.openshift.actions.NotificationUtils;
import org.jboss.tools.intellij.openshift.utils.ProjectUtils;
import org.jboss.tools.intellij.openshift.utils.ToolFactory;
import org.jboss.tools.intellij.openshift.utils.ToolFactory.Tool;
import org.jboss.tools.intellij.openshift.utils.helm.Helm;
import org.jboss.tools.intellij.openshift.utils.odo.ComponentDescriptor;
import org.jboss.tools.intellij.openshift.utils.odo.Odo;
Expand All @@ -34,15 +43,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.function.BiConsumer;

public class ApplicationsRootNode
implements ModuleListener, ConfigWatcher.Listener, ProcessingNode, StructureAwareNode, ParentableNode<ApplicationsRootNode>, Disposable {

Expand All @@ -51,8 +51,8 @@ public class ApplicationsRootNode
private final ApplicationsTreeStructure structure;
private final ProcessingNodeImpl processingNode = new ProcessingNodeImpl();
private final Map<String, ComponentDescriptor> components = new HashMap<>();
private CompletableFuture<Odo> odoFuture;
private CompletableFuture<Helm> helmFuture;
private CompletableFuture<Tool<Odo>> odoFuture;
private CompletableFuture<Tool<Helm>> helmFuture;
private boolean logged;
private Config config;
private final OdoProcessHelper processHelper;
Expand Down Expand Up @@ -81,39 +81,58 @@ public void setLogged(boolean logged) {
this.logged = logged;
}

private CompletableFuture<Odo> getOdo(BiConsumer<Odo, Throwable> whenComplete) {
private CompletableFuture<Tool<Odo>> getOdoTool(BiConsumer<Tool<Odo>, Throwable> whenComplete) {
if (odoFuture == null) {
this.odoFuture = ToolFactory.getInstance()
.createOdo(project)
.thenApply(odo -> (Odo) new ApplicationRootNodeOdo(odo, this, processHelper))
.whenComplete((odo, err) -> loadProjectModel(odo, project))
.whenComplete((tool, err) -> new ApplicationRootNodeOdo(tool.get(), this, processHelper))
.whenComplete((tool, err) -> loadProjectModel(tool.get(), project))
.whenComplete(whenComplete);
}
return odoFuture;
}

public CompletableFuture<Odo> getOdo() {
return getOdo((odo, err) -> structure.fireModified(this));
public CompletableFuture<Tool<Odo>> getOdoTool() {
return getOdoTool((Tool<Odo> tool, Throwable err) -> {
if (tool.isDownloaded()) {
structure.fireModified(this);
}
});
}

public Odo getOdo() {
Tool<Odo> tool = getOdoTool().getNow(null);
if (tool == null) {
return null;
}
return tool.get();
}

public void resetOdo() {
this.odoFuture = null;
}

public CompletableFuture<Helm> getHelm(boolean notify) {
public CompletableFuture<ToolFactory.Tool<Helm>> getHelmTool(boolean notify) {
if (helmFuture == null) {
this.helmFuture = ToolFactory.getInstance()
.createHelm(project)
.whenComplete((odo, err) -> {
if (notify) {
.whenComplete((tool, err) -> {
if (notify && tool.isDownloaded()) {
structure.fireModified(this);
}
}
);
});
}
return helmFuture;
}

public Helm getHelm(boolean notify) {
Tool<Helm> tool = getHelmTool(notify).getNow(null);
if (tool == null) {
return null;
}
return tool.get();
}

public Project getProject() {
return project;
}
Expand Down Expand Up @@ -141,7 +160,7 @@ protected void loadProjectModel(Odo odo, Project project) {

@Override
public void moduleAdded(@NotNull Project project, @NotNull Module module) {
addContext(getOdo().getNow(null), ProjectUtils.getModuleRoot(module));
addContext(getOdo(), ProjectUtils.getModuleRoot(module));
}

@Override
Expand All @@ -159,10 +178,11 @@ private void addContextToSettings(String path, ComponentDescriptor descriptor) {
}

private void migrateOdo(ComponentDescriptor descriptor) {
getOdo()
.thenAccept(odo -> {
if (odo != null) {
odo.migrateComponent(descriptor.getName());
getOdoTool()
.thenAccept(tool -> {
if (tool != null
&& tool.get() != null) {
tool.get().migrateComponent(descriptor.getName());
}
})
.thenRun(() ->
Expand Down Expand Up @@ -192,7 +212,7 @@ private void addContext(Odo odo, VirtualFile modulePathFile) {

public void addContext(String modulePath) {
addContext(
getOdo().getNow(null),
getOdo(),
LocalFileSystem.getInstance().refreshAndFindFileByPath(modulePath));
}

Expand Down Expand Up @@ -228,7 +248,7 @@ public void onUpdate(ConfigWatcher source, Config config) {

public synchronized void refresh() {
resetOdo();
getOdo((odo, err) -> structure.fireModified(ApplicationsRootNode.this));
getOdoTool((odo, err) -> structure.fireModified(ApplicationsRootNode.this));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public Object getApplicationsRoot() {

@NotNull
private Object[] createComponentChildren(ComponentNode componentNode) {
Odo odo = root.getOdo().getNow(null);
Odo odo = root.getOdo();
if (odo == null) {
return new Object[]{new MessageNode<>(root, componentNode, "Could not get components")};
}
Expand All @@ -123,7 +123,7 @@ private Object[] createComponentChildren(ComponentNode componentNode) {

@NotNull
private Object[] createNamespaceChildren(@NotNull NamespaceNode namespaceNode) {
Odo odo = root.getOdo().getNow(null);
Odo odo = root.getOdo();
if (odo == null) {
return new MessageNode[]{new MessageNode<>(root, namespaceNode, "Could not get project children")};
}
Expand All @@ -143,7 +143,7 @@ private Object[] createNamespaceChildren(@NotNull NamespaceNode namespaceNode) {
private Object getCurrentNamespace(ApplicationsRootNode element) {
Object node;
try {
Odo odo = root.getOdo().getNow(null);
Odo odo = root.getOdo();
if (odo == null) {
return new Object[]{new MessageNode<>(element, element, "Could not get current namespace")};
}
Expand All @@ -167,7 +167,7 @@ private Object getCurrentNamespace(ApplicationsRootNode element) {
}

private Object[] createHelmRepositoriesChildren(HelmRepositoriesNode parent) {
Helm helm = root.getHelm(true).getNow(null);
Helm helm = root.getHelm(true);
if (helm == null) {
return new Object[] { new MessageNode<>(root, parent, "Could not list repositories: Helm binary missing.") };
}
Expand Down Expand Up @@ -226,7 +226,7 @@ private List<BaseNode<?>> getServices(NamespaceNode namespaceNode, Odo odo) {
}

private List<BaseNode<?>> getHelmReleases(NamespaceNode namespaceNode) {
Helm helm = namespaceNode.getRoot().getHelm(true).getNow(null);
Helm helm = namespaceNode.getRoot().getHelm(true);
if (helm == null) {
return List.of(new MessageNode<>(root, namespaceNode, "Could not get chart releases"));
}
Expand All @@ -248,7 +248,7 @@ private List<BaseNode<?>> load(Callable<List<BaseNode<?>>> callable, NamespaceNo

private List<URLNode> getURLs(ComponentNode element) {
List<URLNode> results = new ArrayList<>();
Odo odo = element.getRoot().getOdo().getNow(null);
Odo odo = element.getRoot().getOdo();
if (odo == null) {
return Collections.emptyList();
}
Expand Down Expand Up @@ -277,7 +277,7 @@ private List<BindingNode> getBindings(ComponentNode element, @NotNull Odo odo) {
}

private Object[] getRegistries(ApplicationsRootNode root) {
Odo odo = root.getOdo().getNow(null);
Odo odo = root.getOdo();
if (odo == null) {
return new Object[]{new MessageNode<>(root, root, "Could not get registries")};
}
Expand All @@ -293,7 +293,7 @@ private Object[] getRegistries(ApplicationsRootNode root) {
}

private Object[] getRegistryComponentTypes(DevfileRegistryNode registryNode) {
Odo odo = root.getOdo().getNow(null);
Odo odo = root.getOdo();
if (odo == null) {
return new Object[]{new MessageNode<>(root, registryNode, "Could not get registry component types")};
}
Expand All @@ -308,7 +308,7 @@ private Object[] getRegistryComponentTypes(DevfileRegistryNode registryNode) {
}

private Object[] getRegistryComponentTypeStarters(DevfileRegistryComponentTypeNode componentTypeNode) {
Odo odo = root.getOdo().getNow(null);
Odo odo = root.getOdo();
if (odo == null) {
return new Object[]{new MessageNode<>(root, componentTypeNode, "Could not get registry component starters")};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void execute() {
}

private static String getLabel(ApplicationsRootNode root) {
Odo odo = root.getOdo().getNow(null);
Odo odo = root.getOdo();
String label = "Missing %s, <a>choose or create a different one</a>";
if (odo == null) {
return String.format(label, "project/namespace");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class DescriptorFactory {
root,
() -> {
try {
Odo odo = root.getOdo().getNow(null);
Odo odo = root.getOdo();
if (odo == null) {
return "Loading...";
}
Expand Down
Loading

0 comments on commit e90fc66

Please sign in to comment.