From e6195f7306d0c17ca71ab35ef4bf2d999cf0cb14 Mon Sep 17 00:00:00 2001 From: Jan Horvath Date: Fri, 15 Mar 2024 09:10:34 +0100 Subject: [PATCH] Introducing a action/command that allows for the direct switching of OCI Regions from within the IDE --- .../modules/cloud/oracle/OCINode.java | 4 +- .../modules/cloud/oracle/OCIProfile.java | 53 ++++++++- .../modules/cloud/oracle/TenancyInstance.java | 24 ++-- .../modules/cloud/oracle/TenancyNode.java | 28 ++++- .../cloud/oracle/actions/Bundle.properties | 2 + .../oracle/actions/DownloadWalletDialog.java | 1 - .../cloud/oracle/actions/SetRegionAction.java | 97 +++++++++++++++ .../oracle/actions/SetRegionCommand.java | 96 +++++++++++++++ .../cloud/oracle/actions/SetRegionDialog.form | 95 +++++++++++++++ .../cloud/oracle/actions/SetRegionDialog.java | 110 ++++++++++++++++++ .../cloud/oracle/database/DatabaseNode.java | 56 ++++----- .../cloud/oracle/devops/BuildRunNode.java | 9 +- .../oracle/devops/DeployArtifactNode.java | 6 +- .../oracle/devops/DevopsProjectNode.java | 7 +- .../cloud/oracle/devops/RepositoryNode.java | 6 +- .../cloud/oracle/vault/SecretNode.java | 6 +- .../modules/cloud/oracle/vault/VaultNode.java | 9 +- java/java.lsp.server/vscode/package.json | 4 + 18 files changed, 540 insertions(+), 73 deletions(-) create mode 100644 enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/actions/SetRegionAction.java create mode 100644 enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/actions/SetRegionCommand.java create mode 100644 enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/actions/SetRegionDialog.form create mode 100644 enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/actions/SetRegionDialog.java diff --git a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/OCINode.java b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/OCINode.java index 4d25183bac78..31300aa2130f 100644 --- a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/OCINode.java +++ b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/OCINode.java @@ -40,9 +40,9 @@ public class OCINode extends AbstractNode { private RefreshListener refreshListener; - private final OCIItem item; + final OCIItem item; private final CloudChildFactory factory; - private final OCISessionInitiator session; + final OCISessionInitiator session; public OCINode(OCIItem item) { this(new CloudChildFactory(item), item, OCIManager.getDefault().getActiveSession(), Lookups.fixed(item)); diff --git a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/OCIProfile.java b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/OCIProfile.java index 4abbbf8bff19..3fc80b3c0738 100644 --- a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/OCIProfile.java +++ b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/OCIProfile.java @@ -36,6 +36,8 @@ import com.oracle.bmc.identity.requests.GetTenancyRequest; import com.oracle.bmc.identity.responses.GetTenancyResponse; import com.oracle.bmc.model.BmcException; +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; import java.io.FileNotFoundException; import java.io.IOException; import java.lang.reflect.Method; @@ -46,13 +48,16 @@ import java.util.Optional; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.prefs.Preferences; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; +import static org.netbeans.modules.cloud.oracle.OCIManager.PROP_ACTIVE_PROFILE; import org.netbeans.modules.cloud.oracle.items.OCID; import org.netbeans.modules.cloud.oracle.items.OCIItem; import org.netbeans.modules.cloud.oracle.items.TenancyItem; import org.openide.util.Lookup; import org.openide.util.NbBundle; +import org.openide.util.NbPreferences; import org.openide.util.lookup.Lookups; /** @@ -65,6 +70,10 @@ public final class OCIProfile implements OCISessionInitiator { * ID of the default profile. */ public static final String DEFAULT_ID = "DEFAULT"; // NOI18N + /** + * name of preference for active region + */ + static final String PROP_ACTIVE_REGION_CODE = "activeRegionCode"; /** * Profile ID. */ @@ -81,6 +90,8 @@ public final class OCIProfile implements OCISessionInitiator { private IOException initError; private Tenancy tenancyOpt; private static final Logger LOG = Logger.getLogger(OCIProfile.class.getName()); + private Region region; + OCIProfile(Path configPath, String id) { this(configPath, id, true); @@ -115,6 +126,13 @@ private void init() { String stringPath = configPath.toAbsolutePath().toString(); ConfigFileReader.ConfigFile configFile = id == null ? ConfigFileReader.parse(stringPath) : ConfigFileReader.parse(stringPath, id); configProvider = new ConfigFileAuthenticationDetailsProvider(configFile); + Preferences prefs = NbPreferences.forModule(OCIProfile.class); + String regionCode = prefs.get(PROP_ACTIVE_REGION_CODE + "/" + id, null); + if (regionCode == null) { + region = configProvider.getRegion(); + } else { + region = Region.valueOf(regionCode); + } fileStamp = stamp; } catch (IOException ex) { LOG.log(Level.INFO, "init()", ex); @@ -136,6 +154,17 @@ public String getId() { public boolean isValid() { return configProvider != null && fileStamp == configPath.toFile().lastModified(); // avoid IOE } + + public void setRegionCode(String regionCode) { + setRegion(Region.valueOf(regionCode)); + } + + public void setRegion(Region region) { + Preferences prefs = NbPreferences.forModule(OCIProfile.class); + prefs.put(PROP_ACTIVE_REGION_CODE + "/" + id, region.getRegionCode()); + listeners.firePropertyChange(PROP_ACTIVE_REGION_CODE, this.region, region); + this.region = region; + } @Override public BasicAuthenticationDetailsProvider getAuthenticationProvider() { @@ -144,7 +173,7 @@ public BasicAuthenticationDetailsProvider getAuthenticationProvider() { @Override public Region getRegion() { - return configProvider.getRegion(); + return region; } @Override @@ -212,7 +241,7 @@ public T newClient(Class clientClass) { try { T client = clientClass.getConstructor(BasicAuthenticationDetailsProvider.class).newInstance(configProvider); Method setRegion = clientClass.getMethod("setRegion", Region.class); - setRegion.invoke(client, configProvider.getRegion()); + setRegion.invoke(client, getRegion()); return client; } catch (ReflectiveOperationException ex) { throw new IllegalArgumentException("Could not initialize client: " + clientClass); @@ -298,6 +327,26 @@ public Optional createAutonomousDatabase(String compartmentId, String db return Optional.empty(); } } + + private PropertyChangeSupport listeners; + + public void addPropertyChangeListener(PropertyChangeListener listener) { + synchronized (this) { + if (listeners == null) { + listeners = new PropertyChangeSupport(this); + } + listeners.addPropertyChangeListener(listener); + } + } + + public void removePropertyChangeListener(PropertyChangeListener listener) { + synchronized (this) { + if (listeners == null) { + return; + } + listeners.removePropertyChangeListener(listener); + } + } @Override public int hashCode() { diff --git a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/TenancyInstance.java b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/TenancyInstance.java index 50d05657e147..1a38223eed3d 100644 --- a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/TenancyInstance.java +++ b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/TenancyInstance.java @@ -30,6 +30,9 @@ * * @author Jan Horvath */ +@NbBundle.Messages({ + "MSG_BrokenProfile=Broken profile {0}" +}) public class TenancyInstance implements ServerInstanceImplementation, Lookup.Provider { private final OCIItem tenancy; @@ -41,28 +44,15 @@ public TenancyInstance(OCIItem tenancy, OCIProfile profile) { this.profile = profile; lkp = tenancy != null ? Lookups.fixed(profile, tenancy) : Lookups.fixed(profile); } - - @NbBundle.Messages({ - "# {0} - tenancy ID", - "# {1} - profile ID", - "MSG_TenancyDesc={0} ({1})", - "# {0} - tenancy ID", - "# {1} - profile ID", - "MSG_BrokenTenancy=Unavailable tenancy {0}", - "# {0} - profile ID", - "MSG_BrokenProfile=Broken profile {0}", - }) + @Override public String getDisplayName() { if (tenancy != null) { - return Bundle.MSG_TenancyDesc(tenancy.getName(), profile.getId()); - } else if (profile.getTenantId() != null) { - return Bundle.MSG_BrokenTenancy(profile.getTenantId(), profile.getId()); - } else { - return Bundle.MSG_BrokenProfile(profile.getId()); + return tenancy.getName(); } + return profile.getId(); } - + @Override public Lookup getLookup() { return lkp; diff --git a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/TenancyNode.java b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/TenancyNode.java index 5742b0581bfc..0acd976f752b 100644 --- a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/TenancyNode.java +++ b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/TenancyNode.java @@ -45,15 +45,41 @@ public TenancyNode(OCIItem tenancy, String disp, OCISessionInitiator session) { // home region will be set as a description setShortDescription(tenancy.getDescription()); OCIManager.getDefault().addPropertyChangeListener(WeakListeners.propertyChange(this, OCIManager.getDefault())); + if (session instanceof OCIProfile) { + ((OCIProfile) session).addPropertyChangeListener(this); + } } @Override public void propertyChange(PropertyChangeEvent e) { - if (OCIManager.PROP_ACTIVE_PROFILE.equals(e.getPropertyName())) { + if (OCIManager.PROP_ACTIVE_PROFILE.equals(e.getPropertyName()) || + OCIProfile.PROP_ACTIVE_REGION_CODE.equals(e.getPropertyName()) ) { fireDisplayNameChange(null, null); } } + @NbBundle.Messages({ + "# {0} - tenancy ID", + "# {1} - profile ID", + "MSG_TenancyDesc={0} (profile: {1}, region: {2})", + "# {0} - tenancy ID", + "# {1} - profile ID", + "MSG_BrokenTenancy=Unavailable tenancy {0}", + "# {0} - profile ID", + "MSG_BrokenProfileNode=Broken profile {0}", + }) + @Override + public String getDisplayName() { + OCIProfile profile = (OCIProfile) session; + if (item != null) { + return Bundle.MSG_TenancyDesc(item.getName(), profile.getId(), profile.getRegion()); + } else if (profile.getTenantId() != null) { + return Bundle.MSG_BrokenTenancy(profile.getTenantId(), profile.getId()); + } else { + return Bundle.MSG_BrokenProfileNode(profile.getId()); + } + } + @NbBundle.Messages({ "HTML_EmphasizeName={0}" }) diff --git a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/actions/Bundle.properties b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/actions/Bundle.properties index 9a9166bac79f..c6220cea3f56 100644 --- a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/actions/Bundle.properties +++ b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/actions/Bundle.properties @@ -33,3 +33,5 @@ DownloadWalletDialog.dbUserLabel.text=DB Username: DownloadWalletDialog.dbPasswordLabel.text=DB Password: DownloadWalletDialog.addDBCheckbox.toolltip=In addition to downloading Wallet, it also adds this database connection to the database manager. DownloadWalletDialog.addDBCheckbox.text=Add As Database Connection +SetRegionDialog.jLabel1.text=Region: +SetRegionDialog.text=Please choose an Oracle Cloud Region from the list below. Your selected region will be the default for all future requests. diff --git a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/actions/DownloadWalletDialog.java b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/actions/DownloadWalletDialog.java index 65602dbd146e..d477ed25e607 100644 --- a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/actions/DownloadWalletDialog.java +++ b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/actions/DownloadWalletDialog.java @@ -23,7 +23,6 @@ import java.awt.GraphicsEnvironment; import java.io.File; import java.io.IOException; -import java.util.Arrays; import java.util.Locale; import java.util.Optional; import javax.swing.JFileChooser; diff --git a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/actions/SetRegionAction.java b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/actions/SetRegionAction.java new file mode 100644 index 000000000000..ad493fd3f120 --- /dev/null +++ b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/actions/SetRegionAction.java @@ -0,0 +1,97 @@ +/* + * 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.identity.Identity; +import com.oracle.bmc.identity.IdentityClient; +import com.oracle.bmc.identity.requests.ListRegionsRequest; +import com.oracle.bmc.identity.responses.ListRegionsResponse; +import java.awt.Dialog; +import java.awt.GraphicsEnvironment; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.List; +import java.util.stream.Collectors; +import org.netbeans.modules.cloud.oracle.OCIManager; +import org.netbeans.modules.cloud.oracle.OCIProfile; +import org.netbeans.modules.cloud.oracle.OCISessionInitiator; +import org.openide.DialogDescriptor; +import org.openide.DialogDisplayer; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionReferences; +import org.openide.awt.ActionRegistration; +import org.openide.util.NbBundle; + +/** + * This action lets user select an Oracle Cloud region. This region will be used for all subsequent requests. + * + * @author Jan Horvath + */ +@ActionID( + category = "Tools", + id = "org.netbeans.modules.cloud.oracle.actions.SetDefaultRegionAction" +) +@ActionRegistration( + displayName = "#SetDefaultRegion", + asynchronous = true +) +@ActionReferences(value = { + @ActionReference(path = "Cloud/Oracle/Tenancy/Actions", position = 250) +}) +@NbBundle.Messages({ + "SetDefaultRegion=Set OCI Region", + "SelectRegion=Select a Region" +}) +public class SetRegionAction implements ActionListener { + + private final OCIProfile context; + + public SetRegionAction(OCIProfile context) { + this.context = context; + } + + @Override + public void actionPerformed(ActionEvent e) { + OCISessionInitiator session = OCIManager.getDefault().getActiveSession(); + Identity identityClient = IdentityClient.builder().build(session.getAuthenticationProvider()); + ListRegionsRequest request = ListRegionsRequest.builder().build(); + + ListRegionsResponse response = identityClient.listRegions(request); + + List items = response.getItems().stream() + .map(region -> region.getName()) + .sorted((r1, r2) -> r1.compareTo(r2)) + .collect(Collectors.toList()); + + if (!GraphicsEnvironment.isHeadless()) { + SetRegionDialog dlgPanel = new SetRegionDialog(items); + DialogDescriptor descriptor = new DialogDescriptor(dlgPanel, Bundle.SelectRegion()); //NOI18N + Dialog dialog = DialogDisplayer.getDefault().createDialog(descriptor); + dialog.setMinimumSize(dlgPanel.getPreferredSize()); + dialog.setVisible(true); + if (DialogDescriptor.OK_OPTION == descriptor.getValue()) { + String selectedCode = dlgPanel.getSelectedRegion(); + context.setRegionCode(selectedCode); + } + } + + } + +} diff --git a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/actions/SetRegionCommand.java b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/actions/SetRegionCommand.java new file mode 100644 index 000000000000..08a9884b6b43 --- /dev/null +++ b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/actions/SetRegionCommand.java @@ -0,0 +1,96 @@ +/* + * 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.identity.Identity; +import com.oracle.bmc.identity.IdentityClient; +import com.oracle.bmc.identity.model.Region; +import com.oracle.bmc.identity.requests.ListRegionsRequest; +import com.oracle.bmc.identity.responses.ListRegionsResponse; +import java.util.HashSet; +import java.util.List; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.CompletableFuture; +import java.util.stream.Collectors; +import org.netbeans.modules.cloud.oracle.OCIManager; +import org.netbeans.modules.cloud.oracle.OCIProfile; +import org.netbeans.spi.lsp.CommandProvider; +import org.openide.DialogDisplayer; +import org.openide.NotifyDescriptor; +import org.openide.util.lookup.ServiceProvider; + +/** + * This command lets user select an Oracle Cloud region. This region will be used for all subsequent requests. + * + * @author Jan Horvath + */ +@ServiceProvider(service = CommandProvider.class) +public class SetRegionCommand implements CommandProvider { + + private static final String SET_REGION_COMMAND = "nbls.oci.setRegion"; //NOI18N + private static final String GET_REGION_COMMAND = "nbls.oci.getRegion"; //NOI18N + + private static Set commands = new HashSet(){{ + add(SET_REGION_COMMAND); + add(GET_REGION_COMMAND); + }}; + + @Override + public Set getCommands() { + return commands; + } + + @Override + public CompletableFuture runCommand(String command, List arguments) { + CompletableFuture result = new CompletableFuture(); + if (GET_REGION_COMMAND.equals(command)) { + result.complete(OCIManager.getDefault().getActiveSession().getRegion().getRegionCode()); + return result; + } + if (SET_REGION_COMMAND.equals(command)) { + OCIProfile session = (OCIProfile) OCIManager.getDefault().getActiveSession(); + Identity identityClient = session.newClient(IdentityClient.class); + ListRegionsRequest request = ListRegionsRequest.builder().build(); + + ListRegionsResponse response + = identityClient.listRegions(request); + List regions = response.getItems(); + List items = regions.stream() + .map(region -> new NotifyDescriptor.QuickPick.Item(region.getName(), region.getKey())) + .sorted((r1, r2) -> r1.getLabel().compareTo(r2.getLabel())) + .collect(Collectors.toList()); + + DialogDisplayer.getDefault().notifyFuture(new NotifyDescriptor.QuickPick(Bundle.SelectRegion(), Bundle.SelectRegion(), items, false)) + .thenAccept(input -> { + Optional selected = input.getItems().stream().filter(i -> i.isSelected()).findFirst(); + if (selected.isPresent()) { + String selectedRegionCode = selected.get().getLabel(); + session.setRegionCode(selectedRegionCode); + result.complete(selectedRegionCode); + } + }); + } + if (!result.isDone()) { + result.complete(null); + } + return result; + } + +} diff --git a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/actions/SetRegionDialog.form b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/actions/SetRegionDialog.form new file mode 100644 index 000000000000..c696336e7eee --- /dev/null +++ b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/actions/SetRegionDialog.form @@ -0,0 +1,95 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/actions/SetRegionDialog.java b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/actions/SetRegionDialog.java new file mode 100644 index 000000000000..241d06e17645 --- /dev/null +++ b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/actions/SetRegionDialog.java @@ -0,0 +1,110 @@ +/* + * 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 java.util.List; +import javax.swing.ComboBoxModel; +import javax.swing.DefaultComboBoxModel; + +/** + * Oracle Cloud region selection dialog. + * + * @author Jan Horvath + */ +public class SetRegionDialog extends javax.swing.JPanel { + ComboBoxModel model; + + /** + * Creates new form SetRegionDialog + */ + public SetRegionDialog(List regions) { + model = new DefaultComboBoxModel(regions.toArray()); + initComponents(); + } + + String getSelectedRegion() { + return (String) jComboBox1.getSelectedItem(); + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + jLabel1 = new javax.swing.JLabel(); + jComboBox1 = new javax.swing.JComboBox<>(); + jTextArea1 = new javax.swing.JTextArea(); + + setMinimumSize(new java.awt.Dimension(427, 101)); + + org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(SetRegionDialog.class, "SetRegionDialog.jLabel1.text")); // NOI18N + + jComboBox1.setModel(model); + + jTextArea1.setEditable(false); + jTextArea1.setColumns(20); + jTextArea1.setLineWrap(true); + jTextArea1.setRows(5); + jTextArea1.setText(org.openide.util.NbBundle.getMessage(SetRegionDialog.class, "SetRegionDialog.text")); // NOI18N + jTextArea1.setWrapStyleWord(true); + jTextArea1.setAutoscrolls(false); + jTextArea1.setFocusTraversalKeysEnabled(false); + jTextArea1.setFocusable(false); + jTextArea1.setMargin(new java.awt.Insets(0, 0, 0, 0)); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 351, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addComponent(jTextArea1, javax.swing.GroupLayout.PREFERRED_SIZE, 415, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addContainerGap() + .addComponent(jTextArea1, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel1) + .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + + jTextArea1.getAccessibleContext().setAccessibleParent(this); + }// //GEN-END:initComponents + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JComboBox jComboBox1; + private javax.swing.JLabel jLabel1; + private javax.swing.JTextArea jTextArea1; + // End of variables declaration//GEN-END:variables +} diff --git a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/database/DatabaseNode.java b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/database/DatabaseNode.java index c3ee9ad84b42..a2cf821ba3a9 100644 --- a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/database/DatabaseNode.java +++ b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/database/DatabaseNode.java @@ -25,7 +25,6 @@ import java.util.stream.Collectors; import org.netbeans.modules.cloud.oracle.ChildrenProvider; import org.netbeans.modules.cloud.oracle.NodeProvider; -import static org.netbeans.modules.cloud.oracle.OCIManager.getDefault; import org.netbeans.modules.cloud.oracle.OCINode; import org.netbeans.modules.cloud.oracle.compartment.CompartmentItem; import org.netbeans.modules.cloud.oracle.items.OCID; @@ -65,33 +64,34 @@ public static NodeProvider createNode() { * @return List of {@code OCIItem} describing databases in a given * Compartment */ - public static ChildrenProvider getDatabases() { - return compartmentId -> { - DatabaseClient client = new DatabaseClient(getDefault().getConfigProvider()); - ListAutonomousDatabasesRequest listAutonomousDatabasesRequest = ListAutonomousDatabasesRequest.builder() - .compartmentId(compartmentId.getKey().getValue()) - .limit(88) - .build(); - - - return client.listAutonomousDatabases(listAutonomousDatabasesRequest) - .getItems() - .stream() - .map(d -> { - List profiles = d.getConnectionStrings().getProfiles(); - DatabaseItem item = new DatabaseItem( - OCID.of(d.getId(), "Databases"), //NOI18N - d.getDbName(), - d.getConnectionUrls().getOrdsUrl()+SERVICE_CONSOLE_SUFFIX, - getConnectionName(profiles)); - StringBuilder sb = new StringBuilder(); - sb.append(Bundle.LBL_WorkloadType(d.getDbWorkload().getValue())); - sb.append(Bundle.LBL_DatabaseVersion(d.getDbVersion())); - sb.append(Bundle.LBL_Storage(d.getDataStorageSizeInTBs())); - item.setDescription(sb.toString()); - return item; - }) - .collect(Collectors.toList()); + public static ChildrenProvider.SessionAware getDatabases() { + return (compartmentId, session) -> { + try(DatabaseClient client = session.newClient(DatabaseClient.class)) { + ListAutonomousDatabasesRequest listAutonomousDatabasesRequest = ListAutonomousDatabasesRequest.builder() + .compartmentId(compartmentId.getKey().getValue()) + .limit(88) + .build(); + + + return client.listAutonomousDatabases(listAutonomousDatabasesRequest) + .getItems() + .stream() + .map(d -> { + List profiles = d.getConnectionStrings().getProfiles(); + DatabaseItem item = new DatabaseItem( + OCID.of(d.getId(), "Databases"), //NOI18N + d.getDbName(), + d.getConnectionUrls().getOrdsUrl()+SERVICE_CONSOLE_SUFFIX, + getConnectionName(profiles)); + StringBuilder sb = new StringBuilder(); + sb.append(Bundle.LBL_WorkloadType(d.getDbWorkload().getValue())); + sb.append(Bundle.LBL_DatabaseVersion(d.getDbVersion())); + sb.append(Bundle.LBL_Storage(d.getDataStorageSizeInTBs())); + item.setDescription(sb.toString()); + return item; + }) + .collect(Collectors.toList()); + } }; } diff --git a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/devops/BuildRunNode.java b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/devops/BuildRunNode.java index 24aae54f626e..a3e706ecf696 100644 --- a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/devops/BuildRunNode.java +++ b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/devops/BuildRunNode.java @@ -27,7 +27,6 @@ import java.util.stream.Collectors; import org.netbeans.modules.cloud.oracle.ChildrenProvider; import org.netbeans.modules.cloud.oracle.NodeProvider; -import org.netbeans.modules.cloud.oracle.OCIManager; import org.netbeans.modules.cloud.oracle.OCINode; import org.netbeans.modules.cloud.oracle.items.OCID; import org.openide.nodes.Children; @@ -69,9 +68,9 @@ public static ChildrenProvider listBuildR ); } - public static ChildrenProvider expandBuildRuns() { - return project -> { - try ( DevopsClient client = new DevopsClient(OCIManager.getDefault().getConfigProvider())) { + public static ChildrenProvider.SessionAware expandBuildRuns() { + return (project, session) -> { + try (DevopsClient client = session.newClient(DevopsClient.class)) { ListBuildRunsRequest request = ListBuildRunsRequest.builder() .projectId(project.getKey().getValue()) .sortBy(ListBuildRunsRequest.SortBy.TimeCreated) @@ -81,7 +80,7 @@ public static ChildrenProvider expandBuildRuns List projects = response.getBuildRunSummaryCollection().getItems(); return projects.stream() .map(p -> new BuildRunItem( - OCID.of(p.getId(), "BuildRun"), + OCID.of(p.getId(), "BuildRun"), // NOI18N p.getDisplayName(), p.getLifecycleState().getValue() )) diff --git a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/devops/DeployArtifactNode.java b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/devops/DeployArtifactNode.java index 0da6a6ea5a8d..089e6dec24a5 100644 --- a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/devops/DeployArtifactNode.java +++ b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/devops/DeployArtifactNode.java @@ -53,9 +53,9 @@ public static NodeProvider createNode() { return DeployArtifactNode::new; } - public static ChildrenProvider listDeployArtifacts() { - return project -> { - try ( DevopsClient client = new DevopsClient(OCIManager.getDefault().getConfigProvider())) { + public static ChildrenProvider.SessionAware listDeployArtifacts() { + return (project, session) -> { + try ( DevopsClient client = session.newClient(DevopsClient.class)) { ListDeployArtifactsRequest request = ListDeployArtifactsRequest.builder() .projectId(project.getKey().getValue()).build(); ListDeployArtifactsResponse response = client.listDeployArtifacts(request); diff --git a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/devops/DevopsProjectNode.java b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/devops/DevopsProjectNode.java index 5bdea3dfca2c..24a83d561315 100644 --- a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/devops/DevopsProjectNode.java +++ b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/devops/DevopsProjectNode.java @@ -54,11 +54,10 @@ public static NodeProvider createNode() { return DevopsProjectNode::new; } - public static ChildrenProvider listDevopsProjects() { - return compartmentId -> { + public static ChildrenProvider.SessionAware listDevopsProjects() { + return (compartmentId, session) -> { try ( - DevopsClient client = new DevopsClient(OCIManager.getDefault().getConfigProvider()); - ) { + DevopsClient client = session.newClient(DevopsClient.class)) { ListProjectsRequest request = ListProjectsRequest.builder().compartmentId(compartmentId.getKey().getValue()).build(); ListProjectsResponse response = client.listProjects(request); diff --git a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/devops/RepositoryNode.java b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/devops/RepositoryNode.java index f53c59a4b22d..ba56fd04c724 100644 --- a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/devops/RepositoryNode.java +++ b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/devops/RepositoryNode.java @@ -54,9 +54,9 @@ public static NodeProvider createNode() { return RepositoryNode::new; } - public static ChildrenProvider listRepositories() { - return project -> { - try ( DevopsClient client = new DevopsClient(OCIManager.getDefault().getConfigProvider())) { + public static ChildrenProvider.SessionAware listRepositories() { + return (project, session) -> { + try ( DevopsClient client = session.newClient(DevopsClient.class)) { ListRepositoriesRequest listRepositoriesRequest = ListRepositoriesRequest.builder() .projectId(project.getKey().getValue()).build(); ListRepositoriesResponse response = client.listRepositories(listRepositoriesRequest); diff --git a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/vault/SecretNode.java b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/vault/SecretNode.java index e679f385b584..52e26a20376f 100644 --- a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/vault/SecretNode.java +++ b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/vault/SecretNode.java @@ -52,9 +52,9 @@ public static NodeProvider createNode() { * * @@return Returns {@code ChildrenProvider} which fetches List of {@code SecretItem} for given {@code VaultItem} */ - public static ChildrenProvider getSecrets() { - return vault -> { - VaultsClient client = VaultsClient.builder().build(getDefault().getActiveProfile().getConfigProvider()); + public static ChildrenProvider.SessionAware getSecrets() { + return (vault, session) -> { + VaultsClient client = session.newClient(VaultsClient.class); ListSecretsRequest listSecretsRequest = ListSecretsRequest.builder() .compartmentId(vault.getCompartmentId()) diff --git a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/vault/VaultNode.java b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/vault/VaultNode.java index 9d26a4e15e72..b32d03898621 100644 --- a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/vault/VaultNode.java +++ b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/vault/VaultNode.java @@ -19,11 +19,11 @@ package org.netbeans.modules.cloud.oracle.vault; import com.oracle.bmc.keymanagement.KmsVaultClient; +import com.oracle.bmc.keymanagement.model.VaultSummary; import com.oracle.bmc.keymanagement.requests.ListVaultsRequest; import java.util.stream.Collectors; import org.netbeans.modules.cloud.oracle.ChildrenProvider; import org.netbeans.modules.cloud.oracle.NodeProvider; -import org.netbeans.modules.cloud.oracle.OCIManager; import org.netbeans.modules.cloud.oracle.OCINode; import org.netbeans.modules.cloud.oracle.compartment.CompartmentItem; import org.netbeans.modules.cloud.oracle.items.OCID; @@ -55,9 +55,9 @@ public static NodeProvider createNode() { * * @return Returns {@code ChildrenProvider} which fetches List of {@code VaultItem} for given {@code CompartmentItem} */ - public static ChildrenProvider getVaults() { - return compartmentId -> { - KmsVaultClient client = KmsVaultClient.builder().build(OCIManager.getDefault().getActiveProfile().getConfigProvider()); + public static ChildrenProvider.SessionAware getVaults() { + return (compartmentId, session) -> { + KmsVaultClient client = session.newClient(KmsVaultClient.class); ListVaultsRequest listVaultsRequest = ListVaultsRequest.builder() .compartmentId(compartmentId.getKey().getValue()) @@ -67,6 +67,7 @@ public static ChildrenProvider getVaults() { return client.listVaults(listVaultsRequest) .getItems() .stream() + .filter(v -> v.getLifecycleState().equals(VaultSummary.LifecycleState.Active)) .map(d -> new VaultItem( OCID.of(d.getId(), "Vault"), //NOI18N d.getDisplayName(), diff --git a/java/java.lsp.server/vscode/package.json b/java/java.lsp.server/vscode/package.json index a366f4c00879..f15656b1cf0e 100644 --- a/java/java.lsp.server/vscode/package.json +++ b/java/java.lsp.server/vscode/package.json @@ -514,6 +514,10 @@ "command": "nbls.db.add.connection", "title": "Add JDBC Database Connection" }, + { + "command": "nbls.oci.setRegion", + "title": "Set Oracle Cloud Region" + }, { "command": "nbls:Database:netbeans.db.explorer.action.Connect", "title": "Connect to Database"