├── .gitignore ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── pom.xml └── src └── main └── java └── com └── azure └── resourcemanager ├── containerinstance └── samples │ └── ManageContainerInstanceWithMultipleContainerImages.java └── samples └── Utils.java /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Auth filed 4 | *.auth 5 | *.azureauth 6 | 7 | # Mobile Tools for Java (J2ME) 8 | .mtj.tmp/ 9 | 10 | # Package Files # 11 | *.jar 12 | *.war 13 | *.ear 14 | 15 | # Azure Tooling # 16 | node_modules 17 | packages 18 | 19 | # Eclipse # 20 | *.pydevproject 21 | .project 22 | .metadata 23 | bin/** 24 | tmp/** 25 | tmp/**/* 26 | *.tmp 27 | *.bak 28 | *.swp 29 | *~.nib 30 | local.properties 31 | .classpath 32 | .settings/ 33 | .loadpath 34 | 35 | # Other Tooling # 36 | .classpath 37 | .project 38 | target/ 39 | .idea 40 | *.iml 41 | 42 | # Mac OS # 43 | .DS_Store 44 | .DS_Store? 45 | 46 | # Windows # 47 | Thumbs.db 48 | 49 | # reduced pom files should not be included 50 | dependency-reduced-pom.xml -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to Azure samples 2 | 3 | Thank you for your interest in contributing to Azure samples! 4 | 5 | ## Ways to contribute 6 | 7 | You can contribute to [Azure samples](https://azure.microsoft.com/documentation/samples/) in a few different ways: 8 | 9 | - Submit feedback on [this sample page](https://azure.microsoft.com/documentation/samples/aci-java-create-container-groups/) whether it was helpful or not. 10 | - Submit issues through [issue tracker](https://github.com/Azure-Samples/aci-java-create-container-groups/issues) on GitHub. We are actively monitoring the issues and improving our samples. 11 | - If you wish to make code changes to samples, or contribute something new, please follow the [GitHub Forks / Pull requests model](https://help.github.com/articles/fork-a-repo/): Fork the sample repo, make the change and propose it back by submitting a pull request. -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Microsoft Corporation. All rights reserved. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | --- 2 | page_type: sample 3 | languages: 4 | - java 5 | products: 6 | - azure 7 | extensions: 8 | services: Containerinstance 9 | platforms: java 10 | --- 11 | 12 | # Getting Started with Containerinstance - Manage Container Instance With Multiple Container Images - in Java # 13 | 14 | 15 | Azure Container Instance sample for managing container instances. 16 | - Create an Azure container group with two container instances using Docker images "microsoft/aci-helloworld" and "microsoft/aci-tutorial-sidecar" 17 | - Set the container group restart policy to "never" 18 | - Test that the container app can be reached via "curl" like HTTP GET calls 19 | - Retrieve container log content 20 | - Delete the container group resource 21 | 22 | 23 | ## Running this Sample ## 24 | 25 | To run this sample: 26 | 27 | See [DefaultAzureCredential](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/identity/azure-identity#defaultazurecredential) and prepare the authentication works best for you. For more details on authentication, please refer to [AUTH.md](https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/resourcemanager/docs/AUTH.md). 28 | 29 | git clone https://github.com/Azure-Samples/aci-java-create-container-groups.git 30 | 31 | cd aci-java-create-container-groups 32 | 33 | mvn clean compile exec:java 34 | 35 | ## More information ## 36 | 37 | For general documentation as well as quickstarts on how to use Azure Management Libraries for Java, please see [here](https://aka.ms/azsdk/java/mgmt). 38 | 39 | If you find bug in the sample, please create an issue [here](https://github.com/Azure/azure-sdk-for-java/issues). 40 | 41 | Start to develop applications with Java on Azure [here](http://azure.com/java). 42 | 43 | If you don't have a Microsoft Azure subscription you can get a FREE trial account [here](http://go.microsoft.com/fwlink/?LinkId=330212). 44 | 45 | --- 46 | 47 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. 48 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | com.microsoft.azure 6 | aci-java-create-container-groups 7 | 0.0.1-SNAPSHOT 8 | ManageContainerInstanceWithMultipleContainerImages.java 9 | 10 | https://github.com/Azure/aci-java-create-container-groups 11 | 12 | 13 | 14 | org.codehaus.mojo 15 | exec-maven-plugin 16 | 1.4.0 17 | 18 | com.azure.resourcemanager.containerinstance.samples.ManageContainerInstanceWithMultipleContainerImages 19 | false 20 | 21 | 22 | 23 | maven-compiler-plugin 24 | 3.8.1 25 | 26 | 1.8 27 | 1.8 28 | 29 | 30 | 31 | maven-assembly-plugin 32 | 33 | 34 | package 35 | 36 | attached 37 | 38 | 39 | 40 | jar-with-dependencies 41 | 42 | 43 | 44 | com.azure.resourcemanager.containerinstance.samples.ManageContainerInstanceWithMultipleContainerImages.java 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | com.azure.resourcemanager 56 | azure-resourcemanager 57 | 2.17.0 58 | 59 | 60 | com.azure 61 | azure-identity 62 | 1.5.3 63 | 64 | 65 | commons-net 66 | commons-net 67 | 3.6 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /src/main/java/com/azure/resourcemanager/containerinstance/samples/ManageContainerInstanceWithMultipleContainerImages.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | // Licensed under the MIT License. 3 | 4 | package com.azure.resourcemanager.containerinstance.samples; 5 | 6 | import com.azure.core.credential.TokenCredential; 7 | import com.azure.core.http.policy.HttpLogDetailLevel; 8 | import com.azure.core.management.AzureEnvironment; 9 | import com.azure.identity.DefaultAzureCredentialBuilder; 10 | import com.azure.resourcemanager.AzureResourceManager; 11 | import com.azure.resourcemanager.containerinstance.models.ContainerGroup; 12 | import com.azure.resourcemanager.containerinstance.models.ContainerGroupRestartPolicy; 13 | import com.azure.core.management.Region; 14 | import com.azure.core.management.profile.AzureProfile; 15 | import com.azure.resourcemanager.resources.fluentcore.utils.ResourceManagerUtils; 16 | import com.azure.resourcemanager.samples.Utils; 17 | 18 | import java.time.Duration; 19 | 20 | /** 21 | * Azure Container Instance sample for managing container instances. 22 | * - Create an Azure container group with two container instances using Docker images "microsoft/aci-helloworld" and "microsoft/aci-tutorial-sidecar" 23 | * - Set the container group restart policy to "never" 24 | * - Test that the container app can be reached via "curl" like HTTP GET calls 25 | * - Retrieve container log content 26 | * - Delete the container group resource 27 | */ 28 | public class ManageContainerInstanceWithMultipleContainerImages { 29 | /** 30 | * Main function which runs the actual sample. 31 | * 32 | * @param azureResourceManager instance of the azure client 33 | * @return true if sample runs successfully 34 | */ 35 | public static boolean runSample(AzureResourceManager azureResourceManager) { 36 | final String rgName = Utils.randomResourceName(azureResourceManager, "rgACI", 15); 37 | final String aciName = Utils.randomResourceName(azureResourceManager, "acisample", 20); 38 | final String containerImageName1 = "mcr.microsoft.com/azuredocs/aci-helloworld"; 39 | final String containerImageName2 = "mcr.microsoft.com/azuredocs/aci-tutorial-sidecar"; 40 | 41 | try { 42 | //============================================================= 43 | // Create a container group with two container instances 44 | 45 | ContainerGroup containerGroup = azureResourceManager.containerGroups().define(aciName) 46 | .withRegion(Region.US_WEST) 47 | .withNewResourceGroup(rgName) 48 | .withLinux() 49 | .withPublicImageRegistryOnly() 50 | .withoutVolume() 51 | .defineContainerInstance(aciName + "-1") 52 | .withImage(containerImageName1) 53 | .withExternalTcpPort(80) 54 | .withCpuCoreCount(.5) 55 | .withMemorySizeInGB(0.8) 56 | .attach() 57 | .defineContainerInstance(aciName + "-2") 58 | .withImage(containerImageName2) 59 | .withoutPorts() 60 | .withCpuCoreCount(.5) 61 | .withMemorySizeInGB(0.8) 62 | .attach() 63 | .withRestartPolicy(ContainerGroupRestartPolicy.NEVER) 64 | .withDnsPrefix(aciName) 65 | .create(); 66 | 67 | Utils.print(containerGroup); 68 | 69 | //============================================================= 70 | // Check that the container instance is up and running 71 | 72 | // warm up 73 | System.out.println("Warming up " + containerGroup.ipAddress()); 74 | Utils.sendGetRequest("http://" + containerGroup.ipAddress()); 75 | ResourceManagerUtils.sleep(Duration.ofSeconds(15)); 76 | System.out.println("CURLing " + containerGroup.ipAddress()); 77 | System.out.println(Utils.sendGetRequest("http://" + containerGroup.ipAddress())); 78 | 79 | //============================================================= 80 | // Check the container instance logs 81 | 82 | String logContent = containerGroup.getLogContent(aciName + "-1"); 83 | System.out.format("Logs for container instance: %s%n%s", aciName + "-1", logContent); 84 | logContent = containerGroup.getLogContent(aciName + "-2"); 85 | System.out.format("Logs for container instance: %s%n%s", aciName + "-2", logContent); 86 | 87 | //============================================================= 88 | // Remove the container group 89 | 90 | azureResourceManager.containerGroups().deleteById(containerGroup.id()); 91 | 92 | return true; 93 | } finally { 94 | try { 95 | System.out.println("Deleting Resource Group: " + rgName); 96 | azureResourceManager.resourceGroups().beginDeleteByName(rgName); 97 | System.out.println("Deleted Resource Group: " + rgName); 98 | } catch (NullPointerException npe) { 99 | System.out.println("Did not create any resources in Azure. No clean up is necessary"); 100 | } catch (Exception g) { 101 | g.printStackTrace(); 102 | } 103 | } 104 | } 105 | 106 | /** 107 | * Main entry point. 108 | * 109 | * @param args the parameters 110 | */ 111 | public static void main(String[] args) { 112 | try { 113 | //============================================================= 114 | // Authenticate 115 | 116 | final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); 117 | final TokenCredential credential = new DefaultAzureCredentialBuilder() 118 | .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) 119 | .build(); 120 | 121 | AzureResourceManager azureResourceManager = AzureResourceManager 122 | .configure() 123 | .withLogLevel(HttpLogDetailLevel.BASIC) 124 | .authenticate(credential, profile) 125 | .withDefaultSubscription(); 126 | 127 | // Print selected subscription 128 | System.out.println("Selected subscription: " + azureResourceManager.subscriptionId()); 129 | 130 | runSample(azureResourceManager); 131 | } catch (Exception e) { 132 | System.out.println(e.getMessage()); 133 | e.printStackTrace(); 134 | } 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /src/main/java/com/azure/resourcemanager/samples/Utils.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | // Licensed under the MIT License. 3 | 4 | package com.azure.resourcemanager.samples; 5 | 6 | import com.azure.core.exception.HttpResponseException; 7 | import com.azure.core.http.HttpMethod; 8 | import com.azure.core.http.HttpPipeline; 9 | import com.azure.core.http.HttpPipelineBuilder; 10 | import com.azure.core.http.HttpRequest; 11 | import com.azure.core.http.HttpResponse; 12 | import com.azure.core.http.policy.HttpLogDetailLevel; 13 | import com.azure.core.http.policy.HttpLogOptions; 14 | import com.azure.core.http.policy.HttpLoggingPolicy; 15 | import com.azure.core.http.policy.RetryPolicy; 16 | import com.azure.core.http.rest.PagedIterable; 17 | import com.azure.core.http.rest.Response; 18 | import com.azure.core.http.rest.SimpleResponse; 19 | import com.azure.core.management.Region; 20 | import com.azure.core.management.exception.ManagementException; 21 | import com.azure.core.util.logging.ClientLogger; 22 | import com.azure.core.util.serializer.JacksonAdapter; 23 | import com.azure.core.util.serializer.SerializerEncoding; 24 | import com.azure.resourcemanager.AzureResourceManager; 25 | import com.azure.resourcemanager.appplatform.models.ConfigServerProperties; 26 | import com.azure.resourcemanager.appplatform.models.ConfigServerState; 27 | import com.azure.resourcemanager.appplatform.models.MonitoringSettingProperties; 28 | import com.azure.resourcemanager.appplatform.models.MonitoringSettingState; 29 | import com.azure.resourcemanager.appplatform.models.SpringApp; 30 | import com.azure.resourcemanager.appplatform.models.SpringService; 31 | import com.azure.resourcemanager.appservice.models.AppServiceCertificateOrder; 32 | import com.azure.resourcemanager.appservice.models.AppServiceDomain; 33 | import com.azure.resourcemanager.appservice.models.AppServicePlan; 34 | import com.azure.resourcemanager.appservice.models.AppSetting; 35 | import com.azure.resourcemanager.appservice.models.ConnectionString; 36 | import com.azure.resourcemanager.appservice.models.Contact; 37 | import com.azure.resourcemanager.appservice.models.HostnameBinding; 38 | import com.azure.resourcemanager.appservice.models.HostnameSslState; 39 | import com.azure.resourcemanager.appservice.models.PublishingProfile; 40 | import com.azure.resourcemanager.appservice.models.SslState; 41 | import com.azure.resourcemanager.appservice.models.WebAppBase; 42 | import com.azure.resourcemanager.appservice.models.WebSiteBase; 43 | import com.azure.resourcemanager.authorization.models.ActiveDirectoryApplication; 44 | import com.azure.resourcemanager.authorization.models.ActiveDirectoryGroup; 45 | import com.azure.resourcemanager.authorization.models.ActiveDirectoryObject; 46 | import com.azure.resourcemanager.authorization.models.ActiveDirectoryUser; 47 | import com.azure.resourcemanager.authorization.models.Permission; 48 | import com.azure.resourcemanager.authorization.models.RoleAssignment; 49 | import com.azure.resourcemanager.authorization.models.RoleDefinition; 50 | import com.azure.resourcemanager.authorization.models.ServicePrincipal; 51 | import com.azure.resourcemanager.compute.models.AvailabilitySet; 52 | import com.azure.resourcemanager.compute.models.DataDisk; 53 | import com.azure.resourcemanager.compute.models.ImageDataDisk; 54 | import com.azure.resourcemanager.compute.models.VirtualMachine; 55 | import com.azure.resourcemanager.compute.models.VirtualMachineCustomImage; 56 | import com.azure.resourcemanager.compute.models.VirtualMachineExtension; 57 | import com.azure.resourcemanager.containerinstance.models.Container; 58 | import com.azure.resourcemanager.containerinstance.models.ContainerGroup; 59 | import com.azure.resourcemanager.containerinstance.models.ContainerPort; 60 | import com.azure.resourcemanager.containerinstance.models.EnvironmentVariable; 61 | import com.azure.resourcemanager.containerinstance.models.Volume; 62 | import com.azure.resourcemanager.containerinstance.models.VolumeMount; 63 | import com.azure.resourcemanager.containerregistry.models.AccessKeyType; 64 | import com.azure.resourcemanager.containerregistry.models.Registry; 65 | import com.azure.resourcemanager.containerregistry.models.RegistryCredentials; 66 | import com.azure.resourcemanager.containerservice.models.KubernetesCluster; 67 | import com.azure.resourcemanager.cosmos.models.CosmosDBAccount; 68 | import com.azure.resourcemanager.cosmos.models.DatabaseAccountListKeysResult; 69 | import com.azure.resourcemanager.cosmos.models.DatabaseAccountListReadOnlyKeysResult; 70 | import com.azure.resourcemanager.cosmos.models.Location; 71 | import com.azure.resourcemanager.dns.models.ARecordSet; 72 | import com.azure.resourcemanager.dns.models.AaaaRecordSet; 73 | import com.azure.resourcemanager.dns.models.CnameRecordSet; 74 | import com.azure.resourcemanager.dns.models.DnsZone; 75 | import com.azure.resourcemanager.dns.models.MxRecord; 76 | import com.azure.resourcemanager.dns.models.MxRecordSet; 77 | import com.azure.resourcemanager.dns.models.NsRecordSet; 78 | import com.azure.resourcemanager.dns.models.PtrRecordSet; 79 | import com.azure.resourcemanager.dns.models.SoaRecord; 80 | import com.azure.resourcemanager.dns.models.SoaRecordSet; 81 | import com.azure.resourcemanager.dns.models.SrvRecord; 82 | import com.azure.resourcemanager.dns.models.SrvRecordSet; 83 | import com.azure.resourcemanager.dns.models.TxtRecord; 84 | import com.azure.resourcemanager.dns.models.TxtRecordSet; 85 | import com.azure.resourcemanager.eventhubs.models.AccessRights; 86 | import com.azure.resourcemanager.eventhubs.models.DisasterRecoveryPairingAuthorizationKey; 87 | import com.azure.resourcemanager.eventhubs.models.DisasterRecoveryPairingAuthorizationRule; 88 | import com.azure.resourcemanager.eventhubs.models.EventHub; 89 | import com.azure.resourcemanager.eventhubs.models.EventHubConsumerGroup; 90 | import com.azure.resourcemanager.eventhubs.models.EventHubDisasterRecoveryPairing; 91 | import com.azure.resourcemanager.eventhubs.models.EventHubNamespace; 92 | import com.azure.resourcemanager.keyvault.models.AccessPolicy; 93 | import com.azure.resourcemanager.keyvault.models.CertificatePermissions; 94 | import com.azure.resourcemanager.keyvault.models.KeyPermissions; 95 | import com.azure.resourcemanager.keyvault.models.SecretPermissions; 96 | import com.azure.resourcemanager.keyvault.models.Vault; 97 | import com.azure.resourcemanager.monitor.models.ActionGroup; 98 | import com.azure.resourcemanager.monitor.models.ActivityLogAlert; 99 | import com.azure.resourcemanager.monitor.models.AutomationRunbookReceiver; 100 | import com.azure.resourcemanager.monitor.models.AzureAppPushReceiver; 101 | import com.azure.resourcemanager.monitor.models.AzureFunctionReceiver; 102 | import com.azure.resourcemanager.monitor.models.DiagnosticSetting; 103 | import com.azure.resourcemanager.monitor.models.EmailReceiver; 104 | import com.azure.resourcemanager.monitor.models.ItsmReceiver; 105 | import com.azure.resourcemanager.monitor.models.LogSettings; 106 | import com.azure.resourcemanager.monitor.models.LogicAppReceiver; 107 | import com.azure.resourcemanager.monitor.models.MetricAlert; 108 | import com.azure.resourcemanager.monitor.models.MetricAlertCondition; 109 | import com.azure.resourcemanager.monitor.models.MetricDimension; 110 | import com.azure.resourcemanager.monitor.models.MetricSettings; 111 | import com.azure.resourcemanager.monitor.models.SmsReceiver; 112 | import com.azure.resourcemanager.monitor.models.VoiceReceiver; 113 | import com.azure.resourcemanager.monitor.models.WebhookReceiver; 114 | import com.azure.resourcemanager.msi.models.Identity; 115 | import com.azure.resourcemanager.network.fluent.models.SecurityRuleInner; 116 | import com.azure.resourcemanager.network.models.ApplicationGateway; 117 | import com.azure.resourcemanager.network.models.ApplicationGatewayBackend; 118 | import com.azure.resourcemanager.network.models.ApplicationGatewayBackendAddress; 119 | import com.azure.resourcemanager.network.models.ApplicationGatewayBackendHttpConfiguration; 120 | import com.azure.resourcemanager.network.models.ApplicationGatewayFrontend; 121 | import com.azure.resourcemanager.network.models.ApplicationGatewayIpConfiguration; 122 | import com.azure.resourcemanager.network.models.ApplicationGatewayListener; 123 | import com.azure.resourcemanager.network.models.ApplicationGatewayProbe; 124 | import com.azure.resourcemanager.network.models.ApplicationGatewayRedirectConfiguration; 125 | import com.azure.resourcemanager.network.models.ApplicationGatewayRequestRoutingRule; 126 | import com.azure.resourcemanager.network.models.ApplicationGatewaySslCertificate; 127 | import com.azure.resourcemanager.network.models.CustomDnsConfigPropertiesFormat; 128 | import com.azure.resourcemanager.network.models.EffectiveNetworkSecurityRule; 129 | import com.azure.resourcemanager.network.models.FlowLogSettings; 130 | import com.azure.resourcemanager.network.models.LoadBalancer; 131 | import com.azure.resourcemanager.network.models.LoadBalancerBackend; 132 | import com.azure.resourcemanager.network.models.LoadBalancerFrontend; 133 | import com.azure.resourcemanager.network.models.LoadBalancerHttpProbe; 134 | import com.azure.resourcemanager.network.models.LoadBalancerInboundNatPool; 135 | import com.azure.resourcemanager.network.models.LoadBalancerInboundNatRule; 136 | import com.azure.resourcemanager.network.models.LoadBalancerPrivateFrontend; 137 | import com.azure.resourcemanager.network.models.LoadBalancerProbe; 138 | import com.azure.resourcemanager.network.models.LoadBalancerPublicFrontend; 139 | import com.azure.resourcemanager.network.models.LoadBalancerTcpProbe; 140 | import com.azure.resourcemanager.network.models.LoadBalancingRule; 141 | import com.azure.resourcemanager.network.models.Network; 142 | import com.azure.resourcemanager.network.models.NetworkInterface; 143 | import com.azure.resourcemanager.network.models.NetworkPeering; 144 | import com.azure.resourcemanager.network.models.NetworkSecurityGroup; 145 | import com.azure.resourcemanager.network.models.NetworkSecurityRule; 146 | import com.azure.resourcemanager.network.models.NetworkWatcher; 147 | import com.azure.resourcemanager.network.models.NextHop; 148 | import com.azure.resourcemanager.network.models.PacketCapture; 149 | import com.azure.resourcemanager.network.models.PacketCaptureFilter; 150 | import com.azure.resourcemanager.network.models.PrivateEndpoint; 151 | import com.azure.resourcemanager.network.models.PublicIpAddress; 152 | import com.azure.resourcemanager.network.models.RouteTable; 153 | import com.azure.resourcemanager.network.models.SecurityGroupNetworkInterface; 154 | import com.azure.resourcemanager.network.models.SecurityGroupView; 155 | import com.azure.resourcemanager.network.models.ServiceEndpointType; 156 | import com.azure.resourcemanager.network.models.Subnet; 157 | import com.azure.resourcemanager.network.models.Topology; 158 | import com.azure.resourcemanager.network.models.TopologyAssociation; 159 | import com.azure.resourcemanager.network.models.TopologyResource; 160 | import com.azure.resourcemanager.network.models.VerificationIPFlow; 161 | import com.azure.resourcemanager.privatedns.models.PrivateDnsZone; 162 | import com.azure.resourcemanager.privatedns.models.VirtualNetworkLink; 163 | import com.azure.resourcemanager.redis.models.RedisAccessKeys; 164 | import com.azure.resourcemanager.redis.models.RedisCache; 165 | import com.azure.resourcemanager.redis.models.RedisCachePremium; 166 | import com.azure.resourcemanager.redis.models.ScheduleEntry; 167 | import com.azure.resourcemanager.resources.fluentcore.arm.models.PrivateLinkResource; 168 | import com.azure.resourcemanager.resources.fluentcore.utils.ResourceManagerUtils; 169 | import com.azure.resourcemanager.resources.models.ManagementLock; 170 | import com.azure.resourcemanager.resources.models.ResourceGroup; 171 | import com.azure.resourcemanager.search.models.AdminKeys; 172 | import com.azure.resourcemanager.search.models.QueryKey; 173 | import com.azure.resourcemanager.search.models.SearchService; 174 | import com.azure.resourcemanager.servicebus.models.AuthorizationKeys; 175 | import com.azure.resourcemanager.servicebus.models.NamespaceAuthorizationRule; 176 | import com.azure.resourcemanager.servicebus.models.Queue; 177 | import com.azure.resourcemanager.servicebus.models.QueueAuthorizationRule; 178 | import com.azure.resourcemanager.servicebus.models.ServiceBusNamespace; 179 | import com.azure.resourcemanager.servicebus.models.ServiceBusSubscription; 180 | import com.azure.resourcemanager.servicebus.models.Topic; 181 | import com.azure.resourcemanager.servicebus.models.TopicAuthorizationRule; 182 | import com.azure.resourcemanager.sql.models.ElasticPoolActivity; 183 | import com.azure.resourcemanager.sql.models.ElasticPoolDatabaseActivity; 184 | import com.azure.resourcemanager.sql.models.PartnerInfo; 185 | import com.azure.resourcemanager.sql.models.SqlDatabase; 186 | import com.azure.resourcemanager.sql.models.SqlDatabaseMetric; 187 | import com.azure.resourcemanager.sql.models.SqlDatabaseMetricValue; 188 | import com.azure.resourcemanager.sql.models.SqlDatabaseUsageMetric; 189 | import com.azure.resourcemanager.sql.models.SqlElasticPool; 190 | import com.azure.resourcemanager.sql.models.SqlFailoverGroup; 191 | import com.azure.resourcemanager.sql.models.SqlFirewallRule; 192 | import com.azure.resourcemanager.sql.models.SqlServer; 193 | import com.azure.resourcemanager.sql.models.SqlServerKey; 194 | import com.azure.resourcemanager.sql.models.SqlSubscriptionUsageMetric; 195 | import com.azure.resourcemanager.sql.models.SqlVirtualNetworkRule; 196 | import com.azure.resourcemanager.storage.models.StorageAccount; 197 | import com.azure.resourcemanager.storage.models.StorageAccountEncryptionStatus; 198 | import com.azure.resourcemanager.storage.models.StorageAccountKey; 199 | import com.azure.resourcemanager.storage.models.StorageService; 200 | import com.azure.resourcemanager.trafficmanager.models.TrafficManagerAzureEndpoint; 201 | import com.azure.resourcemanager.trafficmanager.models.TrafficManagerExternalEndpoint; 202 | import com.azure.resourcemanager.trafficmanager.models.TrafficManagerNestedProfileEndpoint; 203 | import com.azure.resourcemanager.trafficmanager.models.TrafficManagerProfile; 204 | import org.apache.commons.net.ftp.FTP; 205 | import org.apache.commons.net.ftp.FTPClient; 206 | import reactor.core.publisher.Mono; 207 | import reactor.util.retry.Retry; 208 | 209 | import java.io.BufferedReader; 210 | import java.io.ByteArrayOutputStream; 211 | import java.io.DataOutputStream; 212 | import java.io.File; 213 | import java.io.FileInputStream; 214 | import java.io.IOException; 215 | import java.io.InputStream; 216 | import java.io.InputStreamReader; 217 | import java.nio.charset.StandardCharsets; 218 | import java.nio.file.Files; 219 | import java.security.KeyPair; 220 | import java.security.KeyPairGenerator; 221 | import java.security.NoSuchAlgorithmException; 222 | import java.security.PublicKey; 223 | import java.security.interfaces.RSAPublicKey; 224 | import java.time.Duration; 225 | import java.time.temporal.ChronoUnit; 226 | import java.util.ArrayList; 227 | import java.util.Arrays; 228 | import java.util.Base64; 229 | import java.util.Collection; 230 | import java.util.HashMap; 231 | import java.util.Iterator; 232 | import java.util.List; 233 | import java.util.Map; 234 | import java.util.Properties; 235 | import java.util.Set; 236 | import java.util.concurrent.TimeoutException; 237 | import java.util.stream.Collectors; 238 | 239 | /** 240 | * Common utils for Azure management samples. 241 | */ 242 | public final class Utils { 243 | 244 | // IMPORTANT: do not use SSHShell in Utils 245 | 246 | private static final ClientLogger LOGGER = new ClientLogger(Utils.class); 247 | 248 | private static String sshPublicKey; 249 | 250 | private Utils() { 251 | } 252 | 253 | /** @return a generated password */ 254 | public static String password() { 255 | String password = new ResourceManagerUtils.InternalRuntimeContext().randomResourceName("Pa5$", 12); 256 | System.out.printf("Password: %s%n", password); 257 | return password; 258 | } 259 | 260 | /** 261 | * @return an SSH public key 262 | */ 263 | public static String sshPublicKey() { 264 | if (sshPublicKey == null) { 265 | try { 266 | KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA"); 267 | keyGen.initialize(1024); 268 | KeyPair pair = keyGen.generateKeyPair(); 269 | PublicKey publicKey = pair.getPublic(); 270 | 271 | RSAPublicKey rsaPublicKey = (RSAPublicKey) publicKey; 272 | ByteArrayOutputStream byteOs = new ByteArrayOutputStream(); 273 | DataOutputStream dos = new DataOutputStream(byteOs); 274 | dos.writeInt("ssh-rsa".getBytes(StandardCharsets.US_ASCII).length); 275 | dos.write("ssh-rsa".getBytes(StandardCharsets.US_ASCII)); 276 | dos.writeInt(rsaPublicKey.getPublicExponent().toByteArray().length); 277 | dos.write(rsaPublicKey.getPublicExponent().toByteArray()); 278 | dos.writeInt(rsaPublicKey.getModulus().toByteArray().length); 279 | dos.write(rsaPublicKey.getModulus().toByteArray()); 280 | String publicKeyEncoded = new String(Base64.getEncoder().encode(byteOs.toByteArray()), StandardCharsets.US_ASCII); 281 | sshPublicKey = "ssh-rsa " + publicKeyEncoded; 282 | } catch (NoSuchAlgorithmException | IOException e) { 283 | throw LOGGER.logExceptionAsError(new IllegalStateException("failed to generate ssh key", e)); 284 | } 285 | } 286 | return sshPublicKey; 287 | } 288 | 289 | /** 290 | * Creates a randomized resource name. 291 | * Please provider your own implementation, or avoid using the method, if code is to be used in production. 292 | * 293 | * @param azure the AzureResourceManager instance. 294 | * @param prefix the prefix to the name. 295 | * @param maxLen the max length of the name. 296 | * @return the randomized resource name. 297 | */ 298 | public static String randomResourceName(AzureResourceManager azure, String prefix, int maxLen) { 299 | return azure.resourceGroups().manager().internalContext().randomResourceName(prefix, maxLen); 300 | } 301 | 302 | /** 303 | * Generates the specified number of random resource names with the same prefix. 304 | * Please provider your own implementation, or avoid using the method, if code is to be used in production. 305 | * 306 | * @param azure the AzureResourceManager instance. 307 | * @param prefix the prefix to be used if possible 308 | * @param maxLen the maximum length for the random generated name 309 | * @param count the number of names to generate 310 | * @return the randomized resource names. 311 | */ 312 | public static String[] randomResourceNames(AzureResourceManager azure, String prefix, int maxLen, int count) { 313 | String[] names = new String[count]; 314 | for (int i = 0; i < count; i++) { 315 | names[i] = randomResourceName(azure, prefix, maxLen); 316 | } 317 | return names; 318 | } 319 | 320 | /** 321 | * Creates a random UUID. 322 | * Please provider your own implementation, or avoid using the method, if code is to be used in production. 323 | * 324 | * @param azure the AzureResourceManager instance. 325 | * @return the random UUID. 326 | */ 327 | public static String randomUuid(AzureResourceManager azure) { 328 | return azure.resourceGroups().manager().internalContext().randomUuid(); 329 | } 330 | 331 | /** 332 | * Creates a randomized resource name. 333 | * Please provider your own implementation, or avoid using the method, if code is to be used in production. 334 | * 335 | * @param authenticated the AzureResourceManager.Authenticated instance. 336 | * @param prefix the prefix to the name. 337 | * @param maxLen the max length of the name. 338 | * @return the randomized resource name. 339 | */ 340 | public static String randomResourceName(AzureResourceManager.Authenticated authenticated, String prefix, int maxLen) { 341 | return authenticated.roleAssignments().manager().internalContext().randomResourceName(prefix, maxLen); 342 | } 343 | 344 | /** 345 | * Print resource group info. 346 | * 347 | * @param resource a resource group 348 | */ 349 | public static void print(ResourceGroup resource) { 350 | StringBuilder info = new StringBuilder(); 351 | info.append("Resource Group: ").append(resource.id()) 352 | .append("\n\tName: ").append(resource.name()) 353 | .append("\n\tRegion: ").append(resource.region()) 354 | .append("\n\tTags: ").append(resource.tags()); 355 | System.out.println(info.toString()); 356 | } 357 | 358 | /** 359 | * Print User Assigned MSI info. 360 | * 361 | * @param resource a User Assigned MSI 362 | */ 363 | public static void print(Identity resource) { 364 | StringBuilder info = new StringBuilder(); 365 | info.append("Resource Group: ").append(resource.id()) 366 | .append("\n\tName: ").append(resource.name()) 367 | .append("\n\tRegion: ").append(resource.region()) 368 | .append("\n\tTags: ").append(resource.tags()) 369 | .append("\n\tService Principal Id: ").append(resource.principalId()) 370 | .append("\n\tClient Id: ").append(resource.clientId()) 371 | .append("\n\tTenant Id: ").append(resource.tenantId()); 372 | System.out.println(info.toString()); 373 | } 374 | 375 | /** 376 | * Print virtual machine info. 377 | * 378 | * @param resource a virtual machine 379 | */ 380 | public static void print(VirtualMachine resource) { 381 | 382 | StringBuilder storageProfile = new StringBuilder().append("\n\tStorageProfile: "); 383 | if (resource.storageProfile().imageReference() != null) { 384 | storageProfile.append("\n\t\tImageReference:"); 385 | storageProfile.append("\n\t\t\tPublisher: ").append(resource.storageProfile().imageReference().publisher()); 386 | storageProfile.append("\n\t\t\tOffer: ").append(resource.storageProfile().imageReference().offer()); 387 | storageProfile.append("\n\t\t\tSKU: ").append(resource.storageProfile().imageReference().sku()); 388 | storageProfile.append("\n\t\t\tVersion: ").append(resource.storageProfile().imageReference().version()); 389 | } 390 | 391 | if (resource.storageProfile().osDisk() != null) { 392 | storageProfile.append("\n\t\tOSDisk:"); 393 | storageProfile.append("\n\t\t\tOSType: ").append(resource.storageProfile().osDisk().osType()); 394 | storageProfile.append("\n\t\t\tName: ").append(resource.storageProfile().osDisk().name()); 395 | storageProfile.append("\n\t\t\tCaching: ").append(resource.storageProfile().osDisk().caching()); 396 | storageProfile.append("\n\t\t\tCreateOption: ").append(resource.storageProfile().osDisk().createOption()); 397 | storageProfile.append("\n\t\t\tDiskSizeGB: ").append(resource.storageProfile().osDisk().diskSizeGB()); 398 | if (resource.storageProfile().osDisk().managedDisk() != null) { 399 | if (resource.storageProfile().osDisk().managedDisk().diskEncryptionSet() != null) { 400 | storageProfile.append("\n\t\t\tDiskEncryptionSet Id: ") 401 | .append(resource.storageProfile().osDisk().managedDisk().diskEncryptionSet().id()); 402 | } 403 | } 404 | if (resource.storageProfile().osDisk().image() != null) { 405 | storageProfile.append("\n\t\t\tImage Uri: ").append(resource.storageProfile().osDisk().image().uri()); 406 | } 407 | if (resource.storageProfile().osDisk().vhd() != null) { 408 | storageProfile.append("\n\t\t\tVhd Uri: ").append(resource.storageProfile().osDisk().vhd().uri()); 409 | } 410 | if (resource.storageProfile().osDisk().encryptionSettings() != null) { 411 | storageProfile.append("\n\t\t\tEncryptionSettings: "); 412 | storageProfile.append("\n\t\t\t\tEnabled: ").append(resource.storageProfile().osDisk().encryptionSettings().enabled()); 413 | storageProfile.append("\n\t\t\t\tDiskEncryptionKey Uri: ").append(resource 414 | .storageProfile() 415 | .osDisk() 416 | .encryptionSettings() 417 | .diskEncryptionKey().secretUrl()); 418 | storageProfile.append("\n\t\t\t\tKeyEncryptionKey Uri: ").append(resource 419 | .storageProfile() 420 | .osDisk() 421 | .encryptionSettings() 422 | .keyEncryptionKey().keyUrl()); 423 | } 424 | } 425 | 426 | if (resource.storageProfile().dataDisks() != null) { 427 | int i = 0; 428 | for (DataDisk disk : resource.storageProfile().dataDisks()) { 429 | storageProfile.append("\n\t\tDataDisk: #").append(i++); 430 | storageProfile.append("\n\t\t\tName: ").append(disk.name()); 431 | storageProfile.append("\n\t\t\tCaching: ").append(disk.caching()); 432 | storageProfile.append("\n\t\t\tCreateOption: ").append(disk.createOption()); 433 | storageProfile.append("\n\t\t\tDiskSizeGB: ").append(disk.diskSizeGB()); 434 | storageProfile.append("\n\t\t\tLun: ").append(disk.lun()); 435 | if (resource.isManagedDiskEnabled()) { 436 | if (disk.managedDisk() != null) { 437 | storageProfile.append("\n\t\t\tManaged Disk Id: ").append(disk.managedDisk().id()); 438 | if (disk.managedDisk().diskEncryptionSet() != null) { 439 | storageProfile.append("\n\t\t\tDiskEncryptionSet Id: ").append(disk.managedDisk().diskEncryptionSet().id()); 440 | } 441 | } 442 | } else { 443 | if (disk.vhd().uri() != null) { 444 | storageProfile.append("\n\t\t\tVhd Uri: ").append(disk.vhd().uri()); 445 | } 446 | } 447 | if (disk.image() != null) { 448 | storageProfile.append("\n\t\t\tImage Uri: ").append(disk.image().uri()); 449 | } 450 | } 451 | } 452 | 453 | StringBuilder osProfile = new StringBuilder().append("\n\tOSProfile: "); 454 | if (resource.osProfile() != null) { 455 | osProfile.append("\n\t\tComputerName:").append(resource.osProfile().computerName()); 456 | if (resource.osProfile().windowsConfiguration() != null) { 457 | osProfile.append("\n\t\t\tWindowsConfiguration: "); 458 | osProfile.append("\n\t\t\t\tProvisionVMAgent: ") 459 | .append(resource.osProfile().windowsConfiguration().provisionVMAgent()); 460 | osProfile.append("\n\t\t\t\tEnableAutomaticUpdates: ") 461 | .append(resource.osProfile().windowsConfiguration().enableAutomaticUpdates()); 462 | osProfile.append("\n\t\t\t\tTimeZone: ") 463 | .append(resource.osProfile().windowsConfiguration().timeZone()); 464 | } 465 | 466 | if (resource.osProfile().linuxConfiguration() != null) { 467 | osProfile.append("\n\t\t\tLinuxConfiguration: "); 468 | osProfile.append("\n\t\t\t\tDisablePasswordAuthentication: ") 469 | .append(resource.osProfile().linuxConfiguration().disablePasswordAuthentication()); 470 | } 471 | } else { 472 | // OSProfile will be null for a VM attached to specialized VHD. 473 | osProfile.append("null"); 474 | } 475 | 476 | StringBuilder networkProfile = new StringBuilder().append("\n\tNetworkProfile: "); 477 | for (String networkInterfaceId : resource.networkInterfaceIds()) { 478 | networkProfile.append("\n\t\tId:").append(networkInterfaceId); 479 | } 480 | 481 | StringBuilder extensions = new StringBuilder().append("\n\tExtensions: "); 482 | for (Map.Entry extensionEntry : resource.listExtensions().entrySet()) { 483 | VirtualMachineExtension extension = extensionEntry.getValue(); 484 | extensions.append("\n\t\tExtension: ").append(extension.id()) 485 | .append("\n\t\t\tName: ").append(extension.name()) 486 | .append("\n\t\t\tTags: ").append(extension.tags()) 487 | .append("\n\t\t\tProvisioningState: ").append(extension.provisioningState()) 488 | .append("\n\t\t\tAuto upgrade minor version enabled: ").append(extension.autoUpgradeMinorVersionEnabled()) 489 | .append("\n\t\t\tPublisher: ").append(extension.publisherName()) 490 | .append("\n\t\t\tType: ").append(extension.typeName()) 491 | .append("\n\t\t\tVersion: ").append(extension.versionName()) 492 | .append("\n\t\t\tPublic Settings: ").append(extension.publicSettingsAsJsonString()); 493 | } 494 | 495 | StringBuilder msi = new StringBuilder().append("\n\tMSI: "); 496 | msi.append("\n\t\t\tMSI enabled:").append(resource.isManagedServiceIdentityEnabled()); 497 | msi.append("\n\t\t\tSystem Assigned MSI Active Directory Service Principal Id:").append(resource.systemAssignedManagedServiceIdentityPrincipalId()); 498 | msi.append("\n\t\t\tSystem Assigned MSI Active Directory Tenant Id:").append(resource.systemAssignedManagedServiceIdentityTenantId()); 499 | 500 | StringBuilder zones = new StringBuilder().append("\n\tZones: "); 501 | zones.append(resource.availabilityZones()); 502 | 503 | System.out.println(new StringBuilder().append("Virtual Machine: ").append(resource.id()) 504 | .append("Name: ").append(resource.name()) 505 | .append("\n\tResource group: ").append(resource.resourceGroupName()) 506 | .append("\n\tRegion: ").append(resource.region()) 507 | .append("\n\tTags: ").append(resource.tags()) 508 | .append("\n\tHardwareProfile: ") 509 | .append("\n\t\tSize: ").append(resource.size()) 510 | .append(storageProfile) 511 | .append(osProfile) 512 | .append(networkProfile) 513 | .append(extensions) 514 | .append(msi) 515 | .append(zones) 516 | .toString()); 517 | } 518 | 519 | 520 | /** 521 | * Print availability set info. 522 | * 523 | * @param resource an availability set 524 | */ 525 | public static void print(AvailabilitySet resource) { 526 | 527 | System.out.println(new StringBuilder().append("Availability Set: ").append(resource.id()) 528 | .append("Name: ").append(resource.name()) 529 | .append("\n\tResource group: ").append(resource.resourceGroupName()) 530 | .append("\n\tRegion: ").append(resource.region()) 531 | .append("\n\tTags: ").append(resource.tags()) 532 | .append("\n\tFault domain count: ").append(resource.faultDomainCount()) 533 | .append("\n\tUpdate domain count: ").append(resource.updateDomainCount()) 534 | .toString()); 535 | } 536 | 537 | /** 538 | * Print network info. 539 | * 540 | * @param resource a network 541 | * @throws ManagementException Cloud errors 542 | */ 543 | public static void print(Network resource) { 544 | StringBuilder info = new StringBuilder(); 545 | info.append("Network: ").append(resource.id()) 546 | .append("Name: ").append(resource.name()) 547 | .append("\n\tResource group: ").append(resource.resourceGroupName()) 548 | .append("\n\tRegion: ").append(resource.region()) 549 | .append("\n\tTags: ").append(resource.tags()) 550 | .append("\n\tAddress spaces: ").append(resource.addressSpaces()) 551 | .append("\n\tDNS server IPs: ").append(resource.dnsServerIPs()); 552 | 553 | // Output subnets 554 | for (Subnet subnet : resource.subnets().values()) { 555 | info.append("\n\tSubnet: ").append(subnet.name()) 556 | .append("\n\t\tAddress prefix: ").append(subnet.addressPrefix()); 557 | 558 | // Output associated NSG 559 | NetworkSecurityGroup subnetNsg = subnet.getNetworkSecurityGroup(); 560 | if (subnetNsg != null) { 561 | info.append("\n\t\tNetwork security group ID: ").append(subnetNsg.id()); 562 | } 563 | 564 | // Output associated route table 565 | RouteTable routeTable = subnet.getRouteTable(); 566 | if (routeTable != null) { 567 | info.append("\n\tRoute table ID: ").append(routeTable.id()); 568 | } 569 | 570 | // Output services with access 571 | Map> services = subnet.servicesWithAccess(); 572 | if (services.size() > 0) { 573 | info.append("\n\tServices with access"); 574 | for (Map.Entry> service : services.entrySet()) { 575 | info.append("\n\t\tService: ") 576 | .append(service.getKey()) 577 | .append(" Regions: " + service.getValue() + ""); 578 | } 579 | } 580 | } 581 | 582 | // Output peerings 583 | for (NetworkPeering peering : resource.peerings().list()) { 584 | info.append("\n\tPeering: ").append(peering.name()) 585 | .append("\n\t\tRemote network ID: ").append(peering.remoteNetworkId()) 586 | .append("\n\t\tPeering state: ").append(peering.state()) 587 | .append("\n\t\tIs traffic forwarded from remote network allowed? ").append(peering.isTrafficForwardingFromRemoteNetworkAllowed()) 588 | .append("\n\t\tGateway use: ").append(peering.gatewayUse()); 589 | } 590 | System.out.println(info.toString()); 591 | } 592 | 593 | /** 594 | * Print network interface. 595 | * 596 | * @param resource a network interface 597 | */ 598 | public static void print(NetworkInterface resource) { 599 | StringBuilder info = new StringBuilder(); 600 | info.append("NetworkInterface: ").append(resource.id()) 601 | .append("Name: ").append(resource.name()) 602 | .append("\n\tResource group: ").append(resource.resourceGroupName()) 603 | .append("\n\tRegion: ").append(resource.region()) 604 | .append("\n\tTags: ").append(resource.tags()) 605 | .append("\n\tInternal DNS name label: ").append(resource.internalDnsNameLabel()) 606 | .append("\n\tInternal FQDN: ").append(resource.internalFqdn()) 607 | .append("\n\tInternal domain name suffix: ").append(resource.internalDomainNameSuffix()) 608 | .append("\n\tNetwork security group: ").append(resource.networkSecurityGroupId()) 609 | .append("\n\tApplied DNS servers: ").append(resource.appliedDnsServers().toString()) 610 | .append("\n\tDNS server IPs: "); 611 | 612 | // Output dns servers 613 | for (String dnsServerIp : resource.dnsServers()) { 614 | info.append("\n\t\t").append(dnsServerIp); 615 | } 616 | 617 | info.append("\n\tIP forwarding enabled? ").append(resource.isIPForwardingEnabled()) 618 | .append("\n\tAccelerated networking enabled? ").append(resource.isAcceleratedNetworkingEnabled()) 619 | .append("\n\tMAC Address:").append(resource.macAddress()) 620 | .append("\n\tPrivate IP:").append(resource.primaryPrivateIP()) 621 | .append("\n\tPrivate allocation method:").append(resource.primaryPrivateIpAllocationMethod()) 622 | .append("\n\tPrimary virtual network ID: ").append(resource.primaryIPConfiguration().networkId()) 623 | .append("\n\tPrimary subnet name:").append(resource.primaryIPConfiguration().subnetName()); 624 | 625 | System.out.println(info.toString()); 626 | } 627 | 628 | /** 629 | * Print network security group. 630 | * 631 | * @param resource a network security group 632 | */ 633 | public static void print(NetworkSecurityGroup resource) { 634 | StringBuilder info = new StringBuilder(); 635 | info.append("NSG: ").append(resource.id()) 636 | .append("Name: ").append(resource.name()) 637 | .append("\n\tResource group: ").append(resource.resourceGroupName()) 638 | .append("\n\tRegion: ").append(resource.region()) 639 | .append("\n\tTags: ").append(resource.tags()); 640 | 641 | // Output security rules 642 | for (NetworkSecurityRule rule : resource.securityRules().values()) { 643 | info.append("\n\tRule: ").append(rule.name()) 644 | .append("\n\t\tAccess: ").append(rule.access()) 645 | .append("\n\t\tDirection: ").append(rule.direction()) 646 | .append("\n\t\tFrom address: ").append(rule.sourceAddressPrefix()) 647 | .append("\n\t\tFrom port range: ").append(rule.sourcePortRange()) 648 | .append("\n\t\tTo address: ").append(rule.destinationAddressPrefix()) 649 | .append("\n\t\tTo port: ").append(rule.destinationPortRange()) 650 | .append("\n\t\tProtocol: ").append(rule.protocol()) 651 | .append("\n\t\tPriority: ").append(rule.priority()); 652 | } 653 | 654 | System.out.println(info.toString()); 655 | } 656 | 657 | /** 658 | * Print public IP address. 659 | * 660 | * @param resource a public IP address 661 | */ 662 | public static void print(PublicIpAddress resource) { 663 | System.out.println(new StringBuilder().append("Public IP Address: ").append(resource.id()) 664 | .append("Name: ").append(resource.name()) 665 | .append("\n\tResource group: ").append(resource.resourceGroupName()) 666 | .append("\n\tRegion: ").append(resource.region()) 667 | .append("\n\tTags: ").append(resource.tags()) 668 | .append("\n\tIP Address: ").append(resource.ipAddress()) 669 | .append("\n\tLeaf domain label: ").append(resource.leafDomainLabel()) 670 | .append("\n\tFQDN: ").append(resource.fqdn()) 671 | .append("\n\tReverse FQDN: ").append(resource.reverseFqdn()) 672 | .append("\n\tIdle timeout (minutes): ").append(resource.idleTimeoutInMinutes()) 673 | .append("\n\tIP allocation method: ").append(resource.ipAllocationMethod()) 674 | .append("\n\tZones: ").append(resource.availabilityZones()) 675 | .toString()); 676 | } 677 | 678 | /** 679 | * Print a key vault. 680 | * 681 | * @param vault the key vault resource 682 | */ 683 | public static void print(Vault vault) { 684 | StringBuilder info = new StringBuilder().append("Key Vault: ").append(vault.id()) 685 | .append("Name: ").append(vault.name()) 686 | .append("\n\tResource group: ").append(vault.resourceGroupName()) 687 | .append("\n\tRegion: ").append(vault.region()) 688 | .append("\n\tSku: ").append(vault.sku().name()).append(" - ").append(vault.sku().family()) 689 | .append("\n\tVault URI: ").append(vault.vaultUri()) 690 | .append("\n\tAccess policies: "); 691 | for (AccessPolicy accessPolicy : vault.accessPolicies()) { 692 | info.append("\n\t\tIdentity:").append(accessPolicy.objectId()); 693 | if (accessPolicy.permissions() != null) { 694 | if (accessPolicy.permissions().keys() != null) { 695 | info.append("\n\t\tKey permissions: ").append(accessPolicy.permissions().keys().stream().map(KeyPermissions::toString).collect(Collectors.joining(", "))); 696 | } 697 | if (accessPolicy.permissions().secrets() != null) { 698 | info.append("\n\t\tSecret permissions: ").append(accessPolicy.permissions().secrets().stream().map(SecretPermissions::toString).collect(Collectors.joining(", "))); 699 | } 700 | if (accessPolicy.permissions().certificates() != null) { 701 | info.append("\n\t\tCertificate permissions: ").append(accessPolicy.permissions().certificates().stream().map(CertificatePermissions::toString).collect(Collectors.joining(", "))); 702 | } 703 | } 704 | } 705 | System.out.println(info.toString()); 706 | } 707 | 708 | /** 709 | * Print storage account. 710 | * 711 | * @param storageAccount a storage account 712 | */ 713 | public static void print(StorageAccount storageAccount) { 714 | System.out.println(storageAccount.name() 715 | + " created @ " + storageAccount.creationTime()); 716 | 717 | StringBuilder info = new StringBuilder().append("Storage Account: ").append(storageAccount.id()) 718 | .append("Name: ").append(storageAccount.name()) 719 | .append("\n\tResource group: ").append(storageAccount.resourceGroupName()) 720 | .append("\n\tRegion: ").append(storageAccount.region()) 721 | .append("\n\tSKU: ").append(storageAccount.skuType().name().toString()) 722 | .append("\n\tAccessTier: ").append(storageAccount.accessTier()) 723 | .append("\n\tKind: ").append(storageAccount.kind()); 724 | 725 | info.append("\n\tNetwork Rule Configuration: ") 726 | .append("\n\t\tAllow reading logs from any network: ").append(storageAccount.canReadLogEntriesFromAnyNetwork()) 727 | .append("\n\t\tAllow reading metrics from any network: ").append(storageAccount.canReadMetricsFromAnyNetwork()) 728 | .append("\n\t\tAllow access from all azure services: ").append(storageAccount.canAccessFromAzureServices()); 729 | 730 | if (storageAccount.networkSubnetsWithAccess().size() > 0) { 731 | info.append("\n\t\tNetwork subnets with access: "); 732 | for (String subnetId : storageAccount.networkSubnetsWithAccess()) { 733 | info.append("\n\t\t\t").append(subnetId); 734 | } 735 | } 736 | if (storageAccount.ipAddressesWithAccess().size() > 0) { 737 | info.append("\n\t\tIP addresses with access: "); 738 | for (String ipAddress : storageAccount.ipAddressesWithAccess()) { 739 | info.append("\n\t\t\t").append(ipAddress); 740 | } 741 | } 742 | if (storageAccount.ipAddressRangesWithAccess().size() > 0) { 743 | info.append("\n\t\tIP address-ranges with access: "); 744 | for (String ipAddressRange : storageAccount.ipAddressRangesWithAccess()) { 745 | info.append("\n\t\t\t").append(ipAddressRange); 746 | } 747 | } 748 | info.append("\n\t\tTraffic allowed from only HTTPS: ").append(storageAccount.innerModel().enableHttpsTrafficOnly()); 749 | 750 | info.append("\n\tEncryption status: "); 751 | info.append("\n\t\tInfrastructure Encryption: ").append(storageAccount.infrastructureEncryptionEnabled() ? "Enabled" : "Disabled"); 752 | for (Map.Entry eStatus : storageAccount.encryptionStatuses().entrySet()) { 753 | info.append("\n\t\t").append(eStatus.getValue().storageService()).append(": ").append(eStatus.getValue().isEnabled() ? "Enabled" : "Disabled"); 754 | } 755 | 756 | System.out.println(info.toString()); 757 | } 758 | 759 | /** 760 | * Print storage account keys. 761 | * 762 | * @param storageAccountKeys a list of storage account keys 763 | */ 764 | public static void print(List storageAccountKeys) { 765 | for (int i = 0; i < storageAccountKeys.size(); i++) { 766 | StorageAccountKey storageAccountKey = storageAccountKeys.get(i); 767 | System.out.println("Key (" + i + ") " + storageAccountKey.keyName() + "=" 768 | + storageAccountKey.value()); 769 | } 770 | } 771 | 772 | 773 | /** 774 | * Print Redis Cache. 775 | * 776 | * @param redisCache a Redis cache. 777 | */ 778 | public static void print(RedisCache redisCache) { 779 | StringBuilder redisInfo = new StringBuilder() 780 | .append("Redis Cache Name: ").append(redisCache.name()) 781 | .append("\n\tResource group: ").append(redisCache.resourceGroupName()) 782 | .append("\n\tRegion: ").append(redisCache.region()) 783 | .append("\n\tSKU Name: ").append(redisCache.sku().name()) 784 | .append("\n\tSKU Family: ").append(redisCache.sku().family()) 785 | .append("\n\tHostname: ").append(redisCache.hostname()) 786 | .append("\n\tSSL port: ").append(redisCache.sslPort()) 787 | .append("\n\tNon-SSL port (6379) enabled: ").append(redisCache.nonSslPort()); 788 | if (redisCache.redisConfiguration() != null && !redisCache.redisConfiguration().isEmpty()) { 789 | redisInfo.append("\n\tRedis Configuration:"); 790 | for (Map.Entry redisConfiguration : redisCache.redisConfiguration().entrySet()) { 791 | redisInfo.append("\n\t '").append(redisConfiguration.getKey()) 792 | .append("' : '").append(redisConfiguration.getValue()).append("'"); 793 | } 794 | } 795 | if (redisCache.isPremium()) { 796 | RedisCachePremium premium = redisCache.asPremium(); 797 | List scheduleEntries = premium.listPatchSchedules(); 798 | if (scheduleEntries != null && !scheduleEntries.isEmpty()) { 799 | redisInfo.append("\n\tRedis Patch Schedule:"); 800 | for (ScheduleEntry schedule : scheduleEntries) { 801 | redisInfo.append("\n\t\tDay: '").append(schedule.dayOfWeek()) 802 | .append("', start at: '").append(schedule.startHourUtc()) 803 | .append("', maintenance window: '").append(schedule.maintenanceWindow()) 804 | .append("'"); 805 | } 806 | } 807 | } 808 | 809 | System.out.println(redisInfo.toString()); 810 | } 811 | 812 | /** 813 | * Print Redis Cache access keys. 814 | * 815 | * @param redisAccessKeys a keys for Redis Cache 816 | */ 817 | public static void print(RedisAccessKeys redisAccessKeys) { 818 | StringBuilder redisKeys = new StringBuilder() 819 | .append("Redis Access Keys: ") 820 | .append("\n\tPrimary Key: '").append(redisAccessKeys.primaryKey()).append("', ") 821 | .append("\n\tSecondary Key: '").append(redisAccessKeys.secondaryKey()).append("', "); 822 | 823 | System.out.println(redisKeys.toString()); 824 | } 825 | 826 | /** 827 | * Print management lock. 828 | * 829 | * @param lock a management lock 830 | */ 831 | public static void print(ManagementLock lock) { 832 | StringBuilder info = new StringBuilder(); 833 | info.append("\nLock ID: ").append(lock.id()) 834 | .append("\nLocked resource ID: ").append(lock.lockedResourceId()) 835 | .append("\nLevel: ").append(lock.level()); 836 | System.out.println(info.toString()); 837 | } 838 | 839 | /** 840 | * Print load balancer. 841 | * 842 | * @param resource a load balancer 843 | */ 844 | public static void print(LoadBalancer resource) { 845 | StringBuilder info = new StringBuilder(); 846 | info.append("Load balancer: ").append(resource.id()) 847 | .append("Name: ").append(resource.name()) 848 | .append("\n\tResource group: ").append(resource.resourceGroupName()) 849 | .append("\n\tRegion: ").append(resource.region()) 850 | .append("\n\tTags: ").append(resource.tags()) 851 | .append("\n\tBackends: ").append(resource.backends().keySet().toString()); 852 | 853 | // Show public IP addresses 854 | info.append("\n\tPublic IP address IDs: ") 855 | .append(resource.publicIpAddressIds().size()); 856 | for (String pipId : resource.publicIpAddressIds()) { 857 | info.append("\n\t\tPIP id: ").append(pipId); 858 | } 859 | 860 | // Show TCP probes 861 | info.append("\n\tTCP probes: ") 862 | .append(resource.tcpProbes().size()); 863 | for (LoadBalancerTcpProbe probe : resource.tcpProbes().values()) { 864 | info.append("\n\t\tProbe name: ").append(probe.name()) 865 | .append("\n\t\t\tPort: ").append(probe.port()) 866 | .append("\n\t\t\tInterval in seconds: ").append(probe.intervalInSeconds()) 867 | .append("\n\t\t\tRetries before unhealthy: ").append(probe.numberOfProbes()); 868 | 869 | // Show associated load balancing rules 870 | info.append("\n\t\t\tReferenced from load balancing rules: ") 871 | .append(probe.loadBalancingRules().size()); 872 | for (LoadBalancingRule rule : probe.loadBalancingRules().values()) { 873 | info.append("\n\t\t\t\tName: ").append(rule.name()); 874 | } 875 | } 876 | 877 | // Show HTTP probes 878 | info.append("\n\tHTTP probes: ") 879 | .append(resource.httpProbes().size()); 880 | for (LoadBalancerHttpProbe probe : resource.httpProbes().values()) { 881 | info.append("\n\t\tProbe name: ").append(probe.name()) 882 | .append("\n\t\t\tPort: ").append(probe.port()) 883 | .append("\n\t\t\tInterval in seconds: ").append(probe.intervalInSeconds()) 884 | .append("\n\t\t\tRetries before unhealthy: ").append(probe.numberOfProbes()) 885 | .append("\n\t\t\tHTTP request path: ").append(probe.requestPath()); 886 | 887 | // Show associated load balancing rules 888 | info.append("\n\t\t\tReferenced from load balancing rules: ") 889 | .append(probe.loadBalancingRules().size()); 890 | for (LoadBalancingRule rule : probe.loadBalancingRules().values()) { 891 | info.append("\n\t\t\t\tName: ").append(rule.name()); 892 | } 893 | } 894 | 895 | // Show HTTPS probes 896 | info.append("\n\tHTTPS probes: ") 897 | .append(resource.httpsProbes().size()); 898 | for (LoadBalancerHttpProbe probe : resource.httpsProbes().values()) { 899 | info.append("\n\t\tProbe name: ").append(probe.name()) 900 | .append("\n\t\t\tPort: ").append(probe.port()) 901 | .append("\n\t\t\tInterval in seconds: ").append(probe.intervalInSeconds()) 902 | .append("\n\t\t\tRetries before unhealthy: ").append(probe.numberOfProbes()) 903 | .append("\n\t\t\tHTTPS request path: ").append(probe.requestPath()); 904 | 905 | // Show associated load balancing rules 906 | info.append("\n\t\t\tReferenced from load balancing rules: ") 907 | .append(probe.loadBalancingRules().size()); 908 | for (LoadBalancingRule rule : probe.loadBalancingRules().values()) { 909 | info.append("\n\t\t\t\tName: ").append(rule.name()); 910 | } 911 | } 912 | 913 | // Show load balancing rules 914 | info.append("\n\tLoad balancing rules: ") 915 | .append(resource.loadBalancingRules().size()); 916 | for (LoadBalancingRule rule : resource.loadBalancingRules().values()) { 917 | info.append("\n\t\tLB rule name: ").append(rule.name()) 918 | .append("\n\t\t\tProtocol: ").append(rule.protocol()) 919 | .append("\n\t\t\tFloating IP enabled? ").append(rule.floatingIPEnabled()) 920 | .append("\n\t\t\tIdle timeout in minutes: ").append(rule.idleTimeoutInMinutes()) 921 | .append("\n\t\t\tLoad distribution method: ").append(rule.loadDistribution().toString()); 922 | 923 | LoadBalancerFrontend frontend = rule.frontend(); 924 | info.append("\n\t\t\tFrontend: "); 925 | if (frontend != null) { 926 | info.append(frontend.name()); 927 | } else { 928 | info.append("(None)"); 929 | } 930 | 931 | info.append("\n\t\t\tFrontend port: ").append(rule.frontendPort()); 932 | 933 | LoadBalancerBackend backend = rule.backend(); 934 | info.append("\n\t\t\tBackend: "); 935 | if (backend != null) { 936 | info.append(backend.name()); 937 | } else { 938 | info.append("(None)"); 939 | } 940 | 941 | info.append("\n\t\t\tBackend port: ").append(rule.backendPort()); 942 | 943 | LoadBalancerProbe probe = rule.probe(); 944 | info.append("\n\t\t\tProbe: "); 945 | if (probe == null) { 946 | info.append("(None)"); 947 | } else { 948 | info.append(probe.name()).append(" [").append(probe.protocol().toString()).append("]"); 949 | } 950 | } 951 | 952 | // Show frontends 953 | info.append("\n\tFrontends: ") 954 | .append(resource.frontends().size()); 955 | for (LoadBalancerFrontend frontend : resource.frontends().values()) { 956 | info.append("\n\t\tFrontend name: ").append(frontend.name()) 957 | .append("\n\t\t\tInternet facing: ").append(frontend.isPublic()); 958 | if (frontend.isPublic()) { 959 | info.append("\n\t\t\tPublic IP Address ID: ").append(((LoadBalancerPublicFrontend) frontend).publicIpAddressId()); 960 | } else { 961 | info.append("\n\t\t\tVirtual network ID: ").append(((LoadBalancerPrivateFrontend) frontend).networkId()) 962 | .append("\n\t\t\tSubnet name: ").append(((LoadBalancerPrivateFrontend) frontend).subnetName()) 963 | .append("\n\t\t\tPrivate IP address: ").append(((LoadBalancerPrivateFrontend) frontend).privateIpAddress()) 964 | .append("\n\t\t\tPrivate IP allocation method: ").append(((LoadBalancerPrivateFrontend) frontend).privateIpAllocationMethod()); 965 | } 966 | 967 | // Inbound NAT pool references 968 | info.append("\n\t\t\tReferenced inbound NAT pools: ") 969 | .append(frontend.inboundNatPools().size()); 970 | for (LoadBalancerInboundNatPool pool : frontend.inboundNatPools().values()) { 971 | info.append("\n\t\t\t\tName: ").append(pool.name()); 972 | } 973 | 974 | // Inbound NAT rule references 975 | info.append("\n\t\t\tReferenced inbound NAT rules: ") 976 | .append(frontend.inboundNatRules().size()); 977 | for (LoadBalancerInboundNatRule rule : frontend.inboundNatRules().values()) { 978 | info.append("\n\t\t\t\tName: ").append(rule.name()); 979 | } 980 | 981 | // Load balancing rule references 982 | info.append("\n\t\t\tReferenced load balancing rules: ") 983 | .append(frontend.loadBalancingRules().size()); 984 | for (LoadBalancingRule rule : frontend.loadBalancingRules().values()) { 985 | info.append("\n\t\t\t\tName: ").append(rule.name()); 986 | } 987 | } 988 | 989 | // Show inbound NAT rules 990 | info.append("\n\tInbound NAT rules: ") 991 | .append(resource.inboundNatRules().size()); 992 | for (LoadBalancerInboundNatRule natRule : resource.inboundNatRules().values()) { 993 | info.append("\n\t\tInbound NAT rule name: ").append(natRule.name()) 994 | .append("\n\t\t\tProtocol: ").append(natRule.protocol().toString()) 995 | .append("\n\t\t\tFrontend: ").append(natRule.frontend().name()) 996 | .append("\n\t\t\tFrontend port: ").append(natRule.frontendPort()) 997 | .append("\n\t\t\tBackend port: ").append(natRule.backendPort()) 998 | .append("\n\t\t\tBackend NIC ID: ").append(natRule.backendNetworkInterfaceId()) 999 | .append("\n\t\t\tBackend NIC IP config name: ").append(natRule.backendNicIpConfigurationName()) 1000 | .append("\n\t\t\tFloating IP? ").append(natRule.floatingIPEnabled()) 1001 | .append("\n\t\t\tIdle timeout in minutes: ").append(natRule.idleTimeoutInMinutes()); 1002 | } 1003 | 1004 | // Show inbound NAT pools 1005 | info.append("\n\tInbound NAT pools: ") 1006 | .append(resource.inboundNatPools().size()); 1007 | for (LoadBalancerInboundNatPool natPool : resource.inboundNatPools().values()) { 1008 | info.append("\n\t\tInbound NAT pool name: ").append(natPool.name()) 1009 | .append("\n\t\t\tProtocol: ").append(natPool.protocol().toString()) 1010 | .append("\n\t\t\tFrontend: ").append(natPool.frontend().name()) 1011 | .append("\n\t\t\tFrontend port range: ") 1012 | .append(natPool.frontendPortRangeStart()) 1013 | .append("-") 1014 | .append(natPool.frontendPortRangeEnd()) 1015 | .append("\n\t\t\tBackend port: ").append(natPool.backendPort()); 1016 | } 1017 | 1018 | // Show backends 1019 | info.append("\n\tBackends: ") 1020 | .append(resource.backends().size()); 1021 | for (LoadBalancerBackend backend : resource.backends().values()) { 1022 | info.append("\n\t\tBackend name: ").append(backend.name()); 1023 | 1024 | // Show assigned backend NICs 1025 | info.append("\n\t\t\tReferenced NICs: ") 1026 | .append(backend.backendNicIPConfigurationNames().entrySet().size()); 1027 | for (Map.Entry entry : backend.backendNicIPConfigurationNames().entrySet()) { 1028 | info.append("\n\t\t\t\tNIC ID: ").append(entry.getKey()) 1029 | .append(" - IP Config: ").append(entry.getValue()); 1030 | } 1031 | 1032 | // Show assigned virtual machines 1033 | Set vmIds = backend.getVirtualMachineIds(); 1034 | info.append("\n\t\t\tReferenced virtual machine ids: ") 1035 | .append(vmIds.size()); 1036 | for (String vmId : vmIds) { 1037 | info.append("\n\t\t\t\tVM ID: ").append(vmId); 1038 | } 1039 | 1040 | // Show assigned load balancing rules 1041 | info.append("\n\t\t\tReferenced load balancing rules: ") 1042 | .append(new ArrayList(backend.loadBalancingRules().keySet())); 1043 | } 1044 | 1045 | System.out.println(info.toString()); 1046 | } 1047 | // 1048 | // /** 1049 | // * Prints batch account keys. 1050 | // * 1051 | // * @param batchAccountKeys a list of batch account keys 1052 | // */ 1053 | // public static void print(BatchAccountKeys batchAccountKeys) { 1054 | // System.out.println("Primary Key (" + batchAccountKeys.primary() + ") Secondary key = (" 1055 | // + batchAccountKeys.secondary() + ")"); 1056 | // } 1057 | 1058 | // /** 1059 | // * Prints batch account. 1060 | // * 1061 | // * @param batchAccount a Batch Account 1062 | // */ 1063 | // public static void print(BatchAccount batchAccount) { 1064 | // StringBuilder applicationsOutput = new StringBuilder().append("\n\tapplications: "); 1065 | // 1066 | // if (batchAccount.applications().size() > 0) { 1067 | // for (Map.Entry applicationEntry : batchAccount.applications().entrySet()) { 1068 | // Application application = applicationEntry.getValue(); 1069 | // StringBuilder applicationPackages = new StringBuilder().append("\n\t\t\tapplicationPackages : "); 1070 | // 1071 | // for (Map.Entry applicationPackageEntry : application.applicationPackages().entrySet()) { 1072 | // ApplicationPackage applicationPackage = applicationPackageEntry.getValue(); 1073 | // StringBuilder singleApplicationPackage = new StringBuilder().append("\n\t\t\t\tapplicationPackage : " + applicationPackage.name()); 1074 | // singleApplicationPackage.append("\n\t\t\t\tapplicationPackageState : " + applicationPackage.state()); 1075 | // 1076 | // applicationPackages.append(singleApplicationPackage); 1077 | // singleApplicationPackage.append("\n"); 1078 | // } 1079 | // 1080 | // StringBuilder singleApplication = new StringBuilder().append("\n\t\tapplication: " + application.name()); 1081 | // singleApplication.append("\n\t\tdisplayName: " + application.displayName()); 1082 | // singleApplication.append("\n\t\tdefaultVersion: " + application.defaultVersion()); 1083 | // singleApplication.append(applicationPackages); 1084 | // applicationsOutput.append(singleApplication); 1085 | // applicationsOutput.append("\n"); 1086 | // } 1087 | // } 1088 | // 1089 | // System.out.println(new StringBuilder().append("BatchAccount: ").append(batchAccount.id()) 1090 | // .append("Name: ").append(batchAccount.name()) 1091 | // .append("\n\tResource group: ").append(batchAccount.resourceGroupName()) 1092 | // .append("\n\tRegion: ").append(batchAccount.region()) 1093 | // .append("\n\tTags: ").append(batchAccount.tags()) 1094 | // .append("\n\tAccountEndpoint: ").append(batchAccount.accountEndpoint()) 1095 | // .append("\n\tPoolQuota: ").append(batchAccount.poolQuota()) 1096 | // .append("\n\tActiveJobAndJobScheduleQuota: ").append(batchAccount.activeJobAndJobScheduleQuota()) 1097 | // .append("\n\tStorageAccount: ").append(batchAccount.autoStorage() == null ? "No storage account attached" : batchAccount.autoStorage().storageAccountId()) 1098 | // .append(applicationsOutput) 1099 | // .toString()); 1100 | // } 1101 | 1102 | /** 1103 | * Print app service domain. 1104 | * 1105 | * @param resource an app service domain 1106 | */ 1107 | public static void print(AppServiceDomain resource) { 1108 | StringBuilder builder = new StringBuilder().append("Domain: ").append(resource.id()) 1109 | .append("Name: ").append(resource.name()) 1110 | .append("\n\tResource group: ").append(resource.resourceGroupName()) 1111 | .append("\n\tRegion: ").append(resource.region()) 1112 | .append("\n\tCreated time: ").append(resource.createdTime()) 1113 | .append("\n\tExpiration time: ").append(resource.expirationTime()) 1114 | .append("\n\tContact: "); 1115 | Contact contact = resource.registrantContact(); 1116 | if (contact == null) { 1117 | builder = builder.append("Private"); 1118 | } else { 1119 | builder = builder.append("\n\t\tName: ").append(contact.nameFirst() + " " + contact.nameLast()); 1120 | } 1121 | builder = builder.append("\n\tName servers: "); 1122 | for (String nameServer : resource.nameServers()) { 1123 | builder = builder.append("\n\t\t" + nameServer); 1124 | } 1125 | System.out.println(builder.toString()); 1126 | } 1127 | 1128 | /** 1129 | * Print app service certificate order. 1130 | * 1131 | * @param resource an app service certificate order 1132 | */ 1133 | public static void print(AppServiceCertificateOrder resource) { 1134 | StringBuilder builder = new StringBuilder().append("App service certificate order: ").append(resource.id()) 1135 | .append("Name: ").append(resource.name()) 1136 | .append("\n\tResource group: ").append(resource.resourceGroupName()) 1137 | .append("\n\tRegion: ").append(resource.region()) 1138 | .append("\n\tDistinguished name: ").append(resource.distinguishedName()) 1139 | .append("\n\tProduct type: ").append(resource.productType()) 1140 | .append("\n\tValid years: ").append(resource.validityInYears()) 1141 | .append("\n\tStatus: ").append(resource.status()) 1142 | .append("\n\tIssuance time: ").append(resource.lastCertificateIssuanceTime()) 1143 | .append("\n\tSigned certificate: ").append(resource.signedCertificate() == null ? null : resource.signedCertificate().thumbprint()); 1144 | System.out.println(builder.toString()); 1145 | } 1146 | 1147 | /** 1148 | * Print app service plan. 1149 | * 1150 | * @param resource an app service plan 1151 | */ 1152 | public static void print(AppServicePlan resource) { 1153 | StringBuilder builder = new StringBuilder().append("App service certificate order: ").append(resource.id()) 1154 | .append("Name: ").append(resource.name()) 1155 | .append("\n\tResource group: ").append(resource.resourceGroupName()) 1156 | .append("\n\tRegion: ").append(resource.region()) 1157 | .append("\n\tPricing tier: ").append(resource.pricingTier()); 1158 | System.out.println(builder.toString()); 1159 | } 1160 | 1161 | /** 1162 | * Print a web app. 1163 | * 1164 | * @param resource a web app 1165 | */ 1166 | public static void print(WebAppBase resource) { 1167 | StringBuilder builder = new StringBuilder().append("Web app: ").append(resource.id()) 1168 | .append("\n\tName: ").append(resource.name()) 1169 | .append("\n\tState: ").append(resource.state()) 1170 | .append("\n\tResource group: ").append(resource.resourceGroupName()) 1171 | .append("\n\tRegion: ").append(resource.region()) 1172 | .append("\n\tDefault hostname: ").append(resource.defaultHostname()) 1173 | .append("\n\tApp service plan: ").append(resource.appServicePlanId()) 1174 | .append("\n\tHost name bindings: "); 1175 | for (HostnameBinding binding : resource.getHostnameBindings().values()) { 1176 | builder = builder.append("\n\t\t" + binding.toString()); 1177 | } 1178 | builder = builder.append("\n\tSSL bindings: "); 1179 | for (HostnameSslState binding : resource.hostnameSslStates().values()) { 1180 | builder = builder.append("\n\t\t" + binding.name() + ": " + binding.sslState()); 1181 | if (binding.sslState() != null && binding.sslState() != SslState.DISABLED) { 1182 | builder = builder.append(" - " + binding.thumbprint()); 1183 | } 1184 | } 1185 | builder = builder.append("\n\tApp settings: "); 1186 | for (AppSetting setting : resource.getAppSettings().values()) { 1187 | builder = builder.append("\n\t\t" + setting.key() + ": " + setting.value() + (setting.sticky() ? " - slot setting" : "")); 1188 | } 1189 | builder = builder.append("\n\tConnection strings: "); 1190 | for (ConnectionString conn : resource.getConnectionStrings().values()) { 1191 | builder = builder.append("\n\t\t" + conn.name() + ": " + conn.value() + " - " + conn.type() + (conn.sticky() ? " - slot setting" : "")); 1192 | } 1193 | System.out.println(builder.toString()); 1194 | } 1195 | 1196 | /** 1197 | * Print a web site. 1198 | * 1199 | * @param resource a web site 1200 | */ 1201 | public static void print(WebSiteBase resource) { 1202 | StringBuilder builder = new StringBuilder().append("Web app: ").append(resource.id()) 1203 | .append("\n\tName: ").append(resource.name()) 1204 | .append("\n\tState: ").append(resource.state()) 1205 | .append("\n\tResource group: ").append(resource.resourceGroupName()) 1206 | .append("\n\tRegion: ").append(resource.region()) 1207 | .append("\n\tDefault hostname: ").append(resource.defaultHostname()) 1208 | .append("\n\tApp service plan: ").append(resource.appServicePlanId()); 1209 | builder = builder.append("\n\tSSL bindings: "); 1210 | for (HostnameSslState binding : resource.hostnameSslStates().values()) { 1211 | builder = builder.append("\n\t\t" + binding.name() + ": " + binding.sslState()); 1212 | if (binding.sslState() != null && binding.sslState() != SslState.DISABLED) { 1213 | builder = builder.append(" - " + binding.thumbprint()); 1214 | } 1215 | } 1216 | System.out.println(builder.toString()); 1217 | } 1218 | 1219 | /** 1220 | * Print a traffic manager profile. 1221 | * 1222 | * @param profile a traffic manager profile 1223 | */ 1224 | public static void print(TrafficManagerProfile profile) { 1225 | StringBuilder info = new StringBuilder(); 1226 | info.append("Traffic Manager Profile: ").append(profile.id()) 1227 | .append("\n\tName: ").append(profile.name()) 1228 | .append("\n\tResource group: ").append(profile.resourceGroupName()) 1229 | .append("\n\tRegion: ").append(profile.regionName()) 1230 | .append("\n\tTags: ").append(profile.tags()) 1231 | .append("\n\tDNSLabel: ").append(profile.dnsLabel()) 1232 | .append("\n\tFQDN: ").append(profile.fqdn()) 1233 | .append("\n\tTTL: ").append(profile.timeToLive()) 1234 | .append("\n\tEnabled: ").append(profile.isEnabled()) 1235 | .append("\n\tRoutingMethod: ").append(profile.trafficRoutingMethod()) 1236 | .append("\n\tMonitor status: ").append(profile.monitorStatus()) 1237 | .append("\n\tMonitoring port: ").append(profile.monitoringPort()) 1238 | .append("\n\tMonitoring path: ").append(profile.monitoringPath()); 1239 | 1240 | Map azureEndpoints = profile.azureEndpoints(); 1241 | if (!azureEndpoints.isEmpty()) { 1242 | info.append("\n\tAzure endpoints:"); 1243 | int idx = 1; 1244 | for (TrafficManagerAzureEndpoint endpoint : azureEndpoints.values()) { 1245 | info.append("\n\t\tAzure endpoint: #").append(idx++) 1246 | .append("\n\t\t\tId: ").append(endpoint.id()) 1247 | .append("\n\t\t\tType: ").append(endpoint.endpointType()) 1248 | .append("\n\t\t\tTarget resourceId: ").append(endpoint.targetAzureResourceId()) 1249 | .append("\n\t\t\tTarget resourceType: ").append(endpoint.targetResourceType()) 1250 | .append("\n\t\t\tMonitor status: ").append(endpoint.monitorStatus()) 1251 | .append("\n\t\t\tEnabled: ").append(endpoint.isEnabled()) 1252 | .append("\n\t\t\tRouting priority: ").append(endpoint.routingPriority()) 1253 | .append("\n\t\t\tRouting weight: ").append(endpoint.routingWeight()); 1254 | } 1255 | } 1256 | 1257 | Map externalEndpoints = profile.externalEndpoints(); 1258 | if (!externalEndpoints.isEmpty()) { 1259 | info.append("\n\tExternal endpoints:"); 1260 | int idx = 1; 1261 | for (TrafficManagerExternalEndpoint endpoint : externalEndpoints.values()) { 1262 | info.append("\n\t\tExternal endpoint: #").append(idx++) 1263 | .append("\n\t\t\tId: ").append(endpoint.id()) 1264 | .append("\n\t\t\tType: ").append(endpoint.endpointType()) 1265 | .append("\n\t\t\tFQDN: ").append(endpoint.fqdn()) 1266 | .append("\n\t\t\tSource Traffic Location: ").append(endpoint.sourceTrafficLocation()) 1267 | .append("\n\t\t\tMonitor status: ").append(endpoint.monitorStatus()) 1268 | .append("\n\t\t\tEnabled: ").append(endpoint.isEnabled()) 1269 | .append("\n\t\t\tRouting priority: ").append(endpoint.routingPriority()) 1270 | .append("\n\t\t\tRouting weight: ").append(endpoint.routingWeight()); 1271 | } 1272 | } 1273 | 1274 | Map nestedProfileEndpoints = profile.nestedProfileEndpoints(); 1275 | if (!nestedProfileEndpoints.isEmpty()) { 1276 | info.append("\n\tNested profile endpoints:"); 1277 | int idx = 1; 1278 | for (TrafficManagerNestedProfileEndpoint endpoint : nestedProfileEndpoints.values()) { 1279 | info.append("\n\t\tNested profile endpoint: #").append(idx++) 1280 | .append("\n\t\t\tId: ").append(endpoint.id()) 1281 | .append("\n\t\t\tType: ").append(endpoint.endpointType()) 1282 | .append("\n\t\t\tNested profileId: ").append(endpoint.nestedProfileId()) 1283 | .append("\n\t\t\tMinimum child threshold: ").append(endpoint.minimumChildEndpointCount()) 1284 | .append("\n\t\t\tSource Traffic Location: ").append(endpoint.sourceTrafficLocation()) 1285 | .append("\n\t\t\tMonitor status: ").append(endpoint.monitorStatus()) 1286 | .append("\n\t\t\tEnabled: ").append(endpoint.isEnabled()) 1287 | .append("\n\t\t\tRouting priority: ").append(endpoint.routingPriority()) 1288 | .append("\n\t\t\tRouting weight: ").append(endpoint.routingWeight()); 1289 | } 1290 | } 1291 | System.out.println(info.toString()); 1292 | } 1293 | 1294 | /** 1295 | * Print a dns zone. 1296 | * 1297 | * @param dnsZone a dns zone 1298 | */ 1299 | public static void print(DnsZone dnsZone) { 1300 | StringBuilder info = new StringBuilder(); 1301 | info.append("DNS Zone: ").append(dnsZone.id()) 1302 | .append("\n\tName (Top level domain): ").append(dnsZone.name()) 1303 | .append("\n\tResource group: ").append(dnsZone.resourceGroupName()) 1304 | .append("\n\tRegion: ").append(dnsZone.regionName()) 1305 | .append("\n\tTags: ").append(dnsZone.tags()) 1306 | .append("\n\tName servers:"); 1307 | for (String nameServer : dnsZone.nameServers()) { 1308 | info.append("\n\t\t").append(nameServer); 1309 | } 1310 | SoaRecordSet soaRecordSet = dnsZone.getSoaRecordSet(); 1311 | SoaRecord soaRecord = soaRecordSet.record(); 1312 | info.append("\n\tSOA Record:") 1313 | .append("\n\t\tHost:").append(soaRecord.host()) 1314 | .append("\n\t\tEmail:").append(soaRecord.email()) 1315 | .append("\n\t\tExpire time (seconds):").append(soaRecord.expireTime()) 1316 | .append("\n\t\tRefresh time (seconds):").append(soaRecord.refreshTime()) 1317 | .append("\n\t\tRetry time (seconds):").append(soaRecord.retryTime()) 1318 | .append("\n\t\tNegative response cache ttl (seconds):").append(soaRecord.minimumTtl()) 1319 | .append("\n\t\tTTL (seconds):").append(soaRecordSet.timeToLive()); 1320 | 1321 | PagedIterable aRecordSets = dnsZone.aRecordSets().list(); 1322 | info.append("\n\tA Record sets:"); 1323 | for (ARecordSet aRecordSet : aRecordSets) { 1324 | info.append("\n\t\tId: ").append(aRecordSet.id()) 1325 | .append("\n\t\tName: ").append(aRecordSet.name()) 1326 | .append("\n\t\tTTL (seconds): ").append(aRecordSet.timeToLive()) 1327 | .append("\n\t\tIP v4 addresses: "); 1328 | for (String ipAddress : aRecordSet.ipv4Addresses()) { 1329 | info.append("\n\t\t\t").append(ipAddress); 1330 | } 1331 | } 1332 | 1333 | PagedIterable aaaaRecordSets = dnsZone.aaaaRecordSets().list(); 1334 | info.append("\n\tAAAA Record sets:"); 1335 | for (AaaaRecordSet aaaaRecordSet : aaaaRecordSets) { 1336 | info.append("\n\t\tId: ").append(aaaaRecordSet.id()) 1337 | .append("\n\t\tName: ").append(aaaaRecordSet.name()) 1338 | .append("\n\t\tTTL (seconds): ").append(aaaaRecordSet.timeToLive()) 1339 | .append("\n\t\tIP v6 addresses: "); 1340 | for (String ipAddress : aaaaRecordSet.ipv6Addresses()) { 1341 | info.append("\n\t\t\t").append(ipAddress); 1342 | } 1343 | } 1344 | 1345 | PagedIterable cnameRecordSets = dnsZone.cNameRecordSets().list(); 1346 | info.append("\n\tCNAME Record sets:"); 1347 | for (CnameRecordSet cnameRecordSet : cnameRecordSets) { 1348 | info.append("\n\t\tId: ").append(cnameRecordSet.id()) 1349 | .append("\n\t\tName: ").append(cnameRecordSet.name()) 1350 | .append("\n\t\tTTL (seconds): ").append(cnameRecordSet.timeToLive()) 1351 | .append("\n\t\tCanonical name: ").append(cnameRecordSet.canonicalName()); 1352 | } 1353 | 1354 | PagedIterable mxRecordSets = dnsZone.mxRecordSets().list(); 1355 | info.append("\n\tMX Record sets:"); 1356 | for (MxRecordSet mxRecordSet : mxRecordSets) { 1357 | info.append("\n\t\tId: ").append(mxRecordSet.id()) 1358 | .append("\n\t\tName: ").append(mxRecordSet.name()) 1359 | .append("\n\t\tTTL (seconds): ").append(mxRecordSet.timeToLive()) 1360 | .append("\n\t\tRecords: "); 1361 | for (MxRecord mxRecord : mxRecordSet.records()) { 1362 | info.append("\n\t\t\tExchange server, Preference: ") 1363 | .append(mxRecord.exchange()) 1364 | .append(" ") 1365 | .append(mxRecord.preference()); 1366 | } 1367 | } 1368 | 1369 | PagedIterable nsRecordSets = dnsZone.nsRecordSets().list(); 1370 | info.append("\n\tNS Record sets:"); 1371 | for (NsRecordSet nsRecordSet : nsRecordSets) { 1372 | info.append("\n\t\tId: ").append(nsRecordSet.id()) 1373 | .append("\n\t\tName: ").append(nsRecordSet.name()) 1374 | .append("\n\t\tTTL (seconds): ").append(nsRecordSet.timeToLive()) 1375 | .append("\n\t\tName servers: "); 1376 | for (String nameServer : nsRecordSet.nameServers()) { 1377 | info.append("\n\t\t\t").append(nameServer); 1378 | } 1379 | } 1380 | 1381 | PagedIterable ptrRecordSets = dnsZone.ptrRecordSets().list(); 1382 | info.append("\n\tPTR Record sets:"); 1383 | for (PtrRecordSet ptrRecordSet : ptrRecordSets) { 1384 | info.append("\n\t\tId: ").append(ptrRecordSet.id()) 1385 | .append("\n\t\tName: ").append(ptrRecordSet.name()) 1386 | .append("\n\t\tTTL (seconds): ").append(ptrRecordSet.timeToLive()) 1387 | .append("\n\t\tTarget domain names: "); 1388 | for (String domainNames : ptrRecordSet.targetDomainNames()) { 1389 | info.append("\n\t\t\t").append(domainNames); 1390 | } 1391 | } 1392 | 1393 | PagedIterable srvRecordSets = dnsZone.srvRecordSets().list(); 1394 | info.append("\n\tSRV Record sets:"); 1395 | for (SrvRecordSet srvRecordSet : srvRecordSets) { 1396 | info.append("\n\t\tId: ").append(srvRecordSet.id()) 1397 | .append("\n\t\tName: ").append(srvRecordSet.name()) 1398 | .append("\n\t\tTTL (seconds): ").append(srvRecordSet.timeToLive()) 1399 | .append("\n\t\tRecords: "); 1400 | for (SrvRecord srvRecord : srvRecordSet.records()) { 1401 | info.append("\n\t\t\tTarget, Port, Priority, Weight: ") 1402 | .append(srvRecord.target()) 1403 | .append(", ") 1404 | .append(srvRecord.port()) 1405 | .append(", ") 1406 | .append(srvRecord.priority()) 1407 | .append(", ") 1408 | .append(srvRecord.weight()); 1409 | } 1410 | } 1411 | 1412 | PagedIterable txtRecordSets = dnsZone.txtRecordSets().list(); 1413 | info.append("\n\tTXT Record sets:"); 1414 | for (TxtRecordSet txtRecordSet : txtRecordSets) { 1415 | info.append("\n\t\tId: ").append(txtRecordSet.id()) 1416 | .append("\n\t\tName: ").append(txtRecordSet.name()) 1417 | .append("\n\t\tTTL (seconds): ").append(txtRecordSet.timeToLive()) 1418 | .append("\n\t\tRecords: "); 1419 | for (TxtRecord txtRecord : txtRecordSet.records()) { 1420 | if (txtRecord.value().size() > 0) { 1421 | info.append("\n\t\t\tValue: ").append(txtRecord.value().get(0)); 1422 | } 1423 | } 1424 | } 1425 | System.out.println(info.toString()); 1426 | } 1427 | 1428 | /** 1429 | * Print a private dns zone. 1430 | * 1431 | * @param privateDnsZone a private dns zone 1432 | */ 1433 | public static void print(PrivateDnsZone privateDnsZone) { 1434 | StringBuilder info = new StringBuilder(); 1435 | info.append("Private DNS Zone: ").append(privateDnsZone.id()) 1436 | .append("\n\tName (Top level domain): ").append(privateDnsZone.name()) 1437 | .append("\n\tResource group: ").append(privateDnsZone.resourceGroupName()) 1438 | .append("\n\tRegion: ").append(privateDnsZone.regionName()) 1439 | .append("\n\tTags: ").append(privateDnsZone.tags()) 1440 | .append("\n\tName servers:"); 1441 | com.azure.resourcemanager.privatedns.models.SoaRecordSet soaRecordSet = privateDnsZone.getSoaRecordSet(); 1442 | com.azure.resourcemanager.privatedns.models.SoaRecord soaRecord = soaRecordSet.record(); 1443 | info.append("\n\tSOA Record:") 1444 | .append("\n\t\tHost:").append(soaRecord.host()) 1445 | .append("\n\t\tEmail:").append(soaRecord.email()) 1446 | .append("\n\t\tExpire time (seconds):").append(soaRecord.expireTime()) 1447 | .append("\n\t\tRefresh time (seconds):").append(soaRecord.refreshTime()) 1448 | .append("\n\t\tRetry time (seconds):").append(soaRecord.retryTime()) 1449 | .append("\n\t\tNegative response cache ttl (seconds):").append(soaRecord.minimumTtl()) 1450 | .append("\n\t\tTTL (seconds):").append(soaRecordSet.timeToLive()); 1451 | 1452 | PagedIterable aRecordSets = privateDnsZone 1453 | .aRecordSets().list(); 1454 | info.append("\n\tA Record sets:"); 1455 | for (com.azure.resourcemanager.privatedns.models.ARecordSet aRecordSet : aRecordSets) { 1456 | info.append("\n\t\tId: ").append(aRecordSet.id()) 1457 | .append("\n\t\tName: ").append(aRecordSet.name()) 1458 | .append("\n\t\tTTL (seconds): ").append(aRecordSet.timeToLive()) 1459 | .append("\n\t\tIP v4 addresses: "); 1460 | for (String ipAddress : aRecordSet.ipv4Addresses()) { 1461 | info.append("\n\t\t\t").append(ipAddress); 1462 | } 1463 | } 1464 | 1465 | PagedIterable aaaaRecordSets = privateDnsZone 1466 | .aaaaRecordSets().list(); 1467 | info.append("\n\tAAAA Record sets:"); 1468 | for (com.azure.resourcemanager.privatedns.models.AaaaRecordSet aaaaRecordSet : aaaaRecordSets) { 1469 | info.append("\n\t\tId: ").append(aaaaRecordSet.id()) 1470 | .append("\n\t\tName: ").append(aaaaRecordSet.name()) 1471 | .append("\n\t\tTTL (seconds): ").append(aaaaRecordSet.timeToLive()) 1472 | .append("\n\t\tIP v6 addresses: "); 1473 | for (String ipAddress : aaaaRecordSet.ipv6Addresses()) { 1474 | info.append("\n\t\t\t").append(ipAddress); 1475 | } 1476 | } 1477 | 1478 | PagedIterable cnameRecordSets = privateDnsZone.cnameRecordSets().list(); 1479 | info.append("\n\tCNAME Record sets:"); 1480 | for (com.azure.resourcemanager.privatedns.models.CnameRecordSet cnameRecordSet : cnameRecordSets) { 1481 | info.append("\n\t\tId: ").append(cnameRecordSet.id()) 1482 | .append("\n\t\tName: ").append(cnameRecordSet.name()) 1483 | .append("\n\t\tTTL (seconds): ").append(cnameRecordSet.timeToLive()) 1484 | .append("\n\t\tCanonical name: ").append(cnameRecordSet.canonicalName()); 1485 | } 1486 | 1487 | PagedIterable mxRecordSets = privateDnsZone.mxRecordSets().list(); 1488 | info.append("\n\tMX Record sets:"); 1489 | for (com.azure.resourcemanager.privatedns.models.MxRecordSet mxRecordSet : mxRecordSets) { 1490 | info.append("\n\t\tId: ").append(mxRecordSet.id()) 1491 | .append("\n\t\tName: ").append(mxRecordSet.name()) 1492 | .append("\n\t\tTTL (seconds): ").append(mxRecordSet.timeToLive()) 1493 | .append("\n\t\tRecords: "); 1494 | for (com.azure.resourcemanager.privatedns.models.MxRecord mxRecord : mxRecordSet.records()) { 1495 | info.append("\n\t\t\tExchange server, Preference: ") 1496 | .append(mxRecord.exchange()) 1497 | .append(" ") 1498 | .append(mxRecord.preference()); 1499 | } 1500 | } 1501 | 1502 | PagedIterable ptrRecordSets = privateDnsZone 1503 | .ptrRecordSets().list(); 1504 | info.append("\n\tPTR Record sets:"); 1505 | for (com.azure.resourcemanager.privatedns.models.PtrRecordSet ptrRecordSet : ptrRecordSets) { 1506 | info.append("\n\t\tId: ").append(ptrRecordSet.id()) 1507 | .append("\n\t\tName: ").append(ptrRecordSet.name()) 1508 | .append("\n\t\tTTL (seconds): ").append(ptrRecordSet.timeToLive()) 1509 | .append("\n\t\tTarget domain names: "); 1510 | for (String domainNames : ptrRecordSet.targetDomainNames()) { 1511 | info.append("\n\t\t\t").append(domainNames); 1512 | } 1513 | } 1514 | 1515 | PagedIterable srvRecordSets = privateDnsZone 1516 | .srvRecordSets().list(); 1517 | info.append("\n\tSRV Record sets:"); 1518 | for (com.azure.resourcemanager.privatedns.models.SrvRecordSet srvRecordSet : srvRecordSets) { 1519 | info.append("\n\t\tId: ").append(srvRecordSet.id()) 1520 | .append("\n\t\tName: ").append(srvRecordSet.name()) 1521 | .append("\n\t\tTTL (seconds): ").append(srvRecordSet.timeToLive()) 1522 | .append("\n\t\tRecords: "); 1523 | for (com.azure.resourcemanager.privatedns.models.SrvRecord srvRecord : srvRecordSet.records()) { 1524 | info.append("\n\t\t\tTarget, Port, Priority, Weight: ") 1525 | .append(srvRecord.target()) 1526 | .append(", ") 1527 | .append(srvRecord.port()) 1528 | .append(", ") 1529 | .append(srvRecord.priority()) 1530 | .append(", ") 1531 | .append(srvRecord.weight()); 1532 | } 1533 | } 1534 | 1535 | PagedIterable txtRecordSets = privateDnsZone 1536 | .txtRecordSets().list(); 1537 | info.append("\n\tTXT Record sets:"); 1538 | for (com.azure.resourcemanager.privatedns.models.TxtRecordSet txtRecordSet : txtRecordSets) { 1539 | info.append("\n\t\tId: ").append(txtRecordSet.id()) 1540 | .append("\n\t\tName: ").append(txtRecordSet.name()) 1541 | .append("\n\t\tTTL (seconds): ").append(txtRecordSet.timeToLive()) 1542 | .append("\n\t\tRecords: "); 1543 | for (com.azure.resourcemanager.privatedns.models.TxtRecord txtRecord : txtRecordSet.records()) { 1544 | if (txtRecord.value().size() > 0) { 1545 | info.append("\n\t\t\tValue: ").append(txtRecord.value().get(0)); 1546 | } 1547 | } 1548 | } 1549 | 1550 | PagedIterable virtualNetworkLinks = privateDnsZone.virtualNetworkLinks().list(); 1551 | info.append("\n\tVirtual Network Links:"); 1552 | for (VirtualNetworkLink virtualNetworkLink : virtualNetworkLinks) { 1553 | info.append("\n\tId: ").append(virtualNetworkLink.id()) 1554 | .append("\n\tName: ").append(virtualNetworkLink.name()) 1555 | .append("\n\tReference of Virtual Network: ").append(virtualNetworkLink.referencedVirtualNetworkId()) 1556 | .append("\n\tRegistration enabled: ").append(virtualNetworkLink.isAutoRegistrationEnabled()); 1557 | } 1558 | System.out.println(info.toString()); 1559 | } 1560 | 1561 | /** 1562 | * Print an Azure Container Registry. 1563 | * 1564 | * @param azureRegistry an Azure Container Registry 1565 | */ 1566 | public static void print(Registry azureRegistry) { 1567 | StringBuilder info = new StringBuilder(); 1568 | 1569 | RegistryCredentials acrCredentials = azureRegistry.getCredentials(); 1570 | info.append("Azure Container Registry: ").append(azureRegistry.id()) 1571 | .append("\n\tName: ").append(azureRegistry.name()) 1572 | .append("\n\tServer Url: ").append(azureRegistry.loginServerUrl()) 1573 | .append("\n\tUser: ").append(acrCredentials.username()) 1574 | .append("\n\tFirst Password: ").append(acrCredentials.accessKeys().get(AccessKeyType.PRIMARY)) 1575 | .append("\n\tSecond Password: ").append(acrCredentials.accessKeys().get(AccessKeyType.SECONDARY)); 1576 | System.out.println(info.toString()); 1577 | } 1578 | 1579 | /** 1580 | * Print an Azure Container Service (AKS). 1581 | * 1582 | * @param kubernetesCluster a managed container service 1583 | */ 1584 | public static void print(KubernetesCluster kubernetesCluster) { 1585 | StringBuilder info = new StringBuilder(); 1586 | 1587 | info.append("Azure Container Service: ").append(kubernetesCluster.id()) 1588 | .append("\n\tName: ").append(kubernetesCluster.name()) 1589 | .append("\n\tFQDN: ").append(kubernetesCluster.fqdn()) 1590 | .append("\n\tDNS prefix label: ").append(kubernetesCluster.dnsPrefix()) 1591 | .append("\n\t\tWith Agent pool name: ").append(new ArrayList<>(kubernetesCluster.agentPools().keySet()).get(0)) 1592 | .append("\n\t\tAgent pool count: ").append(new ArrayList<>(kubernetesCluster.agentPools().values()).get(0).count()) 1593 | .append("\n\t\tAgent pool VM size: ").append(new ArrayList<>(kubernetesCluster.agentPools().values()).get(0).vmSize().toString()) 1594 | .append("\n\tLinux user name: ").append(kubernetesCluster.linuxRootUsername()) 1595 | .append("\n\tSSH key: ").append(kubernetesCluster.sshKey()) 1596 | .append("\n\tService principal client ID: ").append(kubernetesCluster.servicePrincipalClientId()); 1597 | 1598 | System.out.println(info.toString()); 1599 | } 1600 | 1601 | /** 1602 | * Print an Azure Search Service. 1603 | * 1604 | * @param searchService an Azure Search Service 1605 | */ 1606 | public static void print(SearchService searchService) { 1607 | StringBuilder info = new StringBuilder(); 1608 | AdminKeys adminKeys = searchService.getAdminKeys(); 1609 | PagedIterable queryKeys = searchService.listQueryKeys(); 1610 | 1611 | info.append("Azure Search: ").append(searchService.id()) 1612 | .append("\n\tResource group: ").append(searchService.resourceGroupName()) 1613 | .append("\n\tRegion: ").append(searchService.region()) 1614 | .append("\n\tTags: ").append(searchService.tags()) 1615 | .append("\n\tSku: ").append(searchService.sku().name()) 1616 | .append("\n\tStatus: ").append(searchService.status()) 1617 | .append("\n\tProvisioning State: ").append(searchService.provisioningState()) 1618 | .append("\n\tHosting Mode: ").append(searchService.hostingMode()) 1619 | .append("\n\tReplicas: ").append(searchService.replicaCount()) 1620 | .append("\n\tPartitions: ").append(searchService.partitionCount()) 1621 | .append("\n\tPrimary Admin Key: ").append(adminKeys.primaryKey()) 1622 | .append("\n\tSecondary Admin Key: ").append(adminKeys.secondaryKey()) 1623 | .append("\n\tQuery keys:"); 1624 | 1625 | for (QueryKey queryKey : queryKeys) { 1626 | info.append("\n\t\tKey name: ").append(queryKey.name()); 1627 | info.append("\n\t\t Value: ").append(queryKey.key()); 1628 | } 1629 | System.out.println(info.toString()); 1630 | } 1631 | 1632 | /** 1633 | * Retrieve the secondary service principal client ID. 1634 | * 1635 | * @param envSecondaryServicePrincipal an Azure Container Registry 1636 | * @return a service principal client ID 1637 | * @throws IOException exception 1638 | */ 1639 | public static String getSecondaryServicePrincipalClientID(String envSecondaryServicePrincipal) throws IOException { 1640 | String content = new String(Files.readAllBytes(new File(envSecondaryServicePrincipal).toPath()), StandardCharsets.UTF_8).trim(); 1641 | HashMap auth = new HashMap<>(); 1642 | 1643 | if (content.startsWith("{")) { 1644 | auth = new JacksonAdapter().deserialize(content, auth.getClass(), SerializerEncoding.JSON); 1645 | return auth.get("clientId"); 1646 | } else { 1647 | Properties authSettings = new Properties(); 1648 | try (FileInputStream credentialsFileStream = new FileInputStream(new File(envSecondaryServicePrincipal))) { 1649 | authSettings.load(credentialsFileStream); 1650 | } 1651 | return authSettings.getProperty("client"); 1652 | } 1653 | } 1654 | 1655 | /** 1656 | * Retrieve the secondary service principal secret. 1657 | * 1658 | * @param envSecondaryServicePrincipal an Azure Container Registry 1659 | * @return a service principal secret 1660 | * @throws IOException exception 1661 | */ 1662 | public static String getSecondaryServicePrincipalSecret(String envSecondaryServicePrincipal) throws IOException { 1663 | String content = new String(Files.readAllBytes(new File(envSecondaryServicePrincipal).toPath()), StandardCharsets.UTF_8).trim(); 1664 | HashMap auth = new HashMap<>(); 1665 | 1666 | if (content.startsWith("{")) { 1667 | auth = new JacksonAdapter().deserialize(content, auth.getClass(), SerializerEncoding.JSON); 1668 | return auth.get("clientSecret"); 1669 | } else { 1670 | Properties authSettings = new Properties(); 1671 | try (FileInputStream credentialsFileStream = new FileInputStream(new File(envSecondaryServicePrincipal))) { 1672 | authSettings.load(credentialsFileStream); 1673 | } 1674 | return authSettings.getProperty("key"); 1675 | } 1676 | } 1677 | // 1678 | // /** 1679 | // * Creates and returns a randomized name based on the prefix file for use by the sample. 1680 | // * 1681 | // * @param namePrefix The prefix string to be used in generating the name. 1682 | // * @return a random name 1683 | // */ 1684 | // public static String createRandomName(String namePrefix) { 1685 | // return ResourceManagerUtils.InternalRuntimeContext.randomResourceName(namePrefix, 30); 1686 | // } 1687 | 1688 | /** 1689 | * This method creates a certificate for given password. 1690 | * 1691 | * @param certPath location of certificate file 1692 | * @param pfxPath location of pfx file 1693 | * @param alias User alias 1694 | * @param password alias password 1695 | * @param cnName domain name 1696 | * @param dnsName dns name in subject alternate name 1697 | * @throws IOException IO Exception 1698 | */ 1699 | public static void createCertificate(String certPath, String pfxPath, String alias, 1700 | String password, String cnName, String dnsName) throws IOException { 1701 | if (new File(pfxPath).exists()) { 1702 | return; 1703 | } 1704 | String validityInDays = "3650"; 1705 | String keyAlg = "RSA"; 1706 | String sigAlg = "SHA1withRSA"; 1707 | String keySize = "2048"; 1708 | String storeType = "pkcs12"; 1709 | String command = "keytool"; 1710 | String jdkPath = System.getProperty("java.home"); 1711 | if (jdkPath != null && !jdkPath.isEmpty()) { 1712 | jdkPath = jdkPath.concat("\\bin"); 1713 | if (new File(jdkPath).isDirectory()) { 1714 | command = String.format("%s%s%s", jdkPath, File.separator, command); 1715 | } 1716 | } else { 1717 | return; 1718 | } 1719 | 1720 | // Create Pfx file 1721 | String[] commandArgs = {command, "-genkey", "-alias", alias, 1722 | "-keystore", pfxPath, "-storepass", password, "-validity", 1723 | validityInDays, "-keyalg", keyAlg, "-sigalg", sigAlg, "-keysize", keySize, 1724 | "-storetype", storeType, "-dname", "CN=" + cnName, "-ext", "EKU=1.3.6.1.5.5.7.3.1"}; 1725 | if (dnsName != null) { 1726 | List args = new ArrayList<>(Arrays.asList(commandArgs)); 1727 | args.add("-ext"); 1728 | args.add("san=dns:" + dnsName); 1729 | commandArgs = args.toArray(new String[0]); 1730 | } 1731 | Utils.cmdInvocation(commandArgs, true); 1732 | 1733 | // Create cer file i.e. extract public key from pfx 1734 | File pfxFile = new File(pfxPath); 1735 | if (pfxFile.exists()) { 1736 | String[] certCommandArgs = {command, "-export", "-alias", alias, 1737 | "-storetype", storeType, "-keystore", pfxPath, 1738 | "-storepass", password, "-rfc", "-file", certPath}; 1739 | // output of keytool export command is going to error stream 1740 | // although command is 1741 | // executed successfully, hence ignoring error stream in this case 1742 | Utils.cmdInvocation(certCommandArgs, true); 1743 | 1744 | // Check if file got created or not 1745 | File cerFile = new File(pfxPath); 1746 | if (!cerFile.exists()) { 1747 | throw new IOException( 1748 | "Error occurred while creating certificate" 1749 | + String.join(" ", certCommandArgs)); 1750 | } 1751 | } else { 1752 | throw new IOException("Error occurred while creating certificates" 1753 | + String.join(" ", commandArgs)); 1754 | } 1755 | } 1756 | 1757 | /** 1758 | * This method is used for invoking native commands. 1759 | * 1760 | * @param command :- command to invoke. 1761 | * @param ignoreErrorStream : Boolean which controls whether to throw exception or not 1762 | * based on error stream. 1763 | * @return result :- depending on the method invocation. 1764 | * @throws IOException exceptions thrown from the execution 1765 | */ 1766 | public static String cmdInvocation(String[] command, 1767 | boolean ignoreErrorStream) throws IOException { 1768 | String result = ""; 1769 | String error = ""; 1770 | 1771 | Process process = new ProcessBuilder(command).start(); 1772 | try ( 1773 | InputStream inputStream = process.getInputStream(); 1774 | InputStream errorStream = process.getErrorStream(); 1775 | BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8)); 1776 | BufferedReader ebr = new BufferedReader(new InputStreamReader(errorStream, StandardCharsets.UTF_8)); 1777 | ) { 1778 | result = br.readLine(); 1779 | process.waitFor(); 1780 | error = ebr.readLine(); 1781 | if (error != null && (!"".equals(error))) { 1782 | // To do - Log error message 1783 | 1784 | if (!ignoreErrorStream) { 1785 | throw new IOException(error, null); 1786 | } 1787 | } 1788 | } catch (Exception e) { 1789 | throw new RuntimeException("Exception occurred while invoking command", e); 1790 | } 1791 | return result; 1792 | } 1793 | 1794 | 1795 | /** 1796 | * Prints information for passed SQL Server. 1797 | * 1798 | * @param sqlServer sqlServer to be printed 1799 | */ 1800 | public static void print(SqlServer sqlServer) { 1801 | StringBuilder builder = new StringBuilder().append("Sql Server: ").append(sqlServer.id()) 1802 | .append("Name: ").append(sqlServer.name()) 1803 | .append("\n\tResource group: ").append(sqlServer.resourceGroupName()) 1804 | .append("\n\tRegion: ").append(sqlServer.region()) 1805 | .append("\n\tSqlServer version: ").append(sqlServer.version()) 1806 | .append("\n\tFully qualified name for Sql Server: ").append(sqlServer.fullyQualifiedDomainName()); 1807 | System.out.println(builder.toString()); 1808 | } 1809 | 1810 | /** 1811 | * Prints information for the passed SQL Database. 1812 | * 1813 | * @param database database to be printed 1814 | */ 1815 | public static void print(SqlDatabase database) { 1816 | StringBuilder builder = new StringBuilder().append("Sql Database: ").append(database.id()) 1817 | .append("Name: ").append(database.name()) 1818 | .append("\n\tResource group: ").append(database.resourceGroupName()) 1819 | .append("\n\tRegion: ").append(database.region()) 1820 | .append("\n\tSqlServer Name: ").append(database.sqlServerName()) 1821 | .append("\n\tEdition of SQL database: ").append(database.edition()) 1822 | .append("\n\tCollation of SQL database: ").append(database.collation()) 1823 | .append("\n\tCreation date of SQL database: ").append(database.creationDate()) 1824 | .append("\n\tIs data warehouse: ").append(database.isDataWarehouse()) 1825 | .append("\n\tRequested service objective of SQL database: ").append(database.requestedServiceObjectiveName()) 1826 | .append("\n\tName of current service objective of SQL database: ").append(database.currentServiceObjectiveName()) 1827 | .append("\n\tMax size bytes of SQL database: ").append(database.maxSizeBytes()) 1828 | .append("\n\tDefault secondary location of SQL database: ").append(database.defaultSecondaryLocation()); 1829 | 1830 | System.out.println(builder.toString()); 1831 | } 1832 | 1833 | /** 1834 | * Prints information for the passed firewall rule. 1835 | * 1836 | * @param firewallRule firewall rule to be printed. 1837 | */ 1838 | public static void print(SqlFirewallRule firewallRule) { 1839 | StringBuilder builder = new StringBuilder().append("Sql firewall rule: ").append(firewallRule.id()) 1840 | .append("Name: ").append(firewallRule.name()) 1841 | .append("\n\tResource group: ").append(firewallRule.resourceGroupName()) 1842 | .append("\n\tRegion: ").append(firewallRule.region()) 1843 | .append("\n\tSqlServer Name: ").append(firewallRule.sqlServerName()) 1844 | .append("\n\tStart IP Address of the firewall rule: ").append(firewallRule.startIpAddress()) 1845 | .append("\n\tEnd IP Address of the firewall rule: ").append(firewallRule.endIpAddress()); 1846 | 1847 | System.out.println(builder.toString()); 1848 | } 1849 | 1850 | /** 1851 | * Prints information for the passed virtual network rule. 1852 | * 1853 | * @param virtualNetworkRule virtual network rule to be printed. 1854 | */ 1855 | public static void print(SqlVirtualNetworkRule virtualNetworkRule) { 1856 | StringBuilder builder = new StringBuilder().append("SQL virtual network rule: ").append(virtualNetworkRule.id()) 1857 | .append("Name: ").append(virtualNetworkRule.name()) 1858 | .append("\n\tResource group: ").append(virtualNetworkRule.resourceGroupName()) 1859 | .append("\n\tSqlServer Name: ").append(virtualNetworkRule.sqlServerName()) 1860 | .append("\n\tSubnet ID: ").append(virtualNetworkRule.subnetId()) 1861 | .append("\n\tState: ").append(virtualNetworkRule.state()); 1862 | 1863 | System.out.println(builder.toString()); 1864 | } 1865 | 1866 | /** 1867 | * Prints information for the passed SQL subscription usage metric. 1868 | * 1869 | * @param subscriptionUsageMetric metric to be printed. 1870 | */ 1871 | public static void print(SqlSubscriptionUsageMetric subscriptionUsageMetric) { 1872 | StringBuilder builder = new StringBuilder().append("SQL Subscription Usage Metric: ").append(subscriptionUsageMetric.id()) 1873 | .append("Name: ").append(subscriptionUsageMetric.name()) 1874 | .append("\n\tDisplay Name: ").append(subscriptionUsageMetric.displayName()) 1875 | .append("\n\tCurrent Value: ").append(subscriptionUsageMetric.currentValue()) 1876 | .append("\n\tLimit: ").append(subscriptionUsageMetric.limit()) 1877 | .append("\n\tUnit: ").append(subscriptionUsageMetric.unit()) 1878 | .append("\n\tType: ").append(subscriptionUsageMetric.type()); 1879 | 1880 | System.out.println(builder.toString()); 1881 | } 1882 | 1883 | /** 1884 | * Prints information for the passed SQL database usage metric. 1885 | * 1886 | * @param dbUsageMetric metric to be printed. 1887 | */ 1888 | public static void print(SqlDatabaseUsageMetric dbUsageMetric) { 1889 | StringBuilder builder = new StringBuilder().append("SQL Database Usage Metric") 1890 | .append("Name: ").append(dbUsageMetric.name()) 1891 | .append("\n\tResource Name: ").append(dbUsageMetric.resourceName()) 1892 | .append("\n\tDisplay Name: ").append(dbUsageMetric.displayName()) 1893 | .append("\n\tCurrent Value: ").append(dbUsageMetric.currentValue()) 1894 | .append("\n\tLimit: ").append(dbUsageMetric.limit()) 1895 | .append("\n\tUnit: ").append(dbUsageMetric.unit()) 1896 | .append("\n\tNext Reset Time: ").append(dbUsageMetric.nextResetTime()); 1897 | 1898 | System.out.println(builder.toString()); 1899 | } 1900 | 1901 | /** 1902 | * Prints information for the passed SQL database metric. 1903 | * 1904 | * @param dbMetric metric to be printed. 1905 | */ 1906 | public static void print(SqlDatabaseMetric dbMetric) { 1907 | StringBuilder builder = new StringBuilder().append("SQL Database Metric") 1908 | .append("Name: ").append(dbMetric.name()) 1909 | .append("\n\tStart Time: ").append(dbMetric.startTime()) 1910 | .append("\n\tEnd Time: ").append(dbMetric.endTime()) 1911 | .append("\n\tTime Grain: ").append(dbMetric.timeGrain()) 1912 | .append("\n\tUnit: ").append(dbMetric.unit()); 1913 | for (SqlDatabaseMetricValue metricValue : dbMetric.metricValues()) { 1914 | builder 1915 | .append("\n\tMetric Value: ") 1916 | .append("\n\t\tCount: ").append(metricValue.count()) 1917 | .append("\n\t\tAverage: ").append(metricValue.average()) 1918 | .append("\n\t\tMaximum: ").append(metricValue.maximum()) 1919 | .append("\n\t\tMinimum: ").append(metricValue.minimum()) 1920 | .append("\n\t\tTimestamp: ").append(metricValue.timestamp()) 1921 | .append("\n\t\tTotal: ").append(metricValue.total()); 1922 | } 1923 | 1924 | System.out.println(builder.toString()); 1925 | } 1926 | 1927 | /** 1928 | * Prints information for the passed Failover Group. 1929 | * 1930 | * @param failoverGroup the SQL Failover Group to be printed. 1931 | */ 1932 | public static void print(SqlFailoverGroup failoverGroup) { 1933 | StringBuilder builder = new StringBuilder().append("SQL Failover Group: ").append(failoverGroup.id()) 1934 | .append("Name: ").append(failoverGroup.name()) 1935 | .append("\n\tResource group: ").append(failoverGroup.resourceGroupName()) 1936 | .append("\n\tSqlServer Name: ").append(failoverGroup.sqlServerName()) 1937 | .append("\n\tRead-write endpoint policy: ").append(failoverGroup.readWriteEndpointPolicy()) 1938 | .append("\n\tData loss grace period: ").append(failoverGroup.readWriteEndpointDataLossGracePeriodMinutes()) 1939 | .append("\n\tRead-only endpoint policy: ").append(failoverGroup.readOnlyEndpointPolicy()) 1940 | .append("\n\tReplication state: ").append(failoverGroup.replicationState()) 1941 | .append("\n\tReplication role: ").append(failoverGroup.replicationRole()); 1942 | builder.append("\n\tPartner Servers: "); 1943 | for (PartnerInfo item : failoverGroup.partnerServers()) { 1944 | builder 1945 | .append("\n\t\tId: ").append(item.id()) 1946 | .append("\n\t\tLocation: ").append(item.location()) 1947 | .append("\n\t\tReplication role: ").append(item.replicationRole()); 1948 | } 1949 | builder.append("\n\tDatabases: "); 1950 | for (String databaseId : failoverGroup.databases()) { 1951 | builder.append("\n\t\tID: ").append(databaseId); 1952 | } 1953 | 1954 | System.out.println(builder.toString()); 1955 | } 1956 | 1957 | /** 1958 | * Prints information for the passed SQL server key. 1959 | * 1960 | * @param serverKey virtual network rule to be printed. 1961 | */ 1962 | public static void print(SqlServerKey serverKey) { 1963 | StringBuilder builder = new StringBuilder().append("SQL server key: ").append(serverKey.id()) 1964 | .append("Name: ").append(serverKey.name()) 1965 | .append("\n\tResource group: ").append(serverKey.resourceGroupName()) 1966 | .append("\n\tSqlServer Name: ").append(serverKey.sqlServerName()) 1967 | .append("\n\tRegion: ").append(serverKey.region() != null ? serverKey.region().name() : "") 1968 | .append("\n\tServer Key Type: ").append(serverKey.serverKeyType()) 1969 | .append("\n\tServer Key URI: ").append(serverKey.uri()) 1970 | .append("\n\tServer Key Thumbprint: ").append(serverKey.thumbprint()) 1971 | .append("\n\tServer Key Creation Date: ").append(serverKey.creationDate() != null ? serverKey.creationDate().toString() : ""); 1972 | 1973 | System.out.println(builder.toString()); 1974 | } 1975 | 1976 | /** 1977 | * Prints information of the elastic pool passed in. 1978 | * 1979 | * @param elasticPool elastic pool to be printed 1980 | */ 1981 | public static void print(SqlElasticPool elasticPool) { 1982 | StringBuilder builder = new StringBuilder().append("Sql elastic pool: ").append(elasticPool.id()) 1983 | .append("Name: ").append(elasticPool.name()) 1984 | .append("\n\tResource group: ").append(elasticPool.resourceGroupName()) 1985 | .append("\n\tRegion: ").append(elasticPool.region()) 1986 | .append("\n\tSqlServer Name: ").append(elasticPool.sqlServerName()) 1987 | .append("\n\tEdition of elastic pool: ").append(elasticPool.edition()) 1988 | .append("\n\tTotal number of DTUs in the elastic pool: ").append(elasticPool.dtu()) 1989 | .append("\n\tMaximum DTUs a database can get in elastic pool: ").append(elasticPool.databaseDtuMax()) 1990 | .append("\n\tMinimum DTUs a database is guaranteed in elastic pool: ").append(elasticPool.databaseDtuMin()) 1991 | .append("\n\tCreation date for the elastic pool: ").append(elasticPool.creationDate()) 1992 | .append("\n\tState of the elastic pool: ").append(elasticPool.state()) 1993 | .append("\n\tStorage capacity in MBs for the elastic pool: ").append(elasticPool.storageCapacity()); 1994 | 1995 | System.out.println(builder.toString()); 1996 | } 1997 | 1998 | /** 1999 | * Prints information of the elastic pool activity. 2000 | * 2001 | * @param elasticPoolActivity elastic pool activity to be printed 2002 | */ 2003 | public static void print(ElasticPoolActivity elasticPoolActivity) { 2004 | StringBuilder builder = new StringBuilder().append("Sql elastic pool activity: ").append(elasticPoolActivity.id()) 2005 | .append("Name: ").append(elasticPoolActivity.name()) 2006 | .append("\n\tResource group: ").append(elasticPoolActivity.resourceGroupName()) 2007 | .append("\n\tState: ").append(elasticPoolActivity.state()) 2008 | .append("\n\tElastic pool name: ").append(elasticPoolActivity.elasticPoolName()) 2009 | .append("\n\tStart time of activity: ").append(elasticPoolActivity.startTime()) 2010 | .append("\n\tEnd time of activity: ").append(elasticPoolActivity.endTime()) 2011 | .append("\n\tError code of activity: ").append(elasticPoolActivity.errorCode()) 2012 | .append("\n\tError message of activity: ").append(elasticPoolActivity.errorMessage()) 2013 | .append("\n\tError severity of activity: ").append(elasticPoolActivity.errorSeverity()) 2014 | .append("\n\tOperation: ").append(elasticPoolActivity.operation()) 2015 | .append("\n\tCompleted percentage of activity: ").append(elasticPoolActivity.percentComplete()) 2016 | .append("\n\tRequested DTU max limit in activity: ").append(elasticPoolActivity.requestedDatabaseDtuMax()) 2017 | .append("\n\tRequested DTU min limit in activity: ").append(elasticPoolActivity.requestedDatabaseDtuMin()) 2018 | .append("\n\tRequested DTU limit in activity: ").append(elasticPoolActivity.requestedDtu()); 2019 | 2020 | System.out.println(builder.toString()); 2021 | 2022 | } 2023 | 2024 | /** 2025 | * Prints information of the database activity. 2026 | * 2027 | * @param databaseActivity database activity to be printed 2028 | */ 2029 | public static void print(ElasticPoolDatabaseActivity databaseActivity) { 2030 | StringBuilder builder = new StringBuilder().append("Sql elastic pool database activity: ").append(databaseActivity.id()) 2031 | .append("Name: ").append(databaseActivity.name()) 2032 | .append("\n\tResource group: ").append(databaseActivity.resourceGroupName()) 2033 | .append("\n\tSQL Server Name: ").append(databaseActivity.serverName()) 2034 | .append("\n\tDatabase name name: ").append(databaseActivity.databaseName()) 2035 | .append("\n\tCurrent elastic pool name of the database: ").append(databaseActivity.currentElasticPoolName()) 2036 | .append("\n\tState: ").append(databaseActivity.state()) 2037 | .append("\n\tStart time of activity: ").append(databaseActivity.startTime()) 2038 | .append("\n\tEnd time of activity: ").append(databaseActivity.endTime()) 2039 | .append("\n\tCompleted percentage: ").append(databaseActivity.percentComplete()) 2040 | .append("\n\tError code of activity: ").append(databaseActivity.errorCode()) 2041 | .append("\n\tError message of activity: ").append(databaseActivity.errorMessage()) 2042 | .append("\n\tError severity of activity: ").append(databaseActivity.errorSeverity()); 2043 | 2044 | System.out.println(builder.toString()); 2045 | } 2046 | 2047 | /** 2048 | * Print an application gateway. 2049 | * 2050 | * @param resource an application gateway 2051 | */ 2052 | public static void print(ApplicationGateway resource) { 2053 | StringBuilder info = new StringBuilder(); 2054 | info.append("Application gateway: ").append(resource.id()) 2055 | .append("Name: ").append(resource.name()) 2056 | .append("\n\tResource group: ").append(resource.resourceGroupName()) 2057 | .append("\n\tRegion: ").append(resource.region()) 2058 | .append("\n\tTags: ").append(resource.tags()) 2059 | .append("\n\tSKU: ").append(resource.sku().toString()) 2060 | .append("\n\tOperational state: ").append(resource.operationalState()) 2061 | .append("\n\tInternet-facing? ").append(resource.isPublic()) 2062 | .append("\n\tInternal? ").append(resource.isPrivate()) 2063 | .append("\n\tDefault private IP address: ").append(resource.privateIpAddress()) 2064 | .append("\n\tPrivate IP address allocation method: ").append(resource.privateIpAllocationMethod()) 2065 | .append("\n\tDisabled SSL protocols: ").append(resource.disabledSslProtocols().toString()); 2066 | 2067 | // Show IP configs 2068 | Map ipConfigs = resource.ipConfigurations(); 2069 | info.append("\n\tIP configurations: ").append(ipConfigs.size()); 2070 | for (ApplicationGatewayIpConfiguration ipConfig : ipConfigs.values()) { 2071 | info.append("\n\t\tName: ").append(ipConfig.name()) 2072 | .append("\n\t\t\tNetwork id: ").append(ipConfig.networkId()) 2073 | .append("\n\t\t\tSubnet name: ").append(ipConfig.subnetName()); 2074 | } 2075 | 2076 | // Show frontends 2077 | Map frontends = resource.frontends(); 2078 | info.append("\n\tFrontends: ").append(frontends.size()); 2079 | for (ApplicationGatewayFrontend frontend : frontends.values()) { 2080 | info.append("\n\t\tName: ").append(frontend.name()) 2081 | .append("\n\t\t\tPublic? ").append(frontend.isPublic()); 2082 | 2083 | if (frontend.isPublic()) { 2084 | // Show public frontend info 2085 | info.append("\n\t\t\tPublic IP address ID: ").append(frontend.publicIpAddressId()); 2086 | } 2087 | 2088 | if (frontend.isPrivate()) { 2089 | // Show private frontend info 2090 | info.append("\n\t\t\tPrivate IP address: ").append(frontend.privateIpAddress()) 2091 | .append("\n\t\t\tPrivate IP allocation method: ").append(frontend.privateIpAllocationMethod()) 2092 | .append("\n\t\t\tSubnet name: ").append(frontend.subnetName()) 2093 | .append("\n\t\t\tVirtual network ID: ").append(frontend.networkId()); 2094 | } 2095 | } 2096 | 2097 | // Show backends 2098 | Map backends = resource.backends(); 2099 | info.append("\n\tBackends: ").append(backends.size()); 2100 | for (ApplicationGatewayBackend backend : backends.values()) { 2101 | info.append("\n\t\tName: ").append(backend.name()) 2102 | .append("\n\t\t\tAssociated NIC IP configuration IDs: ").append(backend.backendNicIPConfigurationNames().keySet()); 2103 | 2104 | // Show addresses 2105 | Collection addresses = backend.addresses(); 2106 | info.append("\n\t\t\tAddresses: ").append(addresses.size()); 2107 | for (ApplicationGatewayBackendAddress address : addresses) { 2108 | info.append("\n\t\t\t\tFQDN: ").append(address.fqdn()) 2109 | .append("\n\t\t\t\tIP: ").append(address.ipAddress()); 2110 | } 2111 | } 2112 | 2113 | // Show backend HTTP configurations 2114 | Map httpConfigs = resource.backendHttpConfigurations(); 2115 | info.append("\n\tHTTP Configurations: ").append(httpConfigs.size()); 2116 | for (ApplicationGatewayBackendHttpConfiguration httpConfig : httpConfigs.values()) { 2117 | info.append("\n\t\tName: ").append(httpConfig.name()) 2118 | .append("\n\t\t\tCookie based affinity: ").append(httpConfig.cookieBasedAffinity()) 2119 | .append("\n\t\t\tPort: ").append(httpConfig.port()) 2120 | .append("\n\t\t\tRequest timeout in seconds: ").append(httpConfig.requestTimeout()) 2121 | .append("\n\t\t\tProtocol: ").append(httpConfig.protocol()) 2122 | .append("\n\t\tHost header: ").append(httpConfig.hostHeader()) 2123 | .append("\n\t\tHost header comes from backend? ").append(httpConfig.isHostHeaderFromBackend()) 2124 | .append("\n\t\tConnection draining timeout in seconds: ").append(httpConfig.connectionDrainingTimeoutInSeconds()) 2125 | .append("\n\t\tAffinity cookie name: ").append(httpConfig.affinityCookieName()) 2126 | .append("\n\t\tPath: ").append(httpConfig.path()); 2127 | ApplicationGatewayProbe probe = httpConfig.probe(); 2128 | if (probe != null) { 2129 | info.append("\n\t\tProbe: " + probe.name()); 2130 | } 2131 | info.append("\n\t\tIs probe enabled? ").append(httpConfig.isProbeEnabled()); 2132 | } 2133 | 2134 | // Show SSL certificates 2135 | Map sslCerts = resource.sslCertificates(); 2136 | info.append("\n\tSSL certificates: ").append(sslCerts.size()); 2137 | for (ApplicationGatewaySslCertificate cert : sslCerts.values()) { 2138 | info.append("\n\t\tName: ").append(cert.name()) 2139 | .append("\n\t\t\tCert data: ").append(cert.publicData()); 2140 | } 2141 | 2142 | // Show redirect configurations 2143 | Map redirects = resource.redirectConfigurations(); 2144 | info.append("\n\tRedirect configurations: ").append(redirects.size()); 2145 | for (ApplicationGatewayRedirectConfiguration redirect : redirects.values()) { 2146 | info.append("\n\t\tName: ").append(redirect.name()) 2147 | .append("\n\t\tTarget URL: ").append(redirect.type()) 2148 | .append("\n\t\tTarget URL: ").append(redirect.targetUrl()) 2149 | .append("\n\t\tTarget listener: ").append(redirect.targetListener() != null ? redirect.targetListener().name() : null) 2150 | .append("\n\t\tIs path included? ").append(redirect.isPathIncluded()) 2151 | .append("\n\t\tIs query string included? ").append(redirect.isQueryStringIncluded()) 2152 | .append("\n\t\tReferencing request routing rules: ").append(redirect.requestRoutingRules().values()); 2153 | } 2154 | 2155 | // Show HTTP listeners 2156 | Map listeners = resource.listeners(); 2157 | info.append("\n\tHTTP listeners: ").append(listeners.size()); 2158 | for (ApplicationGatewayListener listener : listeners.values()) { 2159 | info.append("\n\t\tName: ").append(listener.name()) 2160 | .append("\n\t\t\tHost name: ").append(listener.hostname()) 2161 | .append("\n\t\t\tServer name indication required? ").append(listener.requiresServerNameIndication()) 2162 | .append("\n\t\t\tAssociated frontend name: ").append(listener.frontend().name()) 2163 | .append("\n\t\t\tFrontend port name: ").append(listener.frontendPortName()) 2164 | .append("\n\t\t\tFrontend port number: ").append(listener.frontendPortNumber()) 2165 | .append("\n\t\t\tProtocol: ").append(listener.protocol().toString()); 2166 | if (listener.sslCertificate() != null) { 2167 | info.append("\n\t\t\tAssociated SSL certificate: ").append(listener.sslCertificate().name()); 2168 | } 2169 | } 2170 | 2171 | // Show probes 2172 | Map probes = resource.probes(); 2173 | info.append("\n\tProbes: ").append(probes.size()); 2174 | for (ApplicationGatewayProbe probe : probes.values()) { 2175 | info.append("\n\t\tName: ").append(probe.name()) 2176 | .append("\n\t\tProtocol:").append(probe.protocol().toString()) 2177 | .append("\n\t\tInterval in seconds: ").append(probe.timeBetweenProbesInSeconds()) 2178 | .append("\n\t\tRetries: ").append(probe.retriesBeforeUnhealthy()) 2179 | .append("\n\t\tTimeout: ").append(probe.timeoutInSeconds()) 2180 | .append("\n\t\tHost: ").append(probe.host()) 2181 | .append("\n\t\tHealthy HTTP response status code ranges: ").append(probe.healthyHttpResponseStatusCodeRanges()) 2182 | .append("\n\t\tHealthy HTTP response body contents: ").append(probe.healthyHttpResponseBodyContents()); 2183 | } 2184 | 2185 | // Show request routing rules 2186 | Map rules = resource.requestRoutingRules(); 2187 | info.append("\n\tRequest routing rules: ").append(rules.size()); 2188 | for (ApplicationGatewayRequestRoutingRule rule : rules.values()) { 2189 | info.append("\n\t\tName: ").append(rule.name()) 2190 | .append("\n\t\tType: ").append(rule.ruleType()) 2191 | .append("\n\t\tPublic IP address ID: ").append(rule.publicIpAddressId()) 2192 | .append("\n\t\tHost name: ").append(rule.hostname()) 2193 | .append("\n\t\tServer name indication required? ").append(rule.requiresServerNameIndication()) 2194 | .append("\n\t\tFrontend port: ").append(rule.frontendPort()) 2195 | .append("\n\t\tFrontend protocol: ").append(rule.frontendProtocol().toString()) 2196 | .append("\n\t\tBackend port: ").append(rule.backendPort()) 2197 | .append("\n\t\tCookie based affinity enabled? ").append(rule.cookieBasedAffinity()) 2198 | .append("\n\t\tRedirect configuration: ").append(rule.redirectConfiguration() != null ? rule.redirectConfiguration().name() : "(none)"); 2199 | 2200 | // Show backend addresses 2201 | Collection addresses = rule.backendAddresses(); 2202 | info.append("\n\t\t\tBackend addresses: ").append(addresses.size()); 2203 | for (ApplicationGatewayBackendAddress address : addresses) { 2204 | info.append("\n\t\t\t\t") 2205 | .append(address.fqdn()) 2206 | .append(" [").append(address.ipAddress()).append("]"); 2207 | } 2208 | 2209 | // Show SSL cert 2210 | info.append("\n\t\t\tSSL certificate name: "); 2211 | ApplicationGatewaySslCertificate cert = rule.sslCertificate(); 2212 | if (cert == null) { 2213 | info.append("(None)"); 2214 | } else { 2215 | info.append(cert.name()); 2216 | } 2217 | 2218 | // Show backend 2219 | info.append("\n\t\t\tAssociated backend address pool: "); 2220 | ApplicationGatewayBackend backend = rule.backend(); 2221 | if (backend == null) { 2222 | info.append("(None)"); 2223 | } else { 2224 | info.append(backend.name()); 2225 | } 2226 | 2227 | // Show backend HTTP settings config 2228 | info.append("\n\t\t\tAssociated backend HTTP settings configuration: "); 2229 | ApplicationGatewayBackendHttpConfiguration config = rule.backendHttpConfiguration(); 2230 | if (config == null) { 2231 | info.append("(None)"); 2232 | } else { 2233 | info.append(config.name()); 2234 | } 2235 | 2236 | // Show frontend listener 2237 | info.append("\n\t\t\tAssociated frontend listener: "); 2238 | ApplicationGatewayListener listener = rule.listener(); 2239 | if (listener == null) { 2240 | info.append("(None)"); 2241 | } else { 2242 | info.append(config.name()); 2243 | } 2244 | } 2245 | System.out.println(info.toString()); 2246 | } 2247 | 2248 | /** 2249 | * Prints information of a virtual machine custom image. 2250 | * 2251 | * @param image the image 2252 | */ 2253 | public static void print(VirtualMachineCustomImage image) { 2254 | StringBuilder builder = new StringBuilder().append("Virtual machine custom image: ").append(image.id()) 2255 | .append("Name: ").append(image.name()) 2256 | .append("\n\tResource group: ").append(image.resourceGroupName()) 2257 | .append("\n\tCreated from virtual machine: ").append(image.sourceVirtualMachineId()); 2258 | 2259 | builder.append("\n\tOS disk image: ") 2260 | .append("\n\t\tOperating system: ").append(image.osDiskImage().osType()) 2261 | .append("\n\t\tOperating system state: ").append(image.osDiskImage().osState()) 2262 | .append("\n\t\tCaching: ").append(image.osDiskImage().caching()) 2263 | .append("\n\t\tSize (GB): ").append(image.osDiskImage().diskSizeGB()); 2264 | if (image.isCreatedFromVirtualMachine()) { 2265 | builder.append("\n\t\tSource virtual machine: ").append(image.sourceVirtualMachineId()); 2266 | } 2267 | if (image.osDiskImage().managedDisk() != null) { 2268 | builder.append("\n\t\tSource managed disk: ").append(image.osDiskImage().managedDisk().id()); 2269 | } 2270 | if (image.osDiskImage().snapshot() != null) { 2271 | builder.append("\n\t\tSource snapshot: ").append(image.osDiskImage().snapshot().id()); 2272 | } 2273 | if (image.osDiskImage().blobUri() != null) { 2274 | builder.append("\n\t\tSource un-managed vhd: ").append(image.osDiskImage().blobUri()); 2275 | } 2276 | if (image.dataDiskImages() != null) { 2277 | for (ImageDataDisk diskImage : image.dataDiskImages().values()) { 2278 | builder.append("\n\tDisk Image (Lun) #: ").append(diskImage.lun()) 2279 | .append("\n\t\tCaching: ").append(diskImage.caching()) 2280 | .append("\n\t\tSize (GB): ").append(diskImage.diskSizeGB()); 2281 | if (image.isCreatedFromVirtualMachine()) { 2282 | builder.append("\n\t\tSource virtual machine: ").append(image.sourceVirtualMachineId()); 2283 | } 2284 | if (diskImage.managedDisk() != null) { 2285 | builder.append("\n\t\tSource managed disk: ").append(diskImage.managedDisk().id()); 2286 | } 2287 | if (diskImage.snapshot() != null) { 2288 | builder.append("\n\t\tSource snapshot: ").append(diskImage.snapshot().id()); 2289 | } 2290 | if (diskImage.blobUri() != null) { 2291 | builder.append("\n\t\tSource un-managed vhd: ").append(diskImage.blobUri()); 2292 | } 2293 | } 2294 | } 2295 | System.out.println(builder.toString()); 2296 | } 2297 | 2298 | /** 2299 | * Uploads a file to an Azure app service for Web App. 2300 | * 2301 | * @param profile the publishing profile for the app service. 2302 | * @param fileName the name of the file on server 2303 | * @param file the local file 2304 | */ 2305 | public static void uploadFileViaFtp(PublishingProfile profile, String fileName, InputStream file) { 2306 | String path = "./site/wwwroot/webapps"; 2307 | uploadFileViaFtp(profile, fileName, file, path); 2308 | } 2309 | 2310 | /** 2311 | * Uploads a file to an Azure app service for Function App. 2312 | * 2313 | * @param profile the publishing profile for the app service. 2314 | * @param fileName the name of the file on server 2315 | * @param file the local file 2316 | */ 2317 | public static void uploadFileForFunctionViaFtp(PublishingProfile profile, String fileName, InputStream file) { 2318 | String path = "./site/wwwroot"; 2319 | uploadFileViaFtp(profile, fileName, file, path); 2320 | } 2321 | 2322 | private static void uploadFileViaFtp(PublishingProfile profile, String fileName, InputStream file, String path) { 2323 | FTPClient ftpClient = new FTPClient(); 2324 | String[] ftpUrlSegments = profile.ftpUrl().split("/", 2); 2325 | String server = ftpUrlSegments[0]; 2326 | if (fileName.contains("/")) { 2327 | int lastslash = fileName.lastIndexOf('/'); 2328 | path = path + "/" + fileName.substring(0, lastslash); 2329 | fileName = fileName.substring(lastslash + 1); 2330 | } 2331 | try { 2332 | ftpClient.connect(server); 2333 | ftpClient.enterLocalPassiveMode(); 2334 | ftpClient.login(profile.ftpUsername(), profile.ftpPassword()); 2335 | ftpClient.setFileType(FTP.BINARY_FILE_TYPE); 2336 | for (String segment : path.split("/")) { 2337 | if (!ftpClient.changeWorkingDirectory(segment)) { 2338 | ftpClient.makeDirectory(segment); 2339 | ftpClient.changeWorkingDirectory(segment); 2340 | } 2341 | } 2342 | ftpClient.storeFile(fileName, file); 2343 | ftpClient.disconnect(); 2344 | } catch (IOException e) { 2345 | e.printStackTrace(); 2346 | } 2347 | } 2348 | 2349 | /** 2350 | * Print service bus namespace info. 2351 | * 2352 | * @param serviceBusNamespace a service bus namespace 2353 | */ 2354 | public static void print(ServiceBusNamespace serviceBusNamespace) { 2355 | StringBuilder builder = new StringBuilder() 2356 | .append("Service bus Namespace: ").append(serviceBusNamespace.id()) 2357 | .append("\n\tName: ").append(serviceBusNamespace.name()) 2358 | .append("\n\tRegion: ").append(serviceBusNamespace.regionName()) 2359 | .append("\n\tResourceGroupName: ").append(serviceBusNamespace.resourceGroupName()) 2360 | .append("\n\tCreatedAt: ").append(serviceBusNamespace.createdAt()) 2361 | .append("\n\tUpdatedAt: ").append(serviceBusNamespace.updatedAt()) 2362 | .append("\n\tDnsLabel: ").append(serviceBusNamespace.dnsLabel()) 2363 | .append("\n\tFQDN: ").append(serviceBusNamespace.fqdn()) 2364 | .append("\n\tSku: ") 2365 | .append("\n\t\tCapacity: ").append(serviceBusNamespace.sku().capacity()) 2366 | .append("\n\t\tSkuName: ").append(serviceBusNamespace.sku().name()) 2367 | .append("\n\t\tTier: ").append(serviceBusNamespace.sku().tier()); 2368 | 2369 | System.out.println(builder.toString()); 2370 | } 2371 | 2372 | /** 2373 | * Print service bus queue info. 2374 | * 2375 | * @param queue a service bus queue 2376 | */ 2377 | public static void print(Queue queue) { 2378 | StringBuilder builder = new StringBuilder() 2379 | .append("Service bus Queue: ").append(queue.id()) 2380 | .append("\n\tName: ").append(queue.name()) 2381 | .append("\n\tResourceGroupName: ").append(queue.resourceGroupName()) 2382 | .append("\n\tCreatedAt: ").append(queue.createdAt()) 2383 | .append("\n\tUpdatedAt: ").append(queue.updatedAt()) 2384 | .append("\n\tAccessedAt: ").append(queue.accessedAt()) 2385 | .append("\n\tActiveMessageCount: ").append(queue.activeMessageCount()) 2386 | .append("\n\tCurrentSizeInBytes: ").append(queue.currentSizeInBytes()) 2387 | .append("\n\tDeadLetterMessageCount: ").append(queue.deadLetterMessageCount()) 2388 | .append("\n\tDefaultMessageTtlDuration: ").append(queue.defaultMessageTtlDuration()) 2389 | .append("\n\tDuplicateMessageDetectionHistoryDuration: ").append(queue.duplicateMessageDetectionHistoryDuration()) 2390 | .append("\n\tIsBatchedOperationsEnabled: ").append(queue.isBatchedOperationsEnabled()) 2391 | .append("\n\tIsDeadLetteringEnabledForExpiredMessages: ").append(queue.isDeadLetteringEnabledForExpiredMessages()) 2392 | .append("\n\tIsDuplicateDetectionEnabled: ").append(queue.isDuplicateDetectionEnabled()) 2393 | .append("\n\tIsExpressEnabled: ").append(queue.isExpressEnabled()) 2394 | .append("\n\tIsPartitioningEnabled: ").append(queue.isPartitioningEnabled()) 2395 | .append("\n\tIsSessionEnabled: ").append(queue.isSessionEnabled()) 2396 | .append("\n\tDeleteOnIdleDurationInMinutes: ").append(queue.deleteOnIdleDurationInMinutes()) 2397 | .append("\n\tMaxDeliveryCountBeforeDeadLetteringMessage: ").append(queue.maxDeliveryCountBeforeDeadLetteringMessage()) 2398 | .append("\n\tMaxSizeInMB: ").append(queue.maxSizeInMB()) 2399 | .append("\n\tMessageCount: ").append(queue.messageCount()) 2400 | .append("\n\tScheduledMessageCount: ").append(queue.scheduledMessageCount()) 2401 | .append("\n\tStatus: ").append(queue.status()) 2402 | .append("\n\tTransferMessageCount: ").append(queue.transferMessageCount()) 2403 | .append("\n\tLockDurationInSeconds: ").append(queue.lockDurationInSeconds()) 2404 | .append("\n\tTransferDeadLetterMessageCount: ").append(queue.transferDeadLetterMessageCount()); 2405 | 2406 | System.out.println(builder.toString()); 2407 | 2408 | } 2409 | 2410 | /** 2411 | * Print service bus queue authorization keys info. 2412 | * 2413 | * @param queueAuthorizationRule a service bus queue authorization keys 2414 | */ 2415 | public static void print(QueueAuthorizationRule queueAuthorizationRule) { 2416 | StringBuilder builder = new StringBuilder() 2417 | .append("Service bus queue authorization rule: ").append(queueAuthorizationRule.id()) 2418 | .append("\n\tName: ").append(queueAuthorizationRule.name()) 2419 | .append("\n\tResourceGroupName: ").append(queueAuthorizationRule.resourceGroupName()) 2420 | .append("\n\tNamespace Name: ").append(queueAuthorizationRule.namespaceName()) 2421 | .append("\n\tQueue Name: ").append(queueAuthorizationRule.queueName()); 2422 | 2423 | List rights = queueAuthorizationRule.rights(); 2424 | builder.append("\n\tNumber of access rights in queue: ").append(rights.size()); 2425 | for (com.azure.resourcemanager.servicebus.models.AccessRights right : rights) { 2426 | builder.append("\n\t\tAccessRight: ") 2427 | .append("\n\t\t\tName :").append(right.name()); 2428 | } 2429 | 2430 | System.out.println(builder.toString()); 2431 | } 2432 | 2433 | /** 2434 | * Print service bus namespace authorization keys info. 2435 | * 2436 | * @param keys a service bus namespace authorization keys 2437 | */ 2438 | public static void print(AuthorizationKeys keys) { 2439 | StringBuilder builder = new StringBuilder() 2440 | .append("Authorization keys: ") 2441 | .append("\n\tPrimaryKey: ").append(keys.primaryKey()) 2442 | .append("\n\tPrimaryConnectionString: ").append(keys.primaryConnectionString()) 2443 | .append("\n\tSecondaryKey: ").append(keys.secondaryKey()) 2444 | .append("\n\tSecondaryConnectionString: ").append(keys.secondaryConnectionString()); 2445 | 2446 | System.out.println(builder.toString()); 2447 | } 2448 | 2449 | /** 2450 | * Print service bus namespace authorization rule info. 2451 | * 2452 | * @param namespaceAuthorizationRule a service bus namespace authorization rule 2453 | */ 2454 | public static void print(NamespaceAuthorizationRule namespaceAuthorizationRule) { 2455 | StringBuilder builder = new StringBuilder() 2456 | .append("Service bus queue authorization rule: ").append(namespaceAuthorizationRule.id()) 2457 | .append("\n\tName: ").append(namespaceAuthorizationRule.name()) 2458 | .append("\n\tResourceGroupName: ").append(namespaceAuthorizationRule.resourceGroupName()) 2459 | .append("\n\tNamespace Name: ").append(namespaceAuthorizationRule.namespaceName()); 2460 | 2461 | List rights = namespaceAuthorizationRule.rights(); 2462 | builder.append("\n\tNumber of access rights in queue: ").append(rights.size()); 2463 | for (com.azure.resourcemanager.servicebus.models.AccessRights right : rights) { 2464 | builder.append("\n\t\tAccessRight: ") 2465 | .append("\n\t\t\tName :").append(right.name()); 2466 | } 2467 | 2468 | System.out.println(builder.toString()); 2469 | } 2470 | 2471 | /** 2472 | * Print service bus topic info. 2473 | * 2474 | * @param topic a service bus topic 2475 | */ 2476 | public static void print(Topic topic) { 2477 | StringBuilder builder = new StringBuilder() 2478 | .append("Service bus topic: ").append(topic.id()) 2479 | .append("\n\tName: ").append(topic.name()) 2480 | .append("\n\tResourceGroupName: ").append(topic.resourceGroupName()) 2481 | .append("\n\tCreatedAt: ").append(topic.createdAt()) 2482 | .append("\n\tUpdatedAt: ").append(topic.updatedAt()) 2483 | .append("\n\tAccessedAt: ").append(topic.accessedAt()) 2484 | .append("\n\tActiveMessageCount: ").append(topic.activeMessageCount()) 2485 | .append("\n\tCurrentSizeInBytes: ").append(topic.currentSizeInBytes()) 2486 | .append("\n\tDeadLetterMessageCount: ").append(topic.deadLetterMessageCount()) 2487 | .append("\n\tDefaultMessageTtlDuration: ").append(topic.defaultMessageTtlDuration()) 2488 | .append("\n\tDuplicateMessageDetectionHistoryDuration: ").append(topic.duplicateMessageDetectionHistoryDuration()) 2489 | .append("\n\tIsBatchedOperationsEnabled: ").append(topic.isBatchedOperationsEnabled()) 2490 | .append("\n\tIsDuplicateDetectionEnabled: ").append(topic.isDuplicateDetectionEnabled()) 2491 | .append("\n\tIsExpressEnabled: ").append(topic.isExpressEnabled()) 2492 | .append("\n\tIsPartitioningEnabled: ").append(topic.isPartitioningEnabled()) 2493 | .append("\n\tDeleteOnIdleDurationInMinutes: ").append(topic.deleteOnIdleDurationInMinutes()) 2494 | .append("\n\tMaxSizeInMB: ").append(topic.maxSizeInMB()) 2495 | .append("\n\tScheduledMessageCount: ").append(topic.scheduledMessageCount()) 2496 | .append("\n\tStatus: ").append(topic.status()) 2497 | .append("\n\tTransferMessageCount: ").append(topic.transferMessageCount()) 2498 | .append("\n\tSubscriptionCount: ").append(topic.subscriptionCount()) 2499 | .append("\n\tTransferDeadLetterMessageCount: ").append(topic.transferDeadLetterMessageCount()); 2500 | 2501 | System.out.println(builder.toString()); 2502 | } 2503 | 2504 | /** 2505 | * Print service bus subscription info. 2506 | * 2507 | * @param serviceBusSubscription a service bus subscription 2508 | */ 2509 | public static void print(ServiceBusSubscription serviceBusSubscription) { 2510 | StringBuilder builder = new StringBuilder() 2511 | .append("Service bus subscription: ").append(serviceBusSubscription.id()) 2512 | .append("\n\tName: ").append(serviceBusSubscription.name()) 2513 | .append("\n\tResourceGroupName: ").append(serviceBusSubscription.resourceGroupName()) 2514 | .append("\n\tCreatedAt: ").append(serviceBusSubscription.createdAt()) 2515 | .append("\n\tUpdatedAt: ").append(serviceBusSubscription.updatedAt()) 2516 | .append("\n\tAccessedAt: ").append(serviceBusSubscription.accessedAt()) 2517 | .append("\n\tActiveMessageCount: ").append(serviceBusSubscription.activeMessageCount()) 2518 | .append("\n\tDeadLetterMessageCount: ").append(serviceBusSubscription.deadLetterMessageCount()) 2519 | .append("\n\tDefaultMessageTtlDuration: ").append(serviceBusSubscription.defaultMessageTtlDuration()) 2520 | .append("\n\tIsBatchedOperationsEnabled: ").append(serviceBusSubscription.isBatchedOperationsEnabled()) 2521 | .append("\n\tDeleteOnIdleDurationInMinutes: ").append(serviceBusSubscription.deleteOnIdleDurationInMinutes()) 2522 | .append("\n\tScheduledMessageCount: ").append(serviceBusSubscription.scheduledMessageCount()) 2523 | .append("\n\tStatus: ").append(serviceBusSubscription.status()) 2524 | .append("\n\tTransferMessageCount: ").append(serviceBusSubscription.transferMessageCount()) 2525 | .append("\n\tIsDeadLetteringEnabledForExpiredMessages: ").append(serviceBusSubscription.isDeadLetteringEnabledForExpiredMessages()) 2526 | .append("\n\tIsSessionEnabled: ").append(serviceBusSubscription.isSessionEnabled()) 2527 | .append("\n\tLockDurationInSeconds: ").append(serviceBusSubscription.lockDurationInSeconds()) 2528 | .append("\n\tMaxDeliveryCountBeforeDeadLetteringMessage: ").append(serviceBusSubscription.maxDeliveryCountBeforeDeadLetteringMessage()) 2529 | .append("\n\tIsDeadLetteringEnabledForFilterEvaluationFailedMessages: ").append(serviceBusSubscription.isDeadLetteringEnabledForFilterEvaluationFailedMessages()) 2530 | .append("\n\tTransferMessageCount: ").append(serviceBusSubscription.transferMessageCount()) 2531 | .append("\n\tTransferDeadLetterMessageCount: ").append(serviceBusSubscription.transferDeadLetterMessageCount()); 2532 | 2533 | System.out.println(builder.toString()); 2534 | } 2535 | 2536 | /** 2537 | * Print topic Authorization Rule info. 2538 | * 2539 | * @param topicAuthorizationRule a topic Authorization Rule 2540 | */ 2541 | public static void print(TopicAuthorizationRule topicAuthorizationRule) { 2542 | StringBuilder builder = new StringBuilder() 2543 | .append("Service bus topic authorization rule: ").append(topicAuthorizationRule.id()) 2544 | .append("\n\tName: ").append(topicAuthorizationRule.name()) 2545 | .append("\n\tResourceGroupName: ").append(topicAuthorizationRule.resourceGroupName()) 2546 | .append("\n\tNamespace Name: ").append(topicAuthorizationRule.namespaceName()) 2547 | .append("\n\tTopic Name: ").append(topicAuthorizationRule.topicName()); 2548 | 2549 | List rights = topicAuthorizationRule.rights(); 2550 | builder.append("\n\tNumber of access rights in queue: ").append(rights.size()); 2551 | for (com.azure.resourcemanager.servicebus.models.AccessRights right : rights) { 2552 | builder.append("\n\t\tAccessRight: ") 2553 | .append("\n\t\t\tName :").append(right.name()); 2554 | } 2555 | 2556 | System.out.println(builder.toString()); 2557 | } 2558 | 2559 | /** 2560 | * Print CosmosDB info. 2561 | * 2562 | * @param cosmosDBAccount a CosmosDB 2563 | */ 2564 | public static void print(CosmosDBAccount cosmosDBAccount) { 2565 | StringBuilder builder = new StringBuilder() 2566 | .append("CosmosDB: ").append(cosmosDBAccount.id()) 2567 | .append("\n\tName: ").append(cosmosDBAccount.name()) 2568 | .append("\n\tResourceGroupName: ").append(cosmosDBAccount.resourceGroupName()) 2569 | .append("\n\tKind: ").append(cosmosDBAccount.kind().toString()) 2570 | .append("\n\tDefault consistency level: ").append(cosmosDBAccount.consistencyPolicy().defaultConsistencyLevel()) 2571 | .append("\n\tIP range filter: ").append(cosmosDBAccount.ipRangeFilter()); 2572 | 2573 | DatabaseAccountListKeysResult keys = cosmosDBAccount.listKeys(); 2574 | DatabaseAccountListReadOnlyKeysResult readOnlyKeys = cosmosDBAccount.listReadOnlyKeys(); 2575 | builder 2576 | .append("\n\tPrimary Master Key: ").append(keys.primaryMasterKey()) 2577 | .append("\n\tSecondary Master Key: ").append(keys.secondaryMasterKey()) 2578 | .append("\n\tPrimary Read-Only Key: ").append(readOnlyKeys.primaryReadonlyMasterKey()) 2579 | .append("\n\tSecondary Read-Only Key: ").append(readOnlyKeys.secondaryReadonlyMasterKey()); 2580 | 2581 | for (Location writeReplica : cosmosDBAccount.writableReplications()) { 2582 | builder.append("\n\t\tWrite replication: ") 2583 | .append("\n\t\t\tName :").append(writeReplica.locationName()); 2584 | } 2585 | 2586 | builder.append("\n\tNumber of read replications: ").append(cosmosDBAccount.readableReplications().size()); 2587 | for (Location readReplica : cosmosDBAccount.readableReplications()) { 2588 | builder.append("\n\t\tRead replication: ") 2589 | .append("\n\t\t\tName :").append(readReplica.locationName()); 2590 | } 2591 | 2592 | } 2593 | 2594 | /** 2595 | * Print Active Directory User info. 2596 | * 2597 | * @param user active directory user 2598 | */ 2599 | public static void print(ActiveDirectoryUser user) { 2600 | StringBuilder builder = new StringBuilder() 2601 | .append("Active Directory User: ").append(user.id()) 2602 | .append("\n\tName: ").append(user.name()) 2603 | .append("\n\tMail: ").append(user.mail()) 2604 | .append("\n\tMail Nickname: ").append(user.mailNickname()) 2605 | .append("\n\tUser Principal Name: ").append(user.userPrincipalName()); 2606 | 2607 | System.out.println(builder.toString()); 2608 | } 2609 | 2610 | /** 2611 | * Print Active Directory User info. 2612 | * 2613 | * @param role role definition 2614 | */ 2615 | public static void print(RoleDefinition role) { 2616 | StringBuilder builder = new StringBuilder() 2617 | .append("Role Definition: ").append(role.id()) 2618 | .append("\n\tName: ").append(role.name()) 2619 | .append("\n\tRole Name: ").append(role.roleName()) 2620 | .append("\n\tType: ").append(role.type()) 2621 | .append("\n\tDescription: ").append(role.description()) 2622 | .append("\n\tType: ").append(role.type()); 2623 | 2624 | Set permissions = role.permissions(); 2625 | builder.append("\n\tPermissions: ").append(permissions.size()); 2626 | for (Permission permission : permissions) { 2627 | builder.append("\n\t\tPermission Actions: " + permission.actions().size()); 2628 | for (String action : permission.actions()) { 2629 | builder.append("\n\t\t\tName :").append(action); 2630 | } 2631 | builder.append("\n\t\tPermission Not Actions: " + permission.notActions().size()); 2632 | for (String notAction : permission.notActions()) { 2633 | builder.append("\n\t\t\tName :").append(notAction); 2634 | } 2635 | } 2636 | 2637 | Set assignableScopes = role.assignableScopes(); 2638 | builder.append("\n\tAssignable scopes: ").append(assignableScopes.size()); 2639 | for (String scope : assignableScopes) { 2640 | builder.append("\n\t\tAssignable Scope: ") 2641 | .append("\n\t\t\tName :").append(scope); 2642 | } 2643 | 2644 | System.out.println(builder.toString()); 2645 | } 2646 | 2647 | /** 2648 | * Print Role Assignment info. 2649 | * 2650 | * @param roleAssignment role assignment 2651 | */ 2652 | public static void print(RoleAssignment roleAssignment) { 2653 | StringBuilder builder = new StringBuilder() 2654 | .append("Role Assignment: ") 2655 | .append("\n\tScope: ").append(roleAssignment.scope()) 2656 | .append("\n\tPrincipal Id: ").append(roleAssignment.principalId()) 2657 | .append("\n\tRole Definition Id: ").append(roleAssignment.roleDefinitionId()); 2658 | 2659 | System.out.println(builder.toString()); 2660 | } 2661 | 2662 | /** 2663 | * Print Active Directory Group info. 2664 | * 2665 | * @param group active directory group 2666 | */ 2667 | public static void print(ActiveDirectoryGroup group) { 2668 | StringBuilder builder = new StringBuilder() 2669 | .append("Active Directory Group: ").append(group.id()) 2670 | .append("\n\tName: ").append(group.name()) 2671 | .append("\n\tMail: ").append(group.mail()) 2672 | .append("\n\tSecurity Enabled: ").append(group.securityEnabled()) 2673 | .append("\n\tGroup members:"); 2674 | 2675 | for (ActiveDirectoryObject object : group.listMembers()) { 2676 | builder.append("\n\t\tType: ").append(object.getClass().getSimpleName()) 2677 | .append("\tName: ").append(object.name()); 2678 | } 2679 | 2680 | System.out.println(builder.toString()); 2681 | } 2682 | 2683 | /** 2684 | * Print Active Directory Application info. 2685 | * 2686 | * @param application active directory application 2687 | */ 2688 | public static void print(ActiveDirectoryApplication application) { 2689 | StringBuilder builder = new StringBuilder() 2690 | .append("Active Directory Application: ").append(application.id()) 2691 | .append("\n\tName: ").append(application.name()) 2692 | .append("\n\tSign on URL: ").append(application.signOnUrl()) 2693 | .append("\n\tReply URLs:"); 2694 | for (String replyUrl : application.replyUrls()) { 2695 | builder.append("\n\t\t").append(replyUrl); 2696 | } 2697 | 2698 | System.out.println(builder.toString()); 2699 | } 2700 | 2701 | /** 2702 | * Print Service Principal info. 2703 | * 2704 | * @param servicePrincipal service principal 2705 | */ 2706 | public static void print(ServicePrincipal servicePrincipal) { 2707 | StringBuilder builder = new StringBuilder() 2708 | .append("Service Principal: ").append(servicePrincipal.id()) 2709 | .append("\n\tName: ").append(servicePrincipal.name()) 2710 | .append("\n\tApplication Id: ").append(servicePrincipal.applicationId()); 2711 | 2712 | List names = servicePrincipal.servicePrincipalNames(); 2713 | builder.append("\n\tNames: ").append(names.size()); 2714 | for (String name : names) { 2715 | builder.append("\n\t\tName: ").append(name); 2716 | } 2717 | System.out.println(builder.toString()); 2718 | } 2719 | 2720 | /** 2721 | * Print Network Watcher info. 2722 | * 2723 | * @param nw network watcher 2724 | */ 2725 | public static void print(NetworkWatcher nw) { 2726 | StringBuilder builder = new StringBuilder() 2727 | .append("Network Watcher: ").append(nw.id()) 2728 | .append("\n\tName: ").append(nw.name()) 2729 | .append("\n\tResource group name: ").append(nw.resourceGroupName()) 2730 | .append("\n\tRegion name: ").append(nw.regionName()); 2731 | System.out.println(builder.toString()); 2732 | } 2733 | 2734 | /** 2735 | * Print packet capture info. 2736 | * 2737 | * @param resource packet capture 2738 | */ 2739 | public static void print(PacketCapture resource) { 2740 | StringBuilder sb = new StringBuilder().append("Packet Capture: ").append(resource.id()) 2741 | .append("\n\tName: ").append(resource.name()) 2742 | .append("\n\tTarget id: ").append(resource.targetId()) 2743 | .append("\n\tTime limit in seconds: ").append(resource.timeLimitInSeconds()) 2744 | .append("\n\tBytes to capture per packet: ").append(resource.bytesToCapturePerPacket()) 2745 | .append("\n\tProvisioning state: ").append(resource.provisioningState()) 2746 | .append("\n\tStorage location:") 2747 | .append("\n\tStorage account id: ").append(resource.storageLocation().storageId()) 2748 | .append("\n\tStorage account path: ").append(resource.storageLocation().storagePath()) 2749 | .append("\n\tFile path: ").append(resource.storageLocation().filePath()) 2750 | .append("\n\t Packet capture filters: ").append(resource.filters().size()); 2751 | for (PacketCaptureFilter filter : resource.filters()) { 2752 | sb.append("\n\t\tProtocol: ").append(filter.protocol()); 2753 | sb.append("\n\t\tLocal IP address: ").append(filter.localIpAddress()); 2754 | sb.append("\n\t\tRemote IP address: ").append(filter.remoteIpAddress()); 2755 | sb.append("\n\t\tLocal port: ").append(filter.localPort()); 2756 | sb.append("\n\t\tRemote port: ").append(filter.remotePort()); 2757 | } 2758 | System.out.println(sb.toString()); 2759 | } 2760 | 2761 | /** 2762 | * Print verification IP flow info. 2763 | * 2764 | * @param resource IP flow verification info 2765 | */ 2766 | public static void print(VerificationIPFlow resource) { 2767 | System.out.println(new StringBuilder("IP flow verification: ") 2768 | .append("\n\tAccess: ").append(resource.access()) 2769 | .append("\n\tRule name: ").append(resource.ruleName()) 2770 | .toString()); 2771 | } 2772 | 2773 | /** 2774 | * Print topology info. 2775 | * 2776 | * @param resource topology 2777 | */ 2778 | public static void print(Topology resource) { 2779 | StringBuilder sb = new StringBuilder().append("Topology: ").append(resource.id()) 2780 | .append("\n\tTopology parameters: ") 2781 | .append("\n\t\tResource group: ").append(resource.topologyParameters().targetResourceGroupName()) 2782 | .append("\n\t\tVirtual network: ").append(resource.topologyParameters().targetVirtualNetwork() == null ? "" : resource.topologyParameters().targetVirtualNetwork().id()) 2783 | .append("\n\t\tSubnet id: ").append(resource.topologyParameters().targetSubnet() == null ? "" : resource.topologyParameters().targetSubnet().id()) 2784 | .append("\n\tCreated time: ").append(resource.createdTime()) 2785 | .append("\n\tLast modified time: ").append(resource.lastModifiedTime()); 2786 | for (TopologyResource tr : resource.resources().values()) { 2787 | sb.append("\n\tTopology resource: ").append(tr.id()) 2788 | .append("\n\t\tName: ").append(tr.name()) 2789 | .append("\n\t\tLocation: ").append(tr.location()) 2790 | .append("\n\t\tAssociations:"); 2791 | for (TopologyAssociation association : tr.associations()) { 2792 | sb.append("\n\t\t\tName:").append(association.name()) 2793 | .append("\n\t\t\tResource id:").append(association.resourceId()) 2794 | .append("\n\t\t\tAssociation type:").append(association.associationType()); 2795 | } 2796 | } 2797 | System.out.println(sb.toString()); 2798 | } 2799 | 2800 | /** 2801 | * Print flow log settings info. 2802 | * 2803 | * @param resource flow log settings 2804 | */ 2805 | public static void print(FlowLogSettings resource) { 2806 | System.out.println(new StringBuilder().append("Flow log settings: ") 2807 | .append("Target resource id: ").append(resource.targetResourceId()) 2808 | .append("\n\tFlow log enabled: ").append(resource.enabled()) 2809 | .append("\n\tStorage account id: ").append(resource.storageId()) 2810 | .append("\n\tRetention policy enabled: ").append(resource.isRetentionEnabled()) 2811 | .append("\n\tRetention policy days: ").append(resource.retentionDays()) 2812 | .toString()); 2813 | } 2814 | 2815 | /** 2816 | * Print availability set info. 2817 | * 2818 | * @param resource an availability set 2819 | */ 2820 | public static void print(SecurityGroupView resource) { 2821 | StringBuilder sb = new StringBuilder().append("Security group view: ") 2822 | .append("\n\tVirtual machine id: ").append(resource.vmId()); 2823 | for (SecurityGroupNetworkInterface sgni : resource.networkInterfaces().values()) { 2824 | sb.append("\n\tSecurity group network interface:").append(sgni.id()) 2825 | .append("\n\t\tSecurity group network interface:") 2826 | .append("\n\t\tEffective security rules:"); 2827 | for (EffectiveNetworkSecurityRule rule : sgni.securityRuleAssociations().effectiveSecurityRules()) { 2828 | sb.append("\n\t\t\tName: ").append(rule.name()) 2829 | .append("\n\t\t\tDirection: ").append(rule.direction()) 2830 | .append("\n\t\t\tAccess: ").append(rule.access()) 2831 | .append("\n\t\t\tPriority: ").append(rule.priority()) 2832 | .append("\n\t\t\tSource address prefix: ").append(rule.sourceAddressPrefix()) 2833 | .append("\n\t\t\tSource port range: ").append(rule.sourcePortRange()) 2834 | .append("\n\t\t\tDestination address prefix: ").append(rule.destinationAddressPrefix()) 2835 | .append("\n\t\t\tDestination port range: ").append(rule.destinationPortRange()) 2836 | .append("\n\t\t\tProtocol: ").append(rule.protocol()); 2837 | } 2838 | sb.append("\n\t\tSubnet:").append(sgni.securityRuleAssociations().subnetAssociation().id()); 2839 | printSecurityRule(sb, sgni.securityRuleAssociations().subnetAssociation().securityRules()); 2840 | if (sgni.securityRuleAssociations().networkInterfaceAssociation() != null) { 2841 | sb.append("\n\t\tNetwork interface:").append(sgni.securityRuleAssociations().networkInterfaceAssociation().id()); 2842 | printSecurityRule(sb, sgni.securityRuleAssociations().networkInterfaceAssociation().securityRules()); 2843 | } 2844 | sb.append("\n\t\tDefault security rules:"); 2845 | printSecurityRule(sb, sgni.securityRuleAssociations().defaultSecurityRules()); 2846 | } 2847 | System.out.println(sb.toString()); 2848 | } 2849 | 2850 | private static void printSecurityRule(StringBuilder sb, List rules) { 2851 | for (SecurityRuleInner rule : rules) { 2852 | sb.append("\n\t\t\tName: ").append(rule.name()) 2853 | .append("\n\t\t\tDirection: ").append(rule.direction()) 2854 | .append("\n\t\t\tAccess: ").append(rule.access()) 2855 | .append("\n\t\t\tPriority: ").append(rule.priority()) 2856 | .append("\n\t\t\tSource address prefix: ").append(rule.sourceAddressPrefix()) 2857 | .append("\n\t\t\tSource port range: ").append(rule.sourcePortRange()) 2858 | .append("\n\t\t\tDestination address prefix: ").append(rule.destinationAddressPrefix()) 2859 | .append("\n\t\t\tDestination port range: ").append(rule.destinationPortRange()) 2860 | .append("\n\t\t\tProtocol: ").append(rule.protocol()) 2861 | .append("\n\t\t\tDescription: ").append(rule.description()) 2862 | .append("\n\t\t\tProvisioning state: ").append(rule.provisioningState()); 2863 | } 2864 | } 2865 | 2866 | /** 2867 | * Print next hop info. 2868 | * 2869 | * @param resource an availability set 2870 | */ 2871 | public static void print(NextHop resource) { 2872 | System.out.println(new StringBuilder("Next hop: ") 2873 | .append("Next hop type: ").append(resource.nextHopType()) 2874 | .append("\n\tNext hop ip address: ").append(resource.nextHopIpAddress()) 2875 | .append("\n\tRoute table id: ").append(resource.routeTableId()) 2876 | .toString()); 2877 | } 2878 | 2879 | /** 2880 | * Print container group info. 2881 | * 2882 | * @param resource a container group 2883 | */ 2884 | public static void print(ContainerGroup resource) { 2885 | StringBuilder info = new StringBuilder().append("Container Group: ").append(resource.id()) 2886 | .append("Name: ").append(resource.name()) 2887 | .append("\n\tResource group: ").append(resource.resourceGroupName()) 2888 | .append("\n\tRegion: ").append(resource.region()) 2889 | .append("\n\tTags: ").append(resource.tags()) 2890 | .append("\n\tOS type: ").append(resource.osType()); 2891 | 2892 | if (resource.ipAddress() != null) { 2893 | info.append("\n\tPublic IP address: ").append(resource.ipAddress()); 2894 | } 2895 | if (resource.externalTcpPorts() != null) { 2896 | info.append("\n\tExternal TCP ports:"); 2897 | for (int port : resource.externalTcpPorts()) { 2898 | info.append(" ").append(port); 2899 | } 2900 | } 2901 | if (resource.externalUdpPorts() != null) { 2902 | info.append("\n\tExternal UDP ports:"); 2903 | for (int port : resource.externalUdpPorts()) { 2904 | info.append(" ").append(port); 2905 | } 2906 | } 2907 | if (resource.imageRegistryServers() != null) { 2908 | info.append("\n\tPrivate Docker image registries:"); 2909 | for (String server : resource.imageRegistryServers()) { 2910 | info.append(" ").append(server); 2911 | } 2912 | } 2913 | if (resource.volumes() != null) { 2914 | info.append("\n\tVolume mapping: "); 2915 | for (Map.Entry entry : resource.volumes().entrySet()) { 2916 | info.append("\n\t\tName: ").append(entry.getKey()).append(" -> ") 2917 | .append(entry.getValue().azureFile() != null ? entry.getValue().azureFile().shareName() : "empty direcory volume"); 2918 | } 2919 | } 2920 | if (resource.containers() != null) { 2921 | info.append("\n\tContainer instances: "); 2922 | for (Map.Entry entry : resource.containers().entrySet()) { 2923 | Container container = entry.getValue(); 2924 | info.append("\n\t\tName: ").append(entry.getKey()).append(" -> ").append(container.image()); 2925 | info.append("\n\t\t\tResources: "); 2926 | info.append(container.resources().requests().cpu()).append("CPUs "); 2927 | info.append(container.resources().requests().memoryInGB()).append("GB"); 2928 | info.append("\n\t\t\tPorts:"); 2929 | for (ContainerPort port : container.ports()) { 2930 | info.append(" ").append(port.port()); 2931 | } 2932 | if (container.volumeMounts() != null) { 2933 | info.append("\n\t\t\tVolume mounts:"); 2934 | for (VolumeMount volumeMount : container.volumeMounts()) { 2935 | info.append(" ").append(volumeMount.name()).append("->").append(volumeMount.mountPath()); 2936 | } 2937 | } 2938 | if (container.command() != null) { 2939 | info.append("\n\t\t\tStart commands:"); 2940 | for (String command : container.command()) { 2941 | info.append("\n\t\t\t\t").append(command); 2942 | } 2943 | } 2944 | if (container.environmentVariables() != null) { 2945 | info.append("\n\t\t\tENV vars:"); 2946 | for (EnvironmentVariable envVar : container.environmentVariables()) { 2947 | info.append("\n\t\t\t\t").append(envVar.name()).append("=").append(envVar.value()); 2948 | } 2949 | } 2950 | } 2951 | } 2952 | 2953 | System.out.println(info.toString()); 2954 | } 2955 | 2956 | /** 2957 | * Print event hub namespace. 2958 | * 2959 | * @param resource a virtual machine 2960 | */ 2961 | public static void print(EventHubNamespace resource) { 2962 | StringBuilder info = new StringBuilder(); 2963 | info.append("Eventhub Namespace: ").append(resource.id()) 2964 | .append("\n\tName: ").append(resource.name()) 2965 | .append("\n\tRegion: ").append(resource.region()) 2966 | .append("\n\tTags: ").append(resource.tags()) 2967 | .append("\n\tAzureInsightMetricId: ").append(resource.azureInsightMetricId()) 2968 | .append("\n\tIsAutoScale enabled: ").append(resource.isAutoScaleEnabled()) 2969 | .append("\n\tServiceBus endpoint: ").append(resource.serviceBusEndpoint()) 2970 | .append("\n\tThroughPut upper limit: ").append(resource.throughputUnitsUpperLimit()) 2971 | .append("\n\tCurrent ThroughPut: ").append(resource.currentThroughputUnits()) 2972 | .append("\n\tCreated time: ").append(resource.createdAt()) 2973 | .append("\n\tUpdated time: ").append(resource.updatedAt()); 2974 | 2975 | System.out.println(info.toString()); 2976 | } 2977 | 2978 | /** 2979 | * Print event hub. 2980 | * 2981 | * @param resource event hub 2982 | */ 2983 | public static void print(EventHub resource) { 2984 | StringBuilder info = new StringBuilder(); 2985 | info.append("Eventhub: ").append(resource.id()) 2986 | .append("\n\tName: ").append(resource.name()) 2987 | .append("\n\tNamespace resource group: ").append(resource.namespaceResourceGroupName()) 2988 | .append("\n\tNamespace: ").append(resource.namespaceName()) 2989 | .append("\n\tIs data capture enabled: ").append(resource.isDataCaptureEnabled()) 2990 | .append("\n\tPartition ids: ").append(resource.partitionIds()); 2991 | if (resource.isDataCaptureEnabled()) { 2992 | info.append("\n\t\t\tData capture window size in MB: ").append(resource.dataCaptureWindowSizeInMB()); 2993 | info.append("\n\t\t\tData capture window size in seconds: ").append(resource.dataCaptureWindowSizeInSeconds()); 2994 | if (resource.captureDestination() != null) { 2995 | info.append("\n\t\t\tData capture storage account: ").append(resource.captureDestination().storageAccountResourceId()); 2996 | info.append("\n\t\t\tData capture storage container: ").append(resource.captureDestination().blobContainer()); 2997 | } 2998 | } 2999 | System.out.println(info.toString()); 3000 | } 3001 | 3002 | /** 3003 | * Print event hub namespace recovery pairing. 3004 | * 3005 | * @param resource event hub namespace disaster recovery pairing 3006 | */ 3007 | public static void print(EventHubDisasterRecoveryPairing resource) { 3008 | StringBuilder info = new StringBuilder(); 3009 | info.append("DisasterRecoveryPairing: ").append(resource.id()) 3010 | .append("\n\tName: ").append(resource.name()) 3011 | .append("\n\tPrimary namespace resource group name: ").append(resource.primaryNamespaceResourceGroupName()) 3012 | .append("\n\tPrimary namespace name: ").append(resource.primaryNamespaceName()) 3013 | .append("\n\tSecondary namespace: ").append(resource.secondaryNamespaceId()) 3014 | .append("\n\tNamespace role: ").append(resource.namespaceRole()); 3015 | System.out.println(info.toString()); 3016 | } 3017 | 3018 | /** 3019 | * Print event hub namespace recovery pairing auth rules. 3020 | * 3021 | * @param resource event hub namespace disaster recovery pairing auth rule 3022 | */ 3023 | public static void print(DisasterRecoveryPairingAuthorizationRule resource) { 3024 | StringBuilder info = new StringBuilder(); 3025 | info.append("DisasterRecoveryPairing auth rule: ").append(resource.name()); 3026 | List rightsStr = new ArrayList<>(); 3027 | for (AccessRights rights : resource.rights()) { 3028 | rightsStr.add(rights.toString()); 3029 | } 3030 | info.append("\n\tRights: ").append(rightsStr); 3031 | System.out.println(info.toString()); 3032 | } 3033 | 3034 | /** 3035 | * Print event hub namespace recovery pairing auth rule key. 3036 | * 3037 | * @param resource event hub namespace disaster recovery pairing auth rule key 3038 | */ 3039 | public static void print(DisasterRecoveryPairingAuthorizationKey resource) { 3040 | StringBuilder info = new StringBuilder(); 3041 | info.append("DisasterRecoveryPairing auth key: ") 3042 | .append("\n\t Alias primary connection string: ").append(resource.aliasPrimaryConnectionString()) 3043 | .append("\n\t Alias secondary connection string: ").append(resource.aliasSecondaryConnectionString()) 3044 | .append("\n\t Primary key: ").append(resource.primaryKey()) 3045 | .append("\n\t Secondary key: ").append(resource.secondaryKey()) 3046 | .append("\n\t Primary connection string: ").append(resource.primaryConnectionString()) 3047 | .append("\n\t Secondary connection string: ").append(resource.secondaryConnectionString()); 3048 | System.out.println(info.toString()); 3049 | } 3050 | 3051 | /** 3052 | * Print event hub consumer group. 3053 | * 3054 | * @param resource event hub consumer group 3055 | */ 3056 | public static void print(EventHubConsumerGroup resource) { 3057 | StringBuilder info = new StringBuilder(); 3058 | info.append("Event hub consumer group: ").append(resource.id()) 3059 | .append("\n\tName: ").append(resource.name()) 3060 | .append("\n\tNamespace resource group: ").append(resource.namespaceResourceGroupName()) 3061 | .append("\n\tNamespace: ").append(resource.namespaceName()) 3062 | .append("\n\tEvent hub name: ").append(resource.eventHubName()) 3063 | .append("\n\tUser metadata: ").append(resource.userMetadata()); 3064 | System.out.println(info.toString()); 3065 | } 3066 | 3067 | 3068 | /** 3069 | * Print Diagnostic Setting. 3070 | * 3071 | * @param resource Diagnostic Setting instance 3072 | */ 3073 | public static void print(DiagnosticSetting resource) { 3074 | StringBuilder info = new StringBuilder("Diagnostic Setting: ") 3075 | .append("\n\tId: ").append(resource.id()) 3076 | .append("\n\tAssociated resource Id: ").append(resource.resourceId()) 3077 | .append("\n\tName: ").append(resource.name()) 3078 | .append("\n\tStorage Account Id: ").append(resource.storageAccountId()) 3079 | .append("\n\tEventHub Namespace Autorization Rule Id: ").append(resource.eventHubAuthorizationRuleId()) 3080 | .append("\n\tEventHub name: ").append(resource.eventHubName()) 3081 | .append("\n\tLog Analytics workspace Id: ").append(resource.workspaceId()); 3082 | if (resource.logs() != null && !resource.logs().isEmpty()) { 3083 | info.append("\n\tLog Settings: "); 3084 | for (LogSettings ls : resource.logs()) { 3085 | info.append("\n\t\tCategory: ").append(ls.category()); 3086 | info.append("\n\t\tRetention policy: "); 3087 | if (ls.retentionPolicy() != null) { 3088 | info.append(ls.retentionPolicy().days() + " days"); 3089 | } else { 3090 | info.append("NONE"); 3091 | } 3092 | } 3093 | } 3094 | if (resource.metrics() != null && !resource.metrics().isEmpty()) { 3095 | info.append("\n\tMetric Settings: "); 3096 | for (MetricSettings ls : resource.metrics()) { 3097 | info.append("\n\t\tCategory: ").append(ls.category()); 3098 | info.append("\n\t\tTimegrain: ").append(ls.timeGrain()); 3099 | info.append("\n\t\tRetention policy: "); 3100 | if (ls.retentionPolicy() != null) { 3101 | info.append(ls.retentionPolicy().days() + " days"); 3102 | } else { 3103 | info.append("NONE"); 3104 | } 3105 | } 3106 | } 3107 | System.out.println(info.toString()); 3108 | } 3109 | 3110 | /** 3111 | * Print Action group settings. 3112 | * 3113 | * @param actionGroup action group instance 3114 | */ 3115 | public static void print(ActionGroup actionGroup) { 3116 | StringBuilder info = new StringBuilder("Action Group: ") 3117 | .append("\n\tId: ").append(actionGroup.id()) 3118 | .append("\n\tName: ").append(actionGroup.name()) 3119 | .append("\n\tShort Name: ").append(actionGroup.shortName()); 3120 | 3121 | if (actionGroup.emailReceivers() != null && !actionGroup.emailReceivers().isEmpty()) { 3122 | info.append("\n\tEmail receivers: "); 3123 | for (EmailReceiver er : actionGroup.emailReceivers()) { 3124 | info.append("\n\t\tName: ").append(er.name()); 3125 | info.append("\n\t\tEMail: ").append(er.emailAddress()); 3126 | info.append("\n\t\tStatus: ").append(er.status()); 3127 | info.append("\n\t\t==="); 3128 | } 3129 | } 3130 | 3131 | if (actionGroup.smsReceivers() != null && !actionGroup.smsReceivers().isEmpty()) { 3132 | info.append("\n\tSMS text message receivers: "); 3133 | for (SmsReceiver er : actionGroup.smsReceivers()) { 3134 | info.append("\n\t\tName: ").append(er.name()); 3135 | info.append("\n\t\tPhone: ").append(er.countryCode() + er.phoneNumber()); 3136 | info.append("\n\t\tStatus: ").append(er.status()); 3137 | info.append("\n\t\t==="); 3138 | } 3139 | } 3140 | 3141 | if (actionGroup.webhookReceivers() != null && !actionGroup.webhookReceivers().isEmpty()) { 3142 | info.append("\n\tWebhook receivers: "); 3143 | for (WebhookReceiver er : actionGroup.webhookReceivers()) { 3144 | info.append("\n\t\tName: ").append(er.name()); 3145 | info.append("\n\t\tURI: ").append(er.serviceUri()); 3146 | info.append("\n\t\t==="); 3147 | } 3148 | } 3149 | 3150 | if (actionGroup.pushNotificationReceivers() != null && !actionGroup.pushNotificationReceivers().isEmpty()) { 3151 | info.append("\n\tApp Push Notification receivers: "); 3152 | for (AzureAppPushReceiver er : actionGroup.pushNotificationReceivers()) { 3153 | info.append("\n\t\tName: ").append(er.name()); 3154 | info.append("\n\t\tEmail: ").append(er.emailAddress()); 3155 | info.append("\n\t\t==="); 3156 | } 3157 | } 3158 | 3159 | if (actionGroup.voiceReceivers() != null && !actionGroup.voiceReceivers().isEmpty()) { 3160 | info.append("\n\tVoice Message receivers: "); 3161 | for (VoiceReceiver er : actionGroup.voiceReceivers()) { 3162 | info.append("\n\t\tName: ").append(er.name()); 3163 | info.append("\n\t\tPhone: ").append(er.countryCode() + er.phoneNumber()); 3164 | info.append("\n\t\t==="); 3165 | } 3166 | } 3167 | 3168 | if (actionGroup.automationRunbookReceivers() != null && !actionGroup.automationRunbookReceivers().isEmpty()) { 3169 | info.append("\n\tAutomation Runbook receivers: "); 3170 | for (AutomationRunbookReceiver er : actionGroup.automationRunbookReceivers()) { 3171 | info.append("\n\t\tName: ").append(er.name()); 3172 | info.append("\n\t\tRunbook Name: ").append(er.runbookName()); 3173 | info.append("\n\t\tAccount Id: ").append(er.automationAccountId()); 3174 | info.append("\n\t\tIs Global: ").append(er.isGlobalRunbook()); 3175 | info.append("\n\t\tService URI: ").append(er.serviceUri()); 3176 | info.append("\n\t\tWebhook resource Id: ").append(er.webhookResourceId()); 3177 | info.append("\n\t\t==="); 3178 | } 3179 | } 3180 | 3181 | if (actionGroup.azureFunctionReceivers() != null && !actionGroup.azureFunctionReceivers().isEmpty()) { 3182 | info.append("\n\tAzure Functions receivers: "); 3183 | for (AzureFunctionReceiver er : actionGroup.azureFunctionReceivers()) { 3184 | info.append("\n\t\tName: ").append(er.name()); 3185 | info.append("\n\t\tFunction Name: ").append(er.functionName()); 3186 | info.append("\n\t\tFunction App Resource Id: ").append(er.functionAppResourceId()); 3187 | info.append("\n\t\tFunction Trigger URI: ").append(er.httpTriggerUrl()); 3188 | info.append("\n\t\t==="); 3189 | } 3190 | } 3191 | 3192 | if (actionGroup.logicAppReceivers() != null && !actionGroup.logicAppReceivers().isEmpty()) { 3193 | info.append("\n\tLogic App receivers: "); 3194 | for (LogicAppReceiver er : actionGroup.logicAppReceivers()) { 3195 | info.append("\n\t\tName: ").append(er.name()); 3196 | info.append("\n\t\tResource Id: ").append(er.resourceId()); 3197 | info.append("\n\t\tCallback URL: ").append(er.callbackUrl()); 3198 | info.append("\n\t\t==="); 3199 | } 3200 | } 3201 | 3202 | if (actionGroup.itsmReceivers() != null && !actionGroup.itsmReceivers().isEmpty()) { 3203 | info.append("\n\tITSM receivers: "); 3204 | for (ItsmReceiver er : actionGroup.itsmReceivers()) { 3205 | info.append("\n\t\tName: ").append(er.name()); 3206 | info.append("\n\t\tWorkspace Id: ").append(er.workspaceId()); 3207 | info.append("\n\t\tConnection Id: ").append(er.connectionId()); 3208 | info.append("\n\t\tRegion: ").append(er.region()); 3209 | info.append("\n\t\tTicket Configuration: ").append(er.ticketConfiguration()); 3210 | info.append("\n\t\t==="); 3211 | } 3212 | } 3213 | System.out.println(info.toString()); 3214 | } 3215 | 3216 | /** 3217 | * Print activity log alert settings. 3218 | * 3219 | * @param activityLogAlert activity log instance 3220 | */ 3221 | public static void print(ActivityLogAlert activityLogAlert) { 3222 | 3223 | StringBuilder info = new StringBuilder("Activity Log Alert: ") 3224 | .append("\n\tId: ").append(activityLogAlert.id()) 3225 | .append("\n\tName: ").append(activityLogAlert.name()) 3226 | .append("\n\tDescription: ").append(activityLogAlert.description()) 3227 | .append("\n\tIs Enabled: ").append(activityLogAlert.enabled()); 3228 | 3229 | if (activityLogAlert.scopes() != null && !activityLogAlert.scopes().isEmpty()) { 3230 | info.append("\n\tScopes: "); 3231 | for (String er : activityLogAlert.scopes()) { 3232 | info.append("\n\t\tId: ").append(er); 3233 | } 3234 | } 3235 | 3236 | if (activityLogAlert.actionGroupIds() != null && !activityLogAlert.actionGroupIds().isEmpty()) { 3237 | info.append("\n\tAction Groups: "); 3238 | for (String er : activityLogAlert.actionGroupIds()) { 3239 | info.append("\n\t\tAction Group Id: ").append(er); 3240 | } 3241 | } 3242 | 3243 | if (activityLogAlert.equalsConditions() != null && !activityLogAlert.equalsConditions().isEmpty()) { 3244 | info.append("\n\tAlert conditions (when all of is true): "); 3245 | for (Map.Entry er : activityLogAlert.equalsConditions().entrySet()) { 3246 | info.append("\n\t\t'").append(er.getKey()).append("' equals '").append(er.getValue()).append("'"); 3247 | } 3248 | } 3249 | System.out.println(info.toString()); 3250 | } 3251 | 3252 | /** 3253 | * Print metric alert settings. 3254 | * 3255 | * @param metricAlert metric alert instance 3256 | */ 3257 | public static void print(MetricAlert metricAlert) { 3258 | 3259 | StringBuilder info = new StringBuilder("Metric Alert: ") 3260 | .append("\n\tId: ").append(metricAlert.id()) 3261 | .append("\n\tName: ").append(metricAlert.name()) 3262 | .append("\n\tDescription: ").append(metricAlert.description()) 3263 | .append("\n\tIs Enabled: ").append(metricAlert.enabled()) 3264 | .append("\n\tIs Auto Mitigated: ").append(metricAlert.autoMitigate()) 3265 | .append("\n\tSeverity: ").append(metricAlert.severity()) 3266 | .append("\n\tWindow Size: ").append(metricAlert.windowSize()) 3267 | .append("\n\tEvaluation Frequency: ").append(metricAlert.evaluationFrequency()); 3268 | 3269 | if (metricAlert.scopes() != null && !metricAlert.scopes().isEmpty()) { 3270 | info.append("\n\tScopes: "); 3271 | for (String er : metricAlert.scopes()) { 3272 | info.append("\n\t\tId: ").append(er); 3273 | } 3274 | } 3275 | 3276 | if (metricAlert.actionGroupIds() != null && !metricAlert.actionGroupIds().isEmpty()) { 3277 | info.append("\n\tAction Groups: "); 3278 | for (String er : metricAlert.actionGroupIds()) { 3279 | info.append("\n\t\tAction Group Id: ").append(er); 3280 | } 3281 | } 3282 | 3283 | if (metricAlert.alertCriterias() != null && !metricAlert.alertCriterias().isEmpty()) { 3284 | info.append("\n\tAlert conditions (when all of is true): "); 3285 | for (Map.Entry 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 | --------------------------------------------------------------------------------