diff --git a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/CloudAssets.java b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/CloudAssets.java index b8b149a5ef93..38e490be0fb9 100644 --- a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/CloudAssets.java +++ b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/CloudAssets.java @@ -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) { @@ -184,7 +195,7 @@ public synchronized boolean isTenancyCompatible(OCIItem toCheck) { } public synchronized boolean isTenancyCompatible(OCIItem toCheck, boolean showWarning) { - List itemsMissingInfo = new ArrayList(); + List itemsMissingInfo = new ArrayList<> (); for(OCIItem item: items) { if (item != null && item.getTenancyId() == null) { itemsMissingInfo.add(item); diff --git a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/PropertiesGenerator.java b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/PropertiesGenerator.java index f5a21520695c..319d8214da0b 100644 --- a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/PropertiesGenerator.java +++ b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/PropertiesGenerator.java @@ -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 } diff --git a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/Validator.java b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/Validator.java new file mode 100644 index 000000000000..03231342f21c --- /dev/null +++ b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/Validator.java @@ -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. + * + *

The possible validation states are: + *

+ * + * @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(); + +} diff --git a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/compute/ComputeInstanceItem.java b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/compute/ComputeInstanceItem.java index 8bf09cd44169..c0d471535377 100644 --- a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/compute/ComputeInstanceItem.java +++ b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/compute/ComputeInstanceItem.java @@ -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; @@ -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()); + } + }