20
20
import com .intellij .openapi .application .ApplicationManager ;
21
21
import com .intellij .openapi .util .text .Strings ;
22
22
import com .intellij .util .messages .MessageBus ;
23
- import com .intellij .util .messages .MessageBusConnection ;
24
23
import com .redhat .devtools .intellij .common .utils .ExecHelper ;
25
- import com .redhat .devtools .intellij .telemetry .core .configuration .TelemetryConfiguration ;
26
24
import io .fabric8 .kubernetes .api .Pluralize ;
27
25
import io .fabric8 .kubernetes .api .model .ConfigMap ;
28
26
import io .fabric8 .kubernetes .api .model .DeletionPropagation ;
38
36
import io .fabric8 .openshift .client .OpenShiftClient ;
39
37
import io .fabric8 .openshift .client .dsl .OpenShiftOperatorHubAPIGroupDSL ;
40
38
import io .fabric8 .openshift .client .impl .OpenShiftOperatorHubAPIGroupClient ;
41
- import org .apache .commons .io .FileUtils ;
42
- import org .jboss .tools .intellij .openshift .KubernetesLabels ;
43
- import org .jboss .tools .intellij .openshift .utils .Cli ;
44
- import org .jboss .tools .intellij .openshift .utils .KubernetesClientExceptionUtils ;
45
- import org .jboss .tools .intellij .openshift .utils .Serialization ;
46
- import org .jetbrains .annotations .NotNull ;
47
- import org .jetbrains .annotations .Nullable ;
48
- import org .slf4j .Logger ;
49
- import org .slf4j .LoggerFactory ;
50
-
51
39
import java .io .BufferedReader ;
52
40
import java .io .File ;
53
41
import java .io .IOException ;
60
48
import java .util .Map ;
61
49
import java .util .concurrent .CompletableFuture ;
62
50
import java .util .concurrent .ExecutionException ;
51
+ import java .util .concurrent .TimeUnit ;
52
+ import java .util .concurrent .TimeoutException ;
63
53
import java .util .concurrent .atomic .AtomicBoolean ;
64
54
import java .util .function .BinaryOperator ;
65
55
import java .util .function .Function ;
66
56
import java .util .function .Supplier ;
57
+ import org .apache .commons .io .FileUtils ;
58
+ import org .jboss .tools .intellij .openshift .KubernetesLabels ;
59
+ import org .jboss .tools .intellij .openshift .utils .Cli ;
60
+ import org .jboss .tools .intellij .openshift .utils .KubernetesClientExceptionUtils ;
61
+ import org .jboss .tools .intellij .openshift .utils .Serialization ;
62
+ import org .jetbrains .annotations .NotNull ;
63
+ import org .jetbrains .annotations .Nullable ;
64
+ import org .slf4j .Logger ;
65
+ import org .slf4j .LoggerFactory ;
67
66
68
67
import static io .fabric8 .openshift .client .OpenShiftClient .BASE_API_GROUP ;
69
68
import static org .jboss .tools .intellij .openshift .Constants .HOME_FOLDER ;
@@ -93,7 +92,7 @@ public class OdoCli extends Cli implements OdoDelegate {
93
92
private final AtomicBoolean swaggerLoaded = new AtomicBoolean ();
94
93
private String currentNamespace ;
95
94
private JSonParser swagger ;
96
- private final boolean isPodmanPresent ;
95
+ private CompletableFuture < Boolean > isPodmanPresent ;
97
96
98
97
public OdoCli (com .intellij .openapi .project .Project project , String command ) {
99
98
this (project ,
@@ -116,14 +115,16 @@ protected OdoCli(
116
115
super (kubernetesClientFactory );
117
116
this .command = command ;
118
117
this .project = project ;
119
- MessageBusConnection connection = bus .connect ();
120
118
this .openshiftClient = openshiftClientFactory .apply (client );
121
119
this .envVars = envVarFactory .apply (String .valueOf (client .getMasterUrl ()));
120
+ this .isPodmanPresent = processPodmanPresent (command );
121
+ initTelemetry (bus , telemetryReport );
122
+ }
123
+
124
+ private void initTelemetry (MessageBus bus , TelemetryReport telemetryReport ) {
122
125
telemetryReport .addTelemetryVars (envVars );
123
- connection .subscribe (TelemetryConfiguration .ConfigurationChangedListener .CONFIGURATION_CHANGED ,
124
- telemetryReport .onTelemetryConfigurationChanged (this .envVars ));
126
+ telemetryReport .subscribe (bus , envVars );
125
127
telemetryReport .report (client );
126
- isPodmanPresent = checkPodmanPresence ();
127
128
}
128
129
129
130
@@ -418,7 +419,7 @@ public ComponentInfo getComponentInfo(String project, String component, String p
418
419
419
420
private ComponentInfo parseComponentInfo (String json , ComponentKind kind ) throws IOException {
420
421
JSonParser parser = new JSonParser (Serialization .json ().readTree (json ));
421
- return parser .parseDescribeComponentInfo (kind , isPodmanPresent );
422
+ return parser .parseDescribeComponentInfo (kind , isPodmanPresent () );
422
423
}
423
424
424
425
/*
@@ -747,20 +748,33 @@ public List<DevfileComponentType> getComponentTypesFromRegistry(String name) thr
747
748
filter (type -> name .equals (type .getDevfileRegistry ().getName ())).toList ();
748
749
}
749
750
750
- private boolean checkPodmanPresence () {
751
- CompletableFuture <ExecHelper .ExecResult > result = new CompletableFuture <>();
751
+ private boolean isPodmanPresent () {
752
752
try {
753
- result .complete (ExecHelper .executeWithResult (command , false , new File (HOME_FOLDER ), envVars , "version" ));
754
- return !result .get ().getStdOut ().contains ("unable to fetch the podman client version" );
753
+ if (isPodmanPresent == null ) {
754
+ this .isPodmanPresent = processPodmanPresent (command );
755
+ }
756
+ return isPodmanPresent .get (2 , TimeUnit .SECONDS );
755
757
} catch (InterruptedException e ) {
756
758
Thread .currentThread ().interrupt ();
757
759
LOGGER .warn (e .getLocalizedMessage (), e );
758
- } catch (ExecutionException | IOException e ) {
760
+ } catch (ExecutionException | TimeoutException e ) {
759
761
LOGGER .warn (e .getLocalizedMessage (), e );
760
762
}
761
763
return false ;
762
764
}
763
765
766
+ private @ NotNull CompletableFuture <Boolean > processPodmanPresent (String command ) {
767
+ return CompletableFuture
768
+ .supplyAsync (() -> {
769
+ try {
770
+ ExecHelper .ExecResult result = ExecHelper .executeWithResult (command , false , new File (HOME_FOLDER ), envVars , "version" );
771
+ return result .getStdOut ().contains ("unable to fetch the podman client version" );
772
+ } catch (IOException e ) {
773
+ LOGGER .warn (e .getLocalizedMessage (), e );
774
+ return false ;
775
+ }
776
+ }, runnable -> ApplicationManager .getApplication ().executeOnPooledThread (runnable ));
777
+ }
764
778
765
779
private static final class OpenShiftClientFactory implements Function <KubernetesClient , OpenShiftClient > {
766
780
@ Override
0 commit comments