Skip to content

Commit

Permalink
Merge branch 'endgame-202305' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
wangmingliang-ms committed Jun 2, 2023
2 parents f1c913c + 0234d54 commit fd601b1
Show file tree
Hide file tree
Showing 13 changed files with 127 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public abstract class AbstractMojoBase extends AbstractAzureMojo {
* <ul>
* <li>cpu: Core numbers for deployment. </li>
* <li>memoryInGB: Memory for deployment. </li>
* <li>instanceCount: Instance count for deployment. </li>
* <li>instanceCount: Max replicas num for apps of standard consumption plan or instance num for apps of other plans. </li>
* <li>deploymentName: Name for deployment. </li>
* <li>jvmOptions: JVM options for the deployed app. </li>
* <li>runtimeVersion: The runtime version for Spring app, supported values are `Java 11`, `Java 17` and `Java 8`. </li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ private void confirmAndSave() throws IOException {
} else {
changesToConfirm.put("App name", this.appSettings.getAppName());
changesToConfirm.put("Public access", this.appSettings.getIsPublic());
changesToConfirm.put("Instance count", this.deploymentSettings.getInstanceCount());
changesToConfirm.put("Instance count/max replicas", this.deploymentSettings.getInstanceCount());
changesToConfirm.put("CPU count", this.deploymentSettings.getCpu());
changesToConfirm.put("Memory size(GB)", this.deploymentSettings.getMemoryInGB());
changesToConfirm.put("JVM options", this.deploymentSettings.getJvmOptions());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
public class AppDeploymentMavenConfig {
private Double cpu;
private Double memoryInGB;
/**
* {@code max replicas} for apps of standard consumption plan or {@code instance num} for apps of other plans.
*/
private Integer instanceCount;
private String deploymentName;
private String jvmOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ property: isPublic
required: false
---
id: configure-instance-count
promote: "Input instance count [***${schema.minimum}***-***${schema.maximum}***] (***${schema.default}***):"
promote: "Input instance count (or max replicas for apps of standard consumption plan) [***${schema.minimum}***-***${schema.maximum}***] (***${schema.default}***):"
resource: Deployment
property: instanceCount

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
]
},
"instanceCount": {
"description": "instance count",
"description": "instance count/max replicas",
"type": "integer",
"default": 1,
"minimum": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package com.microsoft.azure.toolkit.lib.common.model;

import com.azure.core.exception.HttpResponseException;
import com.azure.core.http.HttpResponse;
import com.azure.resourcemanager.resources.fluentcore.arm.ResourceId;
import com.azure.resourcemanager.resources.fluentcore.arm.models.HasId;
import com.azure.resourcemanager.resources.fluentcore.model.Refreshable;
Expand Down Expand Up @@ -230,10 +231,9 @@ protected final R loadRemote() {
log.debug("[{}:{}]:loadRemote()", this.module.getName(), this.getName());
try {
return this.getModule().loadResourceFromAzure(this.getName(), this.getResourceGroupName());
} catch (Exception e) {
} catch (final Exception e) {
log.debug("[{}:{}]:loadRemote()=EXCEPTION", this.module.getName(), this.getName(), e);
final Throwable cause = e instanceof HttpResponseException ? e : ExceptionUtils.getRootCause(e);
if (cause instanceof HttpResponseException && HttpStatus.SC_NOT_FOUND == ((HttpResponseException) cause).getResponse().getStatusCode()) {
if (isNotFoundException(e)) {
return null;
}
throw e;
Expand All @@ -247,10 +247,9 @@ protected final R loadRemote() {
private R refreshRemote(@Nonnull R remote) {
try {
return this.refreshRemoteFromAzure(remote);
} catch (Exception e) {
} catch (final Exception e) {
log.debug("[{}:{}]:refreshRemoteFromAzure()=EXCEPTION", this.module.getName(), this.getName(), e);
final Throwable cause = e instanceof HttpResponseException ? e : ExceptionUtils.getRootCause(e);
if (cause instanceof HttpResponseException && HttpStatus.SC_NOT_FOUND == ((HttpResponseException) cause).getResponse().getStatusCode()) {
if (isNotFoundException(e)) {
return null;
}
throw e;
Expand Down Expand Up @@ -297,9 +296,8 @@ private void deleteFromAzure() {
log.debug("[{}:{}]:delete->module.deleteResourceFromAzure({})", this.module.getName(), this.getName(), this.getId());
try {
this.getModule().deleteResourceFromAzure(this.getId());
} catch (Exception e) {
final Throwable cause = e instanceof HttpResponseException ? e : ExceptionUtils.getRootCause(e);
if (cause instanceof HttpResponseException && HttpStatus.SC_NOT_FOUND == ((HttpResponseException) cause).getResponse().getStatusCode()) {
} catch (final Exception e) {
if (isNotFoundException(e)) {
log.debug("[{}]:delete()->deleteResourceFromAzure()=SC_NOT_FOUND", this.name, e);
} else {
this.getSubModules().stream().flatMap(m -> m.listCachedResources().stream()).forEach(r -> r.setStatus(Status.UNKNOWN));
Expand Down Expand Up @@ -365,9 +363,8 @@ protected void doModify(@Nonnull Runnable body, @Nullable String status) {
final R refreshed = Optional.ofNullable(this.remoteRef.get()).map(this::refreshRemote).orElse(null);
log.debug("[{}:{}]:doModify->setRemote({})", this.module.getName(), this.getName(), this.remoteRef.get());
this.setRemote(refreshed);
} catch (Throwable t) {
final Throwable cause = t instanceof HttpResponseException ? t : ExceptionUtils.getRootCause(t);
if (cause instanceof HttpResponseException && HttpStatus.SC_NOT_FOUND == ((HttpResponseException) cause).getResponse().getStatusCode()) {
} catch (final Throwable t) {
if (isNotFoundException(t)) {
this.setRemote(null);
} else {
this.syncTimeRef.compareAndSet(0, System.currentTimeMillis());
Expand All @@ -382,6 +379,16 @@ protected void doModify(@Nonnull Runnable body, @Nullable String status) {
}
}

static boolean isNotFoundException(Throwable t) {
final Throwable cause = t instanceof HttpResponseException ? t : ExceptionUtils.getRootCause(t);
return Optional.ofNullable(cause).filter(c -> cause instanceof HttpResponseException)
.map(c -> ((HttpResponseException) c))
.map(HttpResponseException::getResponse)
.map(HttpResponse::getStatusCode)
.filter(c -> c == HttpStatus.SC_NOT_FOUND)
.isPresent();
}

@Nullable
public R doModify(@Nonnull Callable<R> body, @Nullable String status) {
if (!this.lock.tryLock()) {
Expand All @@ -396,7 +403,7 @@ public R doModify(@Nonnull Callable<R> body, @Nullable String status) {
log.debug("[{}:{}]:doModify->setRemote({})", this.module.getName(), this.getName(), remote);
this.setRemote(remote);
return remote;
} catch (Throwable t) {
} catch (final Throwable t) {
final Throwable cause = t instanceof HttpResponseException ? t : ExceptionUtils.getRootCause(t);
if (cause instanceof HttpResponseException && HttpStatus.SC_NOT_FOUND == ((HttpResponseException) cause).getResponse().getStatusCode()) {
this.setRemote(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.http.HttpStatus;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand All @@ -60,6 +59,7 @@
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;

import static com.microsoft.azure.toolkit.lib.common.model.AbstractAzResource.isNotFoundException;
import static com.microsoft.azure.toolkit.lib.common.model.AzResource.RESOURCE_GROUP_PLACEHOLDER;

@Slf4j
Expand Down Expand Up @@ -148,10 +148,9 @@ private void reloadResources() {
.collect(Collectors.toMap(r -> this.newResource(r).getId().toLowerCase(), r -> r));
log.debug("[{}]:reloadResources->setResources(xxx)", this.name);
this.setResources(loadedResources);
} catch (Exception e) {
} catch (final Exception e) {
log.debug("[{}]:reloadResources->setResources([])", this.name);
final Throwable cause = e instanceof HttpResponseException ? e : ExceptionUtils.getRootCause(e);
if (cause instanceof HttpResponseException && HttpStatus.SC_NOT_FOUND == ((HttpResponseException) cause).getResponse().getStatusCode()) {
if (isNotFoundException(e)) {
log.debug("[{}]:reloadResources->loadResourceFromAzure()=SC_NOT_FOUND", this.name, e);
this.setResources(Collections.emptyMap());
} else {
Expand Down Expand Up @@ -263,11 +262,11 @@ public T get(@Nonnull String name, @Nullable String rgName) {
try {
log.debug("[{}]:get({}, {})->loadResourceFromAzure()", this.name, name, resourceGroup);
remote = loadResourceFromAzure(name, resourceGroup);
} catch (Exception e) {
} catch (final Exception e) {
log.debug("[{}]:get({}, {})->loadResourceFromAzure()=EXCEPTION", this.name, name, resourceGroup, e);
final Throwable cause = e instanceof HttpResponseException ? e : ExceptionUtils.getRootCause(e);
if (cause instanceof HttpResponseException) {
if (HttpStatus.SC_NOT_FOUND != ((HttpResponseException) cause).getResponse().getStatusCode()) {
if (!isNotFoundException(e)) {
log.debug("[{}]:get({}, {})->loadResourceFromAzure()=SC_NOT_FOUND", this.name, name, resourceGroup, e);
throw e;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
package com.microsoft.azure.toolkit.lib.common.utils;

import com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException;
import com.microsoft.azure.toolkit.lib.common.messager.AzureMessager;
import org.apache.commons.lang3.NotImplementedException;
import org.apache.http.client.utils.URIBuilder;
import reactor.core.publisher.Flux;

import javax.annotation.Nonnull;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
Expand Down Expand Up @@ -44,13 +46,15 @@ default Flux<String> streamingLogs(boolean follow, @Nonnull Map<String, String>
return Flux.create((fluxSink) -> {
try {
final InputStream is = connection.getInputStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
final BufferedReader rd = new BufferedReader(new InputStreamReader(is));
String line;
while ((line = rd.readLine()) != null) {
fluxSink.next(line);
}
rd.close();
} catch (final Exception e) {
} catch (final FileNotFoundException e) {
AzureMessager.getMessager().error("app/instance may be deactivated, please refresh and try again later.");
} catch (final IOException e) {
throw new AzureToolkitRuntimeException(e);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@

package com.microsoft.azure.toolkit.lib.containerapps.containerapp;

import com.azure.resourcemanager.appcontainers.ContainerAppsApiManager;
import com.microsoft.azure.toolkit.lib.common.bundle.AzureString;
import com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException;
import com.microsoft.azure.toolkit.lib.common.model.AbstractAzResource;
import com.microsoft.azure.toolkit.lib.common.model.AbstractAzResourceModule;
import com.microsoft.azure.toolkit.lib.common.utils.StreamingLogSupport;
import com.microsoft.azure.toolkit.lib.containerapps.AzureContainerAppsServiceSubscription;
import org.apache.commons.lang3.BooleanUtils;
import org.jetbrains.annotations.NotNull;

Expand All @@ -22,7 +20,6 @@
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

public class ReplicaContainer extends AbstractAzResource<ReplicaContainer, Replica, com.azure.resourcemanager.appcontainers.models.ReplicaContainer>
implements StreamingLogSupport {
Expand Down Expand Up @@ -67,9 +64,6 @@ public String loadStatus(@NotNull com.azure.resourcemanager.appcontainers.models

@Override
public String getLogStreamAuthorization() {
final AzureContainerAppsServiceSubscription subs = this.getParent().getParent().getParent().getParent();
final ContainerAppsApiManager manager = subs.getRemote();
final String authToken = Optional.ofNullable(manager).map(m -> m.containerApps().getAuthToken(getResourceGroupName(), getName()).token()).orElse(null);
return "Bearer " + authToken;
return this.getParent().getParent().getParent().getLogStreamAuthorization();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.azure.resourcemanager.appplatform.models.Sku;
import com.azure.resourcemanager.appplatform.models.SpringApp;
import com.azure.resourcemanager.appplatform.models.SpringService;
import com.azure.resourcemanager.appplatform.models.TemporaryDisk;
import com.microsoft.azure.toolkit.lib.common.bundle.AzureString;
import com.microsoft.azure.toolkit.lib.common.messager.AzureMessager;
import com.microsoft.azure.toolkit.lib.common.messager.IAzureMessager;
Expand Down Expand Up @@ -51,6 +52,8 @@ public class SpringCloudAppDraft extends SpringCloudApp implements AzResource.Dr
* @see <a href="https://azure.microsoft.com/en-us/pricing/details/spring-cloud/">Pricing - Azure Spring Apps</a>
*/
public static final int STANDARD_TIER_DEFAULT_DISK_SIZE = 50;
public static final int DEFAULT_TEMP_DISK_SIZE = 5;
public static final String DEFAULT_TEMP_DISK_MOUNT_PATH = "/tmp";
@Getter
@Nullable
private final SpringCloudApp origin;
Expand Down Expand Up @@ -113,6 +116,7 @@ public SpringApp createResourceInAzure() {
final boolean newPublicEndpointEnabled = this.isPublicEndpointEnabled();
final Integer newDiskSize = this.isPersistentDiskEnabled() ? this.getParent().isStandardTier() ? STANDARD_TIER_DEFAULT_DISK_SIZE : BASIC_TIER_DEFAULT_DISK_SIZE : null;
final PersistentDisk newDisk = this.isPersistentDiskEnabled() ? new PersistentDisk().withSizeInGB(newDiskSize).withMountPath(DEFAULT_DISK_MOUNT_PATH) : null;
final TemporaryDisk tmpDisk = this.getParent().isEnterpriseTier() ? null : new TemporaryDisk().withSizeInGB(DEFAULT_TEMP_DISK_SIZE).withMountPath(DEFAULT_TEMP_DISK_MOUNT_PATH);
// refer https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/resourcemanager/azure-resourcemanager-samples/src/main/java/com/azure/
// resourcemanager/appplatform/samples/ManageSpringCloud.java#L122-L129
final Optional<SpringCloudDeploymentConfig> d = Optional.of(this.getConfig()).map(SpringCloudAppConfig::getDeployment);
Expand All @@ -121,6 +125,7 @@ public SpringApp createResourceInAzure() {
final AppResourceInner appResource = new AppResourceInner()
.withProperties(new AppResourceProperties()
.withPersistentDisk(newDisk)
.withTemporaryDisk(tmpDisk)
.withPublicProperty(newPublicEndpointEnabled));

final DeploymentResourceProperties properties = new DeploymentResourceProperties()
Expand Down Expand Up @@ -221,7 +226,7 @@ public void setPersistentDiskEnabled(Boolean enabled) {

public boolean isPersistentDiskEnabled() {
final Boolean enabled = Optional.ofNullable(config).map(Config::getPersistentDiskEnabled).orElseGet(super::isPersistentDiskEnabled);
return enabled && !this.getParent().isEnterpriseTier();
return enabled && !this.getParent().isEnterpriseTier() && !this.getParent().isConsumptionTier();
}

public void setActiveDeploymentName(String name) {
Expand Down
Loading

0 comments on commit fd601b1

Please sign in to comment.