Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync delivery to release240 for 24-rc3 #7956

Merged
merged 8 commits into from
Nov 13, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.netbeans.api.project.ProjectInformation;
import org.netbeans.api.project.ProjectUtils;
import static org.netbeans.modules.cloud.oracle.NotificationUtils.showMessage;
import org.netbeans.modules.cloud.oracle.assets.CloudAssets;
import org.netbeans.modules.cloud.oracle.assets.ConfigMapProvider;
import org.netbeans.modules.cloud.oracle.assets.Steps;
import org.netbeans.modules.cloud.oracle.compute.ClusterItem;
Expand All @@ -40,22 +41,25 @@
* @author Dusan Petrovic
*/
@NbBundle.Messages({
"SuggestRerun=The changes will take place only after restarting the application"
"SuggestRerun=The changes will take place only after restarting the application",
"ClusterNotPresent=Please add the OKE Cluster first"
})
public class ConfigMapUploader {


public static void uploadConfigMap(CompletableFuture<Object> future) {
ClusterItem cluster = CloudAssets.getDefault().getItem(ClusterItem.class);
if (cluster == null) {
showMessage(Bundle.ClusterNotPresent());
return;
}
Steps.NextStepProvider nsProvider = Steps.NextStepProvider.builder()
.stepForClass(ProjectStep.class, (s) -> new TenancyStep())
.stepForClass(TenancyStep.class, (s) -> new CompartmentStep())
.stepForClass(CompartmentStep.class, (s) -> new SuggestedStep("Cluster"))
.build();
Lookup lookup = Lookups.fixed(nsProvider);
Steps.getDefault().executeMultistep(new ProjectStep(), lookup)
.thenAccept(values -> {
Project project = values.getValueForStep(ProjectStep.class);
ClusterItem cluster = (ClusterItem) values.getValueForStep(SuggestedStep.class);
ProjectInformation projectInfo = ProjectUtils.getInformation(project);
ConfigMapProvider configMapProvider = new ConfigMapProvider(projectInfo.getDisplayName(), cluster);
configMapProvider.createConfigMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,28 @@ public static synchronized CloudAssets getDefault() {
return instance;
}

public synchronized void addItem(OCIItem newItem) {
public synchronized boolean addItem(OCIItem newItem) {
Parameters.notNull("newItem cannot be null", newItem);
long presentCount = items.stream()
.filter(i -> i.getKey().getPath().equals(newItem.getKey().getPath()))
.count();
if (newItem.maxInProject() > presentCount && isTenancyCompatible(newItem, true)) {
if (newItem instanceof Validator) {
Validator.Result result = ((Validator) newItem).validate();
if (result.status == Validator.ValidationStatus.WARNING) {
showWarningMessage(result.message);
}
if (result.status == Validator.ValidationStatus.ERROR) {
showWarningMessage(result.message);
return false;
}
}
items.add(newItem);
newItem.addChangeListener(itemsListener);
update();
storeAssets();
}
return true;
}

synchronized void removeItem(OCIItem item) {
Expand Down Expand Up @@ -184,7 +195,7 @@ public synchronized boolean isTenancyCompatible(OCIItem toCheck) {
}

public synchronized boolean isTenancyCompatible(OCIItem toCheck, boolean showWarning) {
List<OCIItem> itemsMissingInfo = new ArrayList();
List<OCIItem> itemsMissingInfo = new ArrayList<> ();
for(OCIItem item: items) {
if (item != null && item.getTenancyId() == null) {
itemsMissingInfo.add(item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class CreateConfigCommand implements CommandProvider {
private static final String COMMAND_UPLOAD_TO_CONFIGMAP_WITHIN_DEVOPS = "nbls.cloud.assets.configmap.devops.upload"; //NOI18N
private static final String COMMAND_UPLOAD_TO_CONFIGMAP = "nbls.cloud.assets.configmap.upload"; //NOI18N

private static final Set COMMANDS = new HashSet<>(Arrays.asList(
private static final Set<String> COMMANDS = new HashSet<>(Arrays.asList(
COMMAND_CREATE_CONFIG,
COMMAND_UPLOAD_TO_CONFIGMAP_WITHIN_DEVOPS,
COMMAND_UPLOAD_TO_CONFIGMAP
Expand All @@ -53,7 +53,7 @@ public Set<String> getCommands() {

@Override
public CompletableFuture<Object> runCommand(String command, List<Object> arguments) {
CompletableFuture future = new CompletableFuture();
CompletableFuture<Object> future = new CompletableFuture<>();
if (COMMAND_CREATE_CONFIG.equals(command)) {
PropertiesGenerator propGen = new PropertiesGenerator(false);
ApplicationPropertiesGenerator appPropGen = new ApplicationPropertiesGenerator(propGen);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ public PropertiesGenerator(boolean local) {
}
if (vault != null) {
bootstrap.put("oci.vault.config.enabled", "true"); // NOI18N
bootstrap.put("micronaut.config-client.enabled", "true"); // NOI18N
bootstrap.put("oci.vault.vaults[0].ocid", vault.getKey().getValue()); //NOI18N
bootstrap.put("oci.vault.vaults[0].compartment-ocid", vault.getCompartmentId()); //NOI18N
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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.assets;

/**
* Validates if the implementing class is suitable for adding to {@link CloudAssets}.
* The validation result is represented by {@link Result}, which includes a {@link ValidationStatus}
* indicating the outcome of the validation.
*
* <p>The possible validation states are:
* <ul>
* <li>{@link ValidationStatus#OK} - Indicates that the item is suitable for adding to {@link CloudAssets}
* without any warnings or restrictions.</li>
* <li>{@link ValidationStatus#WARNING} - Indicates that the item may be added to {@link CloudAssets},
* but with a warning message to notify the user of potential issues.</li>
* <li>{@link ValidationStatus#ERROR} - Indicates that the item cannot be added to {@link CloudAssets}.
* A warning message will be shown, and the addition process will be blocked.</li>
* </ul>
*
* @author Jan Horvath
*/
public interface Validator {

enum ValidationStatus {
OK, WARNING, ERROR
};

public class Result {

public final ValidationStatus status;
public final String message;

public Result(ValidationStatus status, String message) {
this.status = status;
this.message = message;
}

}

public Result validate();

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,19 @@
import org.netbeans.modules.cloud.oracle.items.OCID;
import org.netbeans.modules.cloud.oracle.items.OCIItem;
import org.openide.util.Exceptions;
import org.openide.util.NbBundle;
import org.netbeans.modules.cloud.oracle.assets.Validator;

/**
*
* @author Jan Horvath
*/
public final class ComputeInstanceItem extends OCIItem implements URLProvider {
@NbBundle.Messages({
"SuggestAmpere=The Compute Instance has a different architecture than the local machine. Container images built on the local machine may not be compatible with this Compute Instance. Please consider creating a Compute Instance with an Ampere® shape.",
"SuggestIntel=The Compute Instance has a different architecture than the local machine. Container images built on the local machine may not be compatible with this Compute Instance. Please consider creating a Compute Instance with an AMD or Intel® shape."
})
public final class ComputeInstanceItem extends OCIItem implements URLProvider, Validator {
private final String AARCH = "aarch64";
private String publicIp = null;
private String processorDescription;
private String username;
Expand Down Expand Up @@ -88,4 +95,19 @@ public URL getURL() {
}
return null;
}

@Override
public Result validate() {
String osArch = System.getProperty("os.arch"); //NOI18N
String shapeDesc = getProcessorDescription();
boolean os_arm = AARCH.equals(osArch);
boolean shape_arm = shapeDesc != null && shapeDesc.contains("Ampere"); //NOI18N
if (os_arm == shape_arm) {
return new Result(ValidationStatus.OK, null);
} else if (os_arm && !shape_arm) {
return new Result(ValidationStatus.WARNING, Bundle.SuggestAmpere());
}
return new Result(ValidationStatus.WARNING, Bundle.SuggestIntel());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,20 @@
*/
package org.netbeans.modules.cloud.oracle.developer;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import org.netbeans.modules.cloud.oracle.adm.URLProvider;
import org.netbeans.modules.cloud.oracle.items.OCID;
import org.netbeans.modules.cloud.oracle.items.OCIItem;
import org.openide.util.Exceptions;

/**
*
* @author Jan Horvath
*/
public final class ContainerRepositoryItem extends OCIItem {
public final class ContainerRepositoryItem extends OCIItem implements URLProvider {

private Boolean isPublic;
private Integer imageCount;
Expand Down Expand Up @@ -65,5 +71,18 @@ public String getUrl() {
public String getRegistry() {
return String.format("%s.ocir.io", getRegionCode());
}

@Override
public URL getURL() {
if (getKey().getValue() != null && getRegion() != null) {
try {
URI uri = new URI(String.format("https://cloud.oracle.com/compute/registry/containers?region=%s", getRegion()));
return uri.toURL();
} catch (MalformedURLException | URISyntaxException ex) {
Exceptions.printStackTrace(ex);
}
}
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,20 @@
*/
package org.netbeans.modules.cloud.oracle.developer;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import org.netbeans.modules.cloud.oracle.adm.URLProvider;
import org.netbeans.modules.cloud.oracle.items.OCID;
import org.netbeans.modules.cloud.oracle.items.OCIItem;
import org.openide.util.Exceptions;

/**
*
* @author Jan Horvath
*/
public final class ContainerTagItem extends OCIItem {
public final class ContainerTagItem extends OCIItem implements URLProvider {

private String digest;
private String version;
Expand Down Expand Up @@ -61,5 +67,18 @@ public String getVersion() {
}
return version;
}

@Override
public URL getURL() {
if (getKey().getValue() != null && getRegion() != null) {
try {
URI uri = new URI(String.format("https://cloud.oracle.com/compute/registry/containers?region=%s", getRegion()));
return uri.toURL();
} catch (MalformedURLException | URISyntaxException ex) {
Exceptions.printStackTrace(ex);
}
}
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -365,12 +365,23 @@ public int index() {
}

public void resetToIndex(int index) {
if (ts == null) {
return ;
}
doc.render(() -> {
if (cancel.get()) {
return ;
}

if (ts == null) {
return ;
}

if (!ts.isValid()) {
cancel.set(true);
return ;
}

ts.moveIndex(index);
ts.moveNext();
ts.moveIndex(index);
ts.moveNext();
});
}

private static List<TokenSequence<?>> embeddedTokenSequences(TokenHierarchy<Document> th, int offset) {
Expand Down
48 changes: 41 additions & 7 deletions java/java.lsp.server/vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1035,12 +1035,22 @@ function activateWithJDK(specifiedJDK: string | null, context: ExtensionContext,
function runCommandInTerminal(command: string, name: string) {
const isWindows = process.platform === 'win32';

const shell = process.env.SHELL || '/bin/bash';
const shellName = shell.split('/').pop();
const isZsh = shellName === 'zsh';

const defaultShell = isWindows
? process.env.ComSpec || 'cmd.exe'
: process.env.SHELL || '/bin/bash';
: shell;

const pauseCommand = isWindows
? 'pause'
: 'echo "Press any key to close..."; ' + (isZsh
? 'read -rs -k1'
: 'read -rsn1');

const commandWithPause = `${command} && ${pauseCommand}`;

const pauseCommand = 'echo "Press any key to close..."; node -e "process.stdin.setRawMode(true); process.stdin.resume(); process.stdin.on(\'data\', process.exit.bind(process, 0));"';
const commandWithPause = `${command} 2>&1; ${pauseCommand}`;
const terminal = vscode.window.createTerminal({
name: name,
shellPath: defaultShell,
Expand Down Expand Up @@ -1098,13 +1108,37 @@ async function runDockerSSH(username: string, host: string, dockerImage: string,
micronautConfigFilesEnv += `${bootstrapProperties ? "," : ""}${applicationPropertiesContainerPath}`;
}

let dockerPullCommand = "";
let script = `#!/bin/sh\n`;
script += `set -e\n`;
script += `CONTAINER_ID_FILE="/home/${username}/.vscode.container.id"\n`;
script += `if [ -f "$CONTAINER_ID_FILE" ]; then\n`;
script += ` CONTAINER_ID=$(cat "$CONTAINER_ID_FILE")\n`;
script += ` if [ ! -z "$CONTAINER_ID" ] && docker ps -q --filter "id=$CONTAINER_ID" | grep -q .; then\n`;
script += ` echo "Stopping existing container with ID $CONTAINER_ID..."\n`;
script += ` docker stop "$CONTAINER_ID"\n`;
script += ` fi\n`;
script += ` rm -f "$CONTAINER_ID_FILE"\n`;
script += `fi\n`;

if (isRepositoryPrivate) {
dockerPullCommand = `cat ${bearerTokenRemotePath} | docker login --username=BEARER_TOKEN --password-stdin ${ocirServer} && `;
script += `cat ${bearerTokenRemotePath} | docker login --username=BEARER_TOKEN --password-stdin ${ocirServer} \n`;
}
dockerPullCommand += `docker pull ${dockerImage} && `;
script += `docker pull ${dockerImage} \n`;

sshCommand += `ssh ${username}@${host} "${dockerPullCommand} docker run -p 8080:8080 ${mountVolume} -e MICRONAUT_CONFIG_FILES=${micronautConfigFilesEnv} -it ${dockerImage}"`;
script += `NEW_CONTAINER_ID=$(docker run -p 8080:8080 ${mountVolume} -e MICRONAUT_CONFIG_FILES=${micronautConfigFilesEnv} -d ${dockerImage})\n`;

script += `if [ -n "$NEW_CONTAINER_ID" ]; then\n`
script += ` echo $NEW_CONTAINER_ID > $CONTAINER_ID_FILE\n`
script += `fi\n`
script += `docker logs -f "$NEW_CONTAINER_ID"\n`

const tempDir = process.env.TEMP || process.env.TMP || '/tmp';
const runContainerScript = path.join(tempDir, `run-container-${Date.now()}.sh`);
fs.writeFileSync(runContainerScript, script);

sshCommand += `scp "${runContainerScript}" ${username}@${host}:run-container.sh && `

sshCommand += `ssh ${username}@${host} "chmod +x run-container.sh && ./run-container.sh" `

runCommandInTerminal(sshCommand, `Container: ${username}@${host}`)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public String getSelectedText() {
int start = getSelectionStart();
int end = getSelectionEnd();
String str = null;
if (start > 0 && end > start) {
if (start >= 0 && end > start) {
try {
str = getDocument().getText(start, end - start);
} catch (BadLocationException ex) {
Expand Down
Loading