1616import com .azure .core .http .rest .PagedIterable ;
1717import com .azure .core .http .rest .Response ;
1818import com .azure .core .http .rest .SimpleResponse ;
19+ import com .azure .core .management .Region ;
1920import com .azure .core .management .exception .ManagementException ;
2021import com .azure .core .util .logging .ClientLogger ;
2122import com .azure .core .util .serializer .JacksonAdapter ;
7172import com .azure .resourcemanager .dns .models .AaaaRecordSet ;
7273import com .azure .resourcemanager .dns .models .CnameRecordSet ;
7374import com .azure .resourcemanager .dns .models .DnsZone ;
74- import com .azure .resourcemanager .dns .models .MxRecordSet ;
7575import com .azure .resourcemanager .dns .models .MxRecord ;
76+ import com .azure .resourcemanager .dns .models .MxRecordSet ;
7677import com .azure .resourcemanager .dns .models .NsRecordSet ;
7778import com .azure .resourcemanager .dns .models .PtrRecordSet ;
7879import com .azure .resourcemanager .dns .models .SoaRecord ;
163164import com .azure .resourcemanager .redis .models .RedisCache ;
164165import com .azure .resourcemanager .redis .models .RedisCachePremium ;
165166import com .azure .resourcemanager .redis .models .ScheduleEntry ;
166- import com .azure .core .management .Region ;
167167import com .azure .resourcemanager .resources .fluentcore .arm .models .PrivateLinkResource ;
168168import com .azure .resourcemanager .resources .fluentcore .utils .ResourceManagerUtils ;
169169import com .azure .resourcemanager .resources .models .ManagementLock ;
201201import com .azure .resourcemanager .trafficmanager .models .TrafficManagerExternalEndpoint ;
202202import com .azure .resourcemanager .trafficmanager .models .TrafficManagerNestedProfileEndpoint ;
203203import com .azure .resourcemanager .trafficmanager .models .TrafficManagerProfile ;
204- import com .jcraft .jsch .JSchException ;
205204import org .apache .commons .net .ftp .FTP ;
206205import org .apache .commons .net .ftp .FTPClient ;
207206import reactor .core .publisher .Mono ;
215214import java .io .IOException ;
216215import java .io .InputStream ;
217216import java .io .InputStreamReader ;
218- import java .io .UnsupportedEncodingException ;
219217import java .nio .charset .StandardCharsets ;
220218import java .nio .file .Files ;
221219import java .security .KeyPair ;
241239/**
242240 * Common utils for Azure management samples.
243241 */
244-
245242public final class Utils {
246243
244+ // IMPORTANT: do not use SSHShell in Utils
245+
247246 private static final ClientLogger LOGGER = new ClientLogger (Utils .class );
248247
249248 private static String sshPublicKey ;
@@ -396,6 +395,12 @@ public static void print(VirtualMachine resource) {
396395 storageProfile .append ("\n \t \t \t Caching: " ).append (resource .storageProfile ().osDisk ().caching ());
397396 storageProfile .append ("\n \t \t \t CreateOption: " ).append (resource .storageProfile ().osDisk ().createOption ());
398397 storageProfile .append ("\n \t \t \t DiskSizeGB: " ).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 \t DiskEncryptionSet Id: " )
401+ .append (resource .storageProfile ().osDisk ().managedDisk ().diskEncryptionSet ().id ());
402+ }
403+ }
399404 if (resource .storageProfile ().osDisk ().image () != null ) {
400405 storageProfile .append ("\n \t \t \t Image Uri: " ).append (resource .storageProfile ().osDisk ().image ().uri ());
401406 }
@@ -430,6 +435,9 @@ public static void print(VirtualMachine resource) {
430435 if (resource .isManagedDiskEnabled ()) {
431436 if (disk .managedDisk () != null ) {
432437 storageProfile .append ("\n \t \t \t Managed Disk Id: " ).append (disk .managedDisk ().id ());
438+ if (disk .managedDisk ().diskEncryptionSet () != null ) {
439+ storageProfile .append ("\n \t \t \t DiskEncryptionSet Id: " ).append (disk .managedDisk ().diskEncryptionSet ().id ());
440+ }
433441 }
434442 } else {
435443 if (disk .vhd ().uri () != null ) {
@@ -1626,7 +1634,7 @@ public static void print(SearchService searchService) {
16261634 *
16271635 * @param envSecondaryServicePrincipal an Azure Container Registry
16281636 * @return a service principal client ID
1629- * @throws Exception exception
1637+ * @throws IOException exception
16301638 */
16311639 public static String getSecondaryServicePrincipalClientID (String envSecondaryServicePrincipal ) throws IOException {
16321640 String content = new String (Files .readAllBytes (new File (envSecondaryServicePrincipal ).toPath ()), StandardCharsets .UTF_8 ).trim ();
@@ -1649,7 +1657,7 @@ public static String getSecondaryServicePrincipalClientID(String envSecondarySer
16491657 *
16501658 * @param envSecondaryServicePrincipal an Azure Container Registry
16511659 * @return a service principal secret
1652- * @throws Exception exception
1660+ * @throws IOException exception
16531661 */
16541662 public static String getSecondaryServicePrincipalSecret (String envSecondaryServicePrincipal ) throws IOException {
16551663 String content = new String (Files .readAllBytes (new File (envSecondaryServicePrincipal ).toPath ()), StandardCharsets .UTF_8 ).trim ();
@@ -1686,7 +1694,6 @@ public static String getSecondaryServicePrincipalSecret(String envSecondaryServi
16861694 * @param password alias password
16871695 * @param cnName domain name
16881696 * @param dnsName dns name in subject alternate name
1689- * @throws Exception exceptions from the creation
16901697 * @throws IOException IO Exception
16911698 */
16921699 public static void createCertificate (String certPath , String pfxPath , String alias ,
@@ -1754,7 +1761,7 @@ public static void createCertificate(String certPath, String pfxPath, String ali
17541761 * @param ignoreErrorStream : Boolean which controls whether to throw exception or not
17551762 * based on error stream.
17561763 * @return result :- depending on the method invocation.
1757- * @throws Exception exceptions thrown from the execution
1764+ * @throws IOException exceptions thrown from the execution
17581765 */
17591766 public static String cmdInvocation (String [] command ,
17601767 boolean ignoreErrorStream ) throws IOException {
@@ -1771,7 +1778,7 @@ public static String cmdInvocation(String[] command,
17711778 result = br .readLine ();
17721779 process .waitFor ();
17731780 error = ebr .readLine ();
1774- if (error != null && (!error .equals ("" ))) {
1781+ if (error != null && (!"" .equals (error ))) {
17751782 // To do - Log error message
17761783
17771784 if (!ignoreErrorStream ) {
@@ -3346,7 +3353,6 @@ public static void print(SpringApp springApp) {
33463353 StringBuilder info = new StringBuilder ("Spring Service: " )
33473354 .append ("\n \t Id: " ).append (springApp .id ())
33483355 .append ("\n \t Name: " ).append (springApp .name ())
3349- .append ("\n \t Created Time: " ).append (springApp .createdTime ())
33503356 .append ("\n \t Public Endpoint: " ).append (springApp .isPublic ())
33513357 .append ("\n \t Url: " ).append (springApp .url ())
33523358 .append ("\n \t Https Only: " ).append (springApp .isHttpsOnly ())
@@ -3527,11 +3533,19 @@ private static Mono<Response<String>> stringResponse(Mono<HttpResponse> response
35273533 new RetryPolicy ("Retry-After" , ChronoUnit .SECONDS ))
35283534 .build ();
35293535
3536+ /**
3537+ * Get the size of the iterable.
3538+ *
3539+ * @param iterable iterable to count size
3540+ * @param <T> generic type parameter of the iterable
3541+ * @return size of the iterable
3542+ */
35303543 public static <T > int getSize (Iterable <T > iterable ) {
35313544 int res = 0 ;
35323545 Iterator <T > iterator = iterable .iterator ();
35333546 while (iterator .hasNext ()) {
35343547 iterator .next ();
3548+ res ++;
35353549 }
35363550 return res ;
35373551 }
0 commit comments