er : metricAlert.alertCriterias().entrySet()) {
3286 | MetricAlertCondition alertCondition = er.getValue();
3287 | info.append("\n\t\tCondition name: ").append(er.getKey())
3288 | .append("\n\t\tSignal name: ").append(alertCondition.metricName())
3289 | .append("\n\t\tMetric Namespace: ").append(alertCondition.metricNamespace())
3290 | .append("\n\t\tOperator: ").append(alertCondition.condition())
3291 | .append("\n\t\tThreshold: ").append(alertCondition.threshold())
3292 | .append("\n\t\tTime Aggregation: ").append(alertCondition.timeAggregation());
3293 | if (alertCondition.dimensions() != null && !alertCondition.dimensions().isEmpty()) {
3294 | for (MetricDimension dimon : alertCondition.dimensions()) {
3295 | info.append("\n\t\tDimension Filter: ").append("Name [").append(dimon.name()).append("] operator [Include] values[");
3296 | for (String vals : dimon.values()) {
3297 | info.append(vals).append(", ");
3298 | }
3299 | info.append("]");
3300 | }
3301 | }
3302 | }
3303 | }
3304 | System.out.println(info.toString());
3305 | }
3306 |
3307 | /**
3308 | * Print spring service settings.
3309 | *
3310 | * @param springService spring service instance
3311 | */
3312 | public static void print(SpringService springService) {
3313 | StringBuilder info = new StringBuilder("Spring Service: ")
3314 | .append("\n\tId: ").append(springService.id())
3315 | .append("\n\tName: ").append(springService.name())
3316 | .append("\n\tResource Group: ").append(springService.resourceGroupName())
3317 | .append("\n\tRegion: ").append(springService.region())
3318 | .append("\n\tTags: ").append(springService.tags());
3319 |
3320 | ConfigServerProperties serverProperties = springService.getServerProperties();
3321 | if (serverProperties != null && serverProperties.provisioningState() != null
3322 | && serverProperties.provisioningState().equals(ConfigServerState.SUCCEEDED) && serverProperties.configServer() != null) {
3323 | info.append("\n\tProperties: ");
3324 | if (serverProperties.configServer().gitProperty() != null) {
3325 | info.append("\n\t\tGit: ").append(serverProperties.configServer().gitProperty().uri());
3326 | }
3327 | }
3328 |
3329 | if (springService.sku() != null) {
3330 | info.append("\n\tSku: ")
3331 | .append("\n\t\tName: ").append(springService.sku().name())
3332 | .append("\n\t\tTier: ").append(springService.sku().tier())
3333 | .append("\n\t\tCapacity: ").append(springService.sku().capacity());
3334 | }
3335 |
3336 | MonitoringSettingProperties monitoringSettingProperties = springService.getMonitoringSetting();
3337 | if (monitoringSettingProperties != null && monitoringSettingProperties.provisioningState() != null
3338 | && monitoringSettingProperties.provisioningState().equals(MonitoringSettingState.SUCCEEDED)) {
3339 | info.append("\n\tTrace: ")
3340 | .append("\n\t\tEnabled: ").append(monitoringSettingProperties.traceEnabled())
3341 | .append("\n\t\tApp Insight Instrumentation Key: ").append(monitoringSettingProperties.appInsightsInstrumentationKey());
3342 | }
3343 |
3344 | System.out.println(info.toString());
3345 | }
3346 |
3347 | /**
3348 | * Print spring app settings.
3349 | *
3350 | * @param springApp spring app instance
3351 | */
3352 | public static void print(SpringApp springApp) {
3353 | StringBuilder info = new StringBuilder("Spring Service: ")
3354 | .append("\n\tId: ").append(springApp.id())
3355 | .append("\n\tName: ").append(springApp.name())
3356 | .append("\n\tPublic Endpoint: ").append(springApp.isPublic())
3357 | .append("\n\tUrl: ").append(springApp.url())
3358 | .append("\n\tHttps Only: ").append(springApp.isHttpsOnly())
3359 | .append("\n\tFully Qualified Domain Name: ").append(springApp.fqdn())
3360 | .append("\n\tActive Deployment Name: ").append(springApp.activeDeploymentName());
3361 |
3362 | if (springApp.temporaryDisk() != null) {
3363 | info.append("\n\tTemporary Disk:")
3364 | .append("\n\t\tSize In GB: ").append(springApp.temporaryDisk().sizeInGB())
3365 | .append("\n\t\tMount Path: ").append(springApp.temporaryDisk().mountPath());
3366 | }
3367 |
3368 | if (springApp.persistentDisk() != null) {
3369 | info.append("\n\tPersistent Disk:")
3370 | .append("\n\t\tSize In GB: ").append(springApp.persistentDisk().sizeInGB())
3371 | .append("\n\t\tMount Path: ").append(springApp.persistentDisk().mountPath());
3372 | }
3373 |
3374 | if (springApp.identity() != null) {
3375 | info.append("\n\tIdentity:")
3376 | .append("\n\t\tType: ").append(springApp.identity().type())
3377 | .append("\n\t\tPrincipal Id: ").append(springApp.identity().principalId())
3378 | .append("\n\t\tTenant Id: ").append(springApp.identity().tenantId());
3379 | }
3380 |
3381 | System.out.println(info.toString());
3382 | }
3383 |
3384 | /**
3385 | * Print private link resource.
3386 | *
3387 | * @param privateLinkResource the private link resource
3388 | */
3389 | public static void print(PrivateLinkResource privateLinkResource) {
3390 | StringBuilder info = new StringBuilder("Private Link Resource: ")
3391 | .append("\n\tGroup ID: ").append(privateLinkResource.groupId())
3392 | .append("\n\tRequired Member Names: ").append(privateLinkResource.requiredMemberNames())
3393 | .append("\n\tRequired DNS Zone Names: ").append(privateLinkResource.requiredDnsZoneNames());
3394 |
3395 | System.out.println(info);
3396 | }
3397 |
3398 | /**
3399 | * Print private endpoint.
3400 | *
3401 | * @param privateEndpoint the private endpoint
3402 | */
3403 | public static void print(PrivateEndpoint privateEndpoint) {
3404 | StringBuilder info = new StringBuilder("Private Endpoint: ")
3405 | .append("\n\tId: ").append(privateEndpoint.id())
3406 | .append("\n\tName: ").append(privateEndpoint.name());
3407 |
3408 | if (privateEndpoint.privateLinkServiceConnections() != null && !privateEndpoint.privateLinkServiceConnections().isEmpty()) {
3409 | for (PrivateEndpoint.PrivateLinkServiceConnection connection : privateEndpoint.privateLinkServiceConnections().values()) {
3410 | info
3411 | .append("\n\t\tPrivate Link Service Connection Name: ").append(connection.name())
3412 | .append("\n\t\tPrivate Link Resource ID: ").append(connection.privateLinkResourceId())
3413 | .append("\n\t\tSub Resource Names: ").append(connection.subResourceNames())
3414 | .append("\n\t\tProvision Status: ").append(connection.state().status());
3415 | }
3416 | }
3417 |
3418 | if (privateEndpoint.privateLinkServiceConnections() != null && !privateEndpoint.privateLinkServiceConnections().isEmpty()) {
3419 | info.append("\n\tPrivate Link Service Connections:");
3420 | for (PrivateEndpoint.PrivateLinkServiceConnection connection : privateEndpoint.privateLinkServiceConnections().values()) {
3421 | info
3422 | .append("\n\t\tName: ").append(connection.name())
3423 | .append("\n\t\tPrivate Link Resource ID: ").append(connection.privateLinkResourceId())
3424 | .append("\n\t\tSub Resource Names: ").append(connection.subResourceNames())
3425 | .append("\n\t\tStatus: ").append(connection.state().status());
3426 | }
3427 | }
3428 |
3429 | if (privateEndpoint.customDnsConfigurations() != null && !privateEndpoint.customDnsConfigurations().isEmpty()) {
3430 | info.append("\n\tCustom DNS Configure:");
3431 | for (CustomDnsConfigPropertiesFormat customDns : privateEndpoint.customDnsConfigurations()) {
3432 | info
3433 | .append("\n\t\tFQDN: ").append(customDns.fqdn())
3434 | .append("\n\t\tIP Address: ").append(customDns.ipAddresses());
3435 | }
3436 | }
3437 |
3438 | System.out.println(info);
3439 | }
3440 |
3441 | /**
3442 | * Sends a GET request to target URL.
3443 | *
3444 | * Retry logic tuned for AppService.
3445 | * The method does not handle 301 redirect.
3446 | *
3447 | * @param urlString the target URL.
3448 | * @return Content of the HTTP response.
3449 | */
3450 | public static String sendGetRequest(String urlString) {
3451 | HttpRequest request = new HttpRequest(HttpMethod.GET, urlString);
3452 | Mono> response =
3453 | stringResponse(HTTP_PIPELINE.send(request)
3454 | .flatMap(response1 -> {
3455 | int code = response1.getStatusCode();
3456 | if (code == 200 || code == 400 || code == 404) {
3457 | return Mono.just(response1);
3458 | } else {
3459 | return Mono.error(new HttpResponseException(response1));
3460 | }
3461 | })
3462 | .retryWhen(Retry
3463 | .fixedDelay(5, Duration.ofSeconds(30))
3464 | .filter(t -> {
3465 | boolean retry = false;
3466 | if (t instanceof TimeoutException) {
3467 | retry = true;
3468 | } else if (t instanceof HttpResponseException
3469 | && ((HttpResponseException) t).getResponse().getStatusCode() == 503) {
3470 | retry = true;
3471 | }
3472 |
3473 | if (retry) {
3474 | LOGGER.info("retry GET request to {}", urlString);
3475 | }
3476 | return retry;
3477 | })));
3478 | Response ret = response.block();
3479 | return ret == null ? null : ret.getValue();
3480 | }
3481 |
3482 | /**
3483 | * Sends a POST request to target URL.
3484 | *
3485 | * Retry logic tuned for AppService.
3486 | *
3487 | * @param urlString the target URL.
3488 | * @param body the request body.
3489 | * @return Content of the HTTP response.
3490 | * */
3491 | public static String sendPostRequest(String urlString, String body) {
3492 | try {
3493 | HttpRequest request = new HttpRequest(HttpMethod.POST, urlString).setBody(body);
3494 | Mono> response =
3495 | stringResponse(HTTP_PIPELINE.send(request)
3496 | .flatMap(response1 -> {
3497 | int code = response1.getStatusCode();
3498 | if (code == 200 || code == 400 || code == 404) {
3499 | return Mono.just(response1);
3500 | } else {
3501 | return Mono.error(new HttpResponseException(response1));
3502 | }
3503 | })
3504 | .retryWhen(Retry
3505 | .fixedDelay(5, Duration.ofSeconds(30))
3506 | .filter(t -> {
3507 | boolean retry = false;
3508 | if (t instanceof TimeoutException) {
3509 | retry = true;
3510 | }
3511 |
3512 | if (retry) {
3513 | LOGGER.info("retry POST request to {}", urlString);
3514 | }
3515 | return retry;
3516 | })));
3517 | Response ret = response.block();
3518 | return ret == null ? null : ret.getValue();
3519 | } catch (Exception e) {
3520 | LOGGER.logThrowableAsError(e);
3521 | return null;
3522 | }
3523 | }
3524 |
3525 | private static Mono> stringResponse(Mono responseMono) {
3526 | return responseMono.flatMap(response -> response.getBodyAsString()
3527 | .map(str -> new SimpleResponse<>(response.getRequest(), response.getStatusCode(), response.getHeaders(), str)));
3528 | }
3529 |
3530 | private static final HttpPipeline HTTP_PIPELINE = new HttpPipelineBuilder()
3531 | .policies(
3532 | new HttpLoggingPolicy(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)),
3533 | new RetryPolicy("Retry-After", ChronoUnit.SECONDS))
3534 | .build();
3535 |
3536 | /**
3537 | * Get the size of the iterable.
3538 | *
3539 | * @param iterable iterable to count size
3540 | * @param generic type parameter of the iterable
3541 | * @return size of the iterable
3542 | */
3543 | public static int getSize(Iterable iterable) {
3544 | int res = 0;
3545 | Iterator iterator = iterable.iterator();
3546 | while (iterator.hasNext()) {
3547 | iterator.next();
3548 | res++;
3549 | }
3550 | return res;
3551 | }
3552 | }
3553 |
--------------------------------------------------------------------------------