16
16
import com .azure .core .http .rest .PagedIterable ;
17
17
import com .azure .core .http .rest .Response ;
18
18
import com .azure .core .http .rest .SimpleResponse ;
19
+ import com .azure .core .management .Region ;
19
20
import com .azure .core .management .exception .ManagementException ;
20
21
import com .azure .core .util .logging .ClientLogger ;
21
22
import com .azure .core .util .serializer .JacksonAdapter ;
71
72
import com .azure .resourcemanager .dns .models .AaaaRecordSet ;
72
73
import com .azure .resourcemanager .dns .models .CnameRecordSet ;
73
74
import com .azure .resourcemanager .dns .models .DnsZone ;
74
- import com .azure .resourcemanager .dns .models .MxRecordSet ;
75
75
import com .azure .resourcemanager .dns .models .MxRecord ;
76
+ import com .azure .resourcemanager .dns .models .MxRecordSet ;
76
77
import com .azure .resourcemanager .dns .models .NsRecordSet ;
77
78
import com .azure .resourcemanager .dns .models .PtrRecordSet ;
78
79
import com .azure .resourcemanager .dns .models .SoaRecord ;
163
164
import com .azure .resourcemanager .redis .models .RedisCache ;
164
165
import com .azure .resourcemanager .redis .models .RedisCachePremium ;
165
166
import com .azure .resourcemanager .redis .models .ScheduleEntry ;
166
- import com .azure .core .management .Region ;
167
167
import com .azure .resourcemanager .resources .fluentcore .arm .models .PrivateLinkResource ;
168
168
import com .azure .resourcemanager .resources .fluentcore .utils .ResourceManagerUtils ;
169
169
import com .azure .resourcemanager .resources .models .ManagementLock ;
201
201
import com .azure .resourcemanager .trafficmanager .models .TrafficManagerExternalEndpoint ;
202
202
import com .azure .resourcemanager .trafficmanager .models .TrafficManagerNestedProfileEndpoint ;
203
203
import com .azure .resourcemanager .trafficmanager .models .TrafficManagerProfile ;
204
- import com .jcraft .jsch .JSchException ;
205
204
import org .apache .commons .net .ftp .FTP ;
206
205
import org .apache .commons .net .ftp .FTPClient ;
207
206
import reactor .core .publisher .Mono ;
215
214
import java .io .IOException ;
216
215
import java .io .InputStream ;
217
216
import java .io .InputStreamReader ;
218
- import java .io .UnsupportedEncodingException ;
219
217
import java .nio .charset .StandardCharsets ;
220
218
import java .nio .file .Files ;
221
219
import java .security .KeyPair ;
241
239
/**
242
240
* Common utils for Azure management samples.
243
241
*/
244
-
245
242
public final class Utils {
246
243
244
+ // IMPORTANT: do not use SSHShell in Utils
245
+
247
246
private static final ClientLogger LOGGER = new ClientLogger (Utils .class );
248
247
249
248
private static String sshPublicKey ;
@@ -396,6 +395,12 @@ public static void print(VirtualMachine resource) {
396
395
storageProfile .append ("\n \t \t \t Caching: " ).append (resource .storageProfile ().osDisk ().caching ());
397
396
storageProfile .append ("\n \t \t \t CreateOption: " ).append (resource .storageProfile ().osDisk ().createOption ());
398
397
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
+ }
399
404
if (resource .storageProfile ().osDisk ().image () != null ) {
400
405
storageProfile .append ("\n \t \t \t Image Uri: " ).append (resource .storageProfile ().osDisk ().image ().uri ());
401
406
}
@@ -430,6 +435,9 @@ public static void print(VirtualMachine resource) {
430
435
if (resource .isManagedDiskEnabled ()) {
431
436
if (disk .managedDisk () != null ) {
432
437
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
+ }
433
441
}
434
442
} else {
435
443
if (disk .vhd ().uri () != null ) {
@@ -1626,7 +1634,7 @@ public static void print(SearchService searchService) {
1626
1634
*
1627
1635
* @param envSecondaryServicePrincipal an Azure Container Registry
1628
1636
* @return a service principal client ID
1629
- * @throws Exception exception
1637
+ * @throws IOException exception
1630
1638
*/
1631
1639
public static String getSecondaryServicePrincipalClientID (String envSecondaryServicePrincipal ) throws IOException {
1632
1640
String content = new String (Files .readAllBytes (new File (envSecondaryServicePrincipal ).toPath ()), StandardCharsets .UTF_8 ).trim ();
@@ -1649,7 +1657,7 @@ public static String getSecondaryServicePrincipalClientID(String envSecondarySer
1649
1657
*
1650
1658
* @param envSecondaryServicePrincipal an Azure Container Registry
1651
1659
* @return a service principal secret
1652
- * @throws Exception exception
1660
+ * @throws IOException exception
1653
1661
*/
1654
1662
public static String getSecondaryServicePrincipalSecret (String envSecondaryServicePrincipal ) throws IOException {
1655
1663
String content = new String (Files .readAllBytes (new File (envSecondaryServicePrincipal ).toPath ()), StandardCharsets .UTF_8 ).trim ();
@@ -1686,7 +1694,6 @@ public static String getSecondaryServicePrincipalSecret(String envSecondaryServi
1686
1694
* @param password alias password
1687
1695
* @param cnName domain name
1688
1696
* @param dnsName dns name in subject alternate name
1689
- * @throws Exception exceptions from the creation
1690
1697
* @throws IOException IO Exception
1691
1698
*/
1692
1699
public static void createCertificate (String certPath , String pfxPath , String alias ,
@@ -1754,7 +1761,7 @@ public static void createCertificate(String certPath, String pfxPath, String ali
1754
1761
* @param ignoreErrorStream : Boolean which controls whether to throw exception or not
1755
1762
* based on error stream.
1756
1763
* @return result :- depending on the method invocation.
1757
- * @throws Exception exceptions thrown from the execution
1764
+ * @throws IOException exceptions thrown from the execution
1758
1765
*/
1759
1766
public static String cmdInvocation (String [] command ,
1760
1767
boolean ignoreErrorStream ) throws IOException {
@@ -1771,7 +1778,7 @@ public static String cmdInvocation(String[] command,
1771
1778
result = br .readLine ();
1772
1779
process .waitFor ();
1773
1780
error = ebr .readLine ();
1774
- if (error != null && (!error .equals ("" ))) {
1781
+ if (error != null && (!"" .equals (error ))) {
1775
1782
// To do - Log error message
1776
1783
1777
1784
if (!ignoreErrorStream ) {
@@ -3346,7 +3353,6 @@ public static void print(SpringApp springApp) {
3346
3353
StringBuilder info = new StringBuilder ("Spring Service: " )
3347
3354
.append ("\n \t Id: " ).append (springApp .id ())
3348
3355
.append ("\n \t Name: " ).append (springApp .name ())
3349
- .append ("\n \t Created Time: " ).append (springApp .createdTime ())
3350
3356
.append ("\n \t Public Endpoint: " ).append (springApp .isPublic ())
3351
3357
.append ("\n \t Url: " ).append (springApp .url ())
3352
3358
.append ("\n \t Https Only: " ).append (springApp .isHttpsOnly ())
@@ -3527,11 +3533,19 @@ private static Mono<Response<String>> stringResponse(Mono<HttpResponse> response
3527
3533
new RetryPolicy ("Retry-After" , ChronoUnit .SECONDS ))
3528
3534
.build ();
3529
3535
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
+ */
3530
3543
public static <T > int getSize (Iterable <T > iterable ) {
3531
3544
int res = 0 ;
3532
3545
Iterator <T > iterator = iterable .iterator ();
3533
3546
while (iterator .hasNext ()) {
3534
3547
iterator .next ();
3548
+ res ++;
3535
3549
}
3536
3550
return res ;
3537
3551
}
0 commit comments