sdedic commented on code in PR #7540:
URL: https://github.com/apache/netbeans/pull/7540#discussion_r1670556332


##########
enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/Steps.java:
##########
@@ -92,16 +60,20 @@ public static synchronized Steps getDefault() {
         return instance;
     }
 
-    public CompletableFuture<Object> executeMultistep(Step firstStep, Lookup 
lookup) {
+    public CompletableFuture<Values> executeMultistep(AbstractStep firstStep, 
Lookup lookup) {
         DialogDisplayer dd = DialogDisplayer.getDefault();
         CompletableFuture future = new CompletableFuture();
         RP.post(() -> {
-            Multistep multistep = new Multistep(firstStep, lookup);
-            NotifyDescriptor.ComposedInput ci = new 
NotifyDescriptor.ComposedInput(Bundle.AddSuggestedItem(), 3, 
multistep.createInput());
-            if (DialogDescriptor.OK_OPTION == dd.notify(ci)) {
-                future.complete(multistep.getResult());
-            } else {
-                future.cancel(true);
+            try {
+                Multistep multistep = new Multistep(firstStep, lookup);
+                NotifyDescriptor.ComposedInput ci = new 
NotifyDescriptor.ComposedInput(Bundle.AddSuggestedItem(), 3, 
multistep.createInput());
+                if (DialogDescriptor.OK_OPTION == dd.notify(ci)) {

Review Comment:
   I'd use `dd.notifyFuture(ci).handle()` or `.then*` so that  RP (throughput 
1) is not blocked.



##########
enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/actions/ConfigMapCommand.java:
##########
@@ -0,0 +1,385 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.netbeans.modules.cloud.oracle.actions;
+
+import com.oracle.bmc.devops.DevopsClient;
+import com.oracle.bmc.devops.model.DeployArtifactSource;
+import com.oracle.bmc.devops.model.DeployArtifactSummary;
+import com.oracle.bmc.devops.model.InlineDeployArtifactSource;
+import com.oracle.bmc.devops.model.UpdateDeployArtifactDetails;
+import com.oracle.bmc.devops.requests.GetDeployArtifactRequest;
+import com.oracle.bmc.devops.requests.ListDeployArtifactsRequest;
+import com.oracle.bmc.devops.requests.UpdateDeployArtifactRequest;
+import com.oracle.bmc.devops.responses.GetDeployArtifactResponse;
+import com.oracle.bmc.devops.responses.ListDeployArtifactsResponse;
+import com.oracle.bmc.model.BmcException;
+import com.oracle.bmc.vault.VaultsClient;
+import com.oracle.bmc.vault.model.Base64SecretContentDetails;
+import com.oracle.bmc.vault.model.CreateSecretDetails;
+import com.oracle.bmc.vault.model.SecretContentDetails;
+import com.oracle.bmc.vault.model.SecretReuseRule;
+import com.oracle.bmc.vault.model.UpdateSecretDetails;
+import com.oracle.bmc.vault.requests.CreateSecretRequest;
+import com.oracle.bmc.vault.requests.ListSecretsRequest;
+import com.oracle.bmc.vault.requests.UpdateSecretRequest;
+import com.oracle.bmc.vault.responses.ListSecretsResponse;
+import com.oracle.bmc.vault.responses.UpdateSecretResponse;
+import java.io.StringWriter;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import org.netbeans.modules.cloud.oracle.steps.DevopsStep;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.stream.Collectors;
+import org.netbeans.api.db.explorer.ConnectionManager;
+import org.netbeans.api.db.explorer.DatabaseConnection;
+import org.netbeans.api.progress.ProgressHandle;
+import org.netbeans.api.project.Project;
+import org.netbeans.modules.cloud.oracle.OCIManager;
+import static org.netbeans.modules.cloud.oracle.OCIManager.getDefault;
+import org.netbeans.modules.cloud.oracle.assets.CloudAssets;
+import org.netbeans.modules.cloud.oracle.assets.DependencyUtils;
+import org.netbeans.modules.cloud.oracle.assets.PropertiesGenerator;
+import org.netbeans.modules.cloud.oracle.assets.Steps;
+import org.netbeans.modules.cloud.oracle.database.DatabaseItem;
+import org.netbeans.modules.cloud.oracle.devops.DevopsProjectItem;
+import org.netbeans.modules.cloud.oracle.steps.DatasourceNameStep;
+import org.netbeans.modules.cloud.oracle.steps.KeyStep;
+import org.netbeans.modules.cloud.oracle.steps.OverwriteStep;
+import org.netbeans.modules.cloud.oracle.steps.PasswordStep;
+import org.netbeans.modules.cloud.oracle.steps.ProjectStep;
+import org.netbeans.modules.cloud.oracle.items.OCIItem;
+import org.netbeans.modules.cloud.oracle.steps.CompartmentStep;
+import org.netbeans.modules.cloud.oracle.steps.TenancyStep;
+import org.netbeans.modules.cloud.oracle.vault.KeyItem;
+import org.netbeans.modules.cloud.oracle.vault.VaultItem;
+import org.netbeans.spi.lsp.CommandProvider;
+import org.openide.DialogDisplayer;
+import org.openide.NotifyDescriptor;
+import org.openide.util.Lookup;
+import org.openide.util.NbBundle;
+import org.openide.util.lookup.Lookups;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ * Command that updates a ConfigMap with the current properties generated from 
the contents of {@link CloudAssets}.
+ * 
+ * @author Jan Horvath
+ */
[email protected]({
+    "SuggestVault=For better security when using Autonomous Database, be sure 
to also add OCI Vault.",
+    "UpdatingConfigMap=Updating Config Map",
+    "CMUpdated=ConfigMap in \"{0}\" project was updated"
+})
+@ServiceProvider(service = CommandProvider.class)
+public class ConfigMapCommand implements CommandProvider {
+
+    private static final Logger LOG = 
Logger.getLogger(ConfigMapCommand.class.getName());
+
+    private static final String COMMAND_UPLOAD_TO_CONFIGMAP = 
"nbls.cloud.assets.configmap.upload"; //NOI18N
+
+    private static final Set COMMANDS = new HashSet<>(Arrays.asList(
+            COMMAND_UPLOAD_TO_CONFIGMAP
+    ));
+
+    @Override
+    public Set<String> getCommands() {
+        return Collections.unmodifiableSet(COMMANDS);
+    }
+
+    @Override
+    public CompletableFuture<Object> runCommand(String command, List<Object> 
arguments) {
+        Steps.NextStepProvider.Builder nsProviderBuilder = 
Steps.NextStepProvider.builder();
+        CompletableFuture future = new CompletableFuture();
+        
+        nsProviderBuilder.stepForClass(TenancyStep.class, (s) -> new 
CompartmentStep())
+            .stepForClass(CompartmentStep.class, (s) -> new DevopsStep())
+            .stepForClass(DevopsStep.class, (s) -> new ProjectStep());
+        
+        Collection<OCIItem> items = 
CloudAssets.getDefault().getAssignedItems();
+        AtomicReference<VaultItem> vaultRef = new AtomicReference<>();
+        AtomicReference<DatabaseItem> dbRef = new AtomicReference<>();
+        for (OCIItem item : items) {
+            if (item instanceof VaultItem) {
+                vaultRef.set((VaultItem) item);
+                nsProviderBuilder.stepForClass(OverwriteStep.class, (s) -> new 
KeyStep(vaultRef.get()));
+            } else if (item instanceof DatabaseItem) {
+                dbRef.set((DatabaseItem) item);
+                DatabaseConnection conn = null;
+                DatabaseConnection[] connections = 
ConnectionManager.getDefault().getConnections();
+                for (int i = 0; i < connections.length; i++) {
+                    if (item.getKey().getValue().equals(
+                            
connections[i].getConnectionProperties().get("OCID"))) { //NOI18N
+                        conn = connections[i];
+                        break;
+                    }
+                }
+                String user, password;
+                if (conn != null) {
+                    user = conn.getUser();
+                    password = conn.getPassword();
+                } else {
+                    user = null;
+                    password = null;
+                }
+                nsProviderBuilder.stepForClass(ProjectStep.class, (s) -> new 
PasswordStep(user, password))
+                    .stepForClass(PasswordStep.class, (s) -> new 
DatasourceNameStep())
+                    .stepForClass(DatasourceNameStep.class, (s) -> new 
OverwriteStep());
+            }
+        }
+        
+        if (vaultRef.get() == null && dbRef.get() != null) {
+            NotifyDescriptor.Message msg = new 
NotifyDescriptor.Message(Bundle.SuggestVault(), 
NotifyDescriptor.INFORMATION_MESSAGE);
+            DialogDisplayer.getDefault().notifyLater(msg);
+        }
+        
+        Lookup lookup = Lookups.fixed(nsProviderBuilder.build());
+        Steps.getDefault()
+            .executeMultistep(new TenancyStep(), lookup)
+            .thenAccept(values -> {
+                Project project = values.getValueForStep(ProjectStep.class);
+                KeyItem key = values.getValueForStep(KeyStep.class);
+                DevopsProjectItem devopsProject = 
values.getValueForStep(DevopsStep.class);
+                String datasourceName = 
values.getValueForStep(DatasourceNameStep.class);
+                
+                if (dbRef.get() != null) {
+                    CloudAssets.getDefault().setReferenceName(dbRef.get(), 
datasourceName);
+                }
+
+                ProgressHandle h = 
ProgressHandle.createHandle(Bundle.UpdatingConfigMap());
+                try {
+                    PropertiesGenerator propGen = new 
PropertiesGenerator(false);
+                    if (vaultRef.get() != null) {
+                        updateVault(h, key, vaultRef.get(), propGen, project);
+                    }
+                    updateConfigMap(h, devopsProject, propGen, command);
+                    NotifyDescriptor.Message msg = new 
NotifyDescriptor.Message(Bundle.CMUpdated(devopsProject.getName()), 
NotifyDescriptor.INFORMATION_MESSAGE);
+                    DialogDisplayer.getDefault().notify(msg);

Review Comment:
   I recommend to use `notifyLater` here, since we do not need to wait on the 
dialog to complete. `notify` might block the LSP message thread.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to