Skip to content

Commit d5baaa8

Browse files
author
Dan Schulte
committed
Update and publish samples for 1.3 release
1 parent a639aaa commit d5baaa8

File tree

3 files changed

+163
-25
lines changed

3 files changed

+163
-25
lines changed

LICENSE

+17-17
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
The MIT License (MIT)
1+
MIT License
22

3-
Copyright (c) 2015 Microsoft Corporation
3+
Copyright (c) Microsoft Corporation. All rights reserved.
44

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:
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:
1111

12-
The above copyright notice and this permission notice shall be included in all
13-
copies or substantial portions of the Software.
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
1414

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.
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

pom.xml

+4-4
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@
5353
<dependency>
5454
<groupId>com.microsoft.azure</groupId>
5555
<artifactId>azure</artifactId>
56-
<version>1.2.1</version>
56+
<version>1.3.0</version>
5757
</dependency>
5858
<dependency>
59-
<groupId>com.github.cverges.expect4j</groupId>
60-
<artifactId>expect4j</artifactId>
61-
<version>1.6</version>
59+
<groupId>commons-net</groupId>
60+
<artifactId>commons-net</artifactId>
61+
<version>3.3</version>
6262
</dependency>
6363
</dependencies>
6464
</project>

src/main/java/com/microsoft/azure/management/samples/Utils.java

+142-4
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,18 @@
2626
import com.microsoft.azure.management.batch.BatchAccountKeys;
2727
import com.microsoft.azure.management.compute.AvailabilitySet;
2828
import com.microsoft.azure.management.compute.ContainerService;
29-
import com.microsoft.azure.management.compute.ContainerServiceOchestratorTypes;
29+
import com.microsoft.azure.management.compute.ContainerServiceOrchestratorTypes;
3030
import com.microsoft.azure.management.compute.DataDisk;
3131
import com.microsoft.azure.management.compute.ImageDataDisk;
3232
import com.microsoft.azure.management.compute.VirtualMachine;
3333
import com.microsoft.azure.management.compute.VirtualMachineCustomImage;
3434
import com.microsoft.azure.management.compute.VirtualMachineExtension;
35+
import com.microsoft.azure.management.containerinstance.Container;
36+
import com.microsoft.azure.management.containerinstance.ContainerGroup;
37+
import com.microsoft.azure.management.containerinstance.ContainerPort;
38+
import com.microsoft.azure.management.containerinstance.EnvironmentVariable;
39+
import com.microsoft.azure.management.containerinstance.Volume;
40+
import com.microsoft.azure.management.containerinstance.VolumeMount;
3541
import com.microsoft.azure.management.containerregistry.Registry;
3642
import com.microsoft.azure.management.containerregistry.implementation.RegistryListCredentials;
3743
import com.microsoft.azure.management.cosmosdb.CosmosDBAccount;
@@ -84,13 +90,15 @@
8490
import com.microsoft.azure.management.network.LoadBalancingRule;
8591
import com.microsoft.azure.management.network.Network;
8692
import com.microsoft.azure.management.network.NetworkInterface;
93+
import com.microsoft.azure.management.network.NetworkPeering;
8794
import com.microsoft.azure.management.network.NetworkSecurityGroup;
8895
import com.microsoft.azure.management.network.NetworkSecurityRule;
8996
import com.microsoft.azure.management.network.NetworkWatcher;
9097
import com.microsoft.azure.management.network.NextHop;
9198
import com.microsoft.azure.management.network.PacketCapture;
9299
import com.microsoft.azure.management.network.PacketCaptureFilter;
93100
import com.microsoft.azure.management.network.PublicIPAddress;
101+
import com.microsoft.azure.management.network.RouteTable;
94102
import com.microsoft.azure.management.network.SecurityGroupNetworkInterface;
95103
import com.microsoft.azure.management.network.SecurityGroupView;
96104
import com.microsoft.azure.management.network.Subnet;
@@ -128,6 +136,8 @@
128136
import com.microsoft.azure.management.trafficmanager.TrafficManagerExternalEndpoint;
129137
import com.microsoft.azure.management.trafficmanager.TrafficManagerNestedProfileEndpoint;
130138
import com.microsoft.azure.management.trafficmanager.TrafficManagerProfile;
139+
import okhttp3.OkHttpClient;
140+
import okhttp3.Request;
131141
import org.apache.commons.lang3.StringUtils;
132142
import org.apache.commons.net.ftp.FTP;
133143
import org.apache.commons.net.ftp.FTPClient;
@@ -144,6 +154,7 @@
144154
import java.util.Map;
145155
import java.util.Properties;
146156
import java.util.Set;
157+
import java.util.concurrent.TimeUnit;
147158

148159
/**
149160
* Common utils for Azure management samples.
@@ -267,6 +278,9 @@ public static void print(VirtualMachine resource) {
267278
msi.append("\n\t\t\tMSI Active Directory Service Principal Id:").append(resource.managedServiceIdentityPrincipalId());
268279
msi.append("\n\t\t\tMSI Active Directory Tenant Id:").append(resource.managedServiceIdentityTenantId());
269280

281+
StringBuilder zones = new StringBuilder().append("\n\tZones: ");
282+
zones.append(resource.availabilityZones());
283+
270284
System.out.println(new StringBuilder().append("Virtual Machine: ").append(resource.id())
271285
.append("Name: ").append(resource.name())
272286
.append("\n\tResource group: ").append(resource.resourceGroupName())
@@ -279,6 +293,7 @@ public static void print(VirtualMachine resource) {
279293
.append(networkProfile)
280294
.append(extensions)
281295
.append(msi)
296+
.append(zones)
282297
.toString());
283298
}
284299

@@ -320,12 +335,29 @@ public static void print(Network resource) {
320335
for (Subnet subnet : resource.subnets().values()) {
321336
info.append("\n\tSubnet: ").append(subnet.name())
322337
.append("\n\t\tAddress prefix: ").append(subnet.addressPrefix());
338+
339+
// Output associated NSG
323340
NetworkSecurityGroup subnetNsg = subnet.getNetworkSecurityGroup();
324341
if (subnetNsg != null) {
325-
info.append("\n\t\tNetwork security group: ").append(subnetNsg.id());
342+
info.append("\n\t\tNetwork security group ID: ").append(subnetNsg.id());
343+
}
344+
345+
// Output associated route table
346+
RouteTable routeTable = subnet.getRouteTable();
347+
if (routeTable != null) {
348+
info.append("\n\tRoute table ID: ").append(routeTable.id());
326349
}
327350
}
328351

352+
// Output peerings
353+
for (NetworkPeering peering : resource.peerings().list()) {
354+
info.append("\n\tPeering: ").append(peering.name())
355+
.append("\n\t\tRemote network ID: ").append(peering.remoteNetworkId())
356+
.append("\n\t\tPeering state: ").append(peering.state())
357+
.append("\n\t\tIs traffic forwarded from remote network allowed? ").append(peering.isTrafficForwardingFromRemoteNetworkAllowed())
358+
//TODO .append("\n\t\tIs access from remote network allowed? ").append(peering.isAccessFromRemoteNetworkAllowed())
359+
.append("\n\t\tGateway use: ").append(peering.gatewayUse());
360+
}
329361
System.out.println(info.toString());
330362
}
331363

@@ -410,6 +442,7 @@ public static void print(PublicIPAddress resource) {
410442
.append("\n\tReverse FQDN: ").append(resource.reverseFqdn())
411443
.append("\n\tIdle timeout (minutes): ").append(resource.idleTimeoutInMinutes())
412444
.append("\n\tIP allocation method: ").append(resource.ipAllocationMethod())
445+
.append("\n\tZones: ").append(resource.availabilityZones())
413446
.toString());
414447
}
415448

@@ -1097,7 +1130,7 @@ public static void print(ContainerService containerService) {
10971130
.append("\n\t\tAgent pool leaf domain label: ").append(containerService.agentPoolLeafDomainLabel())
10981131
.append("\n\tLinux user name: ").append(containerService.linuxRootUsername())
10991132
.append("\n\tSSH key: ").append(containerService.sshKey());
1100-
if (containerService.orchestratorType() == ContainerServiceOchestratorTypes.KUBERNETES) {
1133+
if (containerService.orchestratorType() == ContainerServiceOrchestratorTypes.KUBERNETES) {
11011134
info.append("\n\tName: ").append(containerService.servicePrincipalClientId());
11021135
}
11031136

@@ -1933,7 +1966,7 @@ public static void print(CosmosDBAccount cosmosDBAccount) {
19331966
.append("\n\t\t\tName :").append(readReplica.locationName());
19341967
}
19351968
}
1936-
1969+
19371970
/**
19381971
* Print Active Directory User info.
19391972
* @param user active directory user
@@ -2211,4 +2244,109 @@ public static void print(NextHop resource) {
22112244
.append("\n\tRoute table id: ").append(resource.routeTableId())
22122245
.toString());
22132246
}
2247+
2248+
/**
2249+
* Print container group info.
2250+
*
2251+
* @param resource a container group
2252+
*/
2253+
public static void print(ContainerGroup resource) {
2254+
StringBuilder info = new StringBuilder().append("Container Group: ").append(resource.id())
2255+
.append("Name: ").append(resource.name())
2256+
.append("\n\tResource group: ").append(resource.resourceGroupName())
2257+
.append("\n\tRegion: ").append(resource.region())
2258+
.append("\n\tTags: ").append(resource.tags())
2259+
.append("\n\tOS type: ").append(resource.osType());
2260+
2261+
if (resource.ipAddress() != null) {
2262+
info.append("\n\tPublic IP address: ").append(resource.ipAddress());
2263+
}
2264+
if (resource.externalTcpPorts() != null) {
2265+
info.append("\n\tExternal TCP ports:");
2266+
for (int port : resource.externalTcpPorts()) {
2267+
info.append(" ").append(port);
2268+
}
2269+
}
2270+
if (resource.externalUdpPorts() != null) {
2271+
info.append("\n\tExternal UDP ports:");
2272+
for (int port : resource.externalUdpPorts()) {
2273+
info.append(" ").append(port);
2274+
}
2275+
}
2276+
if (resource.imageRegistryServers() != null) {
2277+
info.append("\n\tPrivate Docker image registries:");
2278+
for (String server : resource.imageRegistryServers()) {
2279+
info.append(" ").append(server);
2280+
}
2281+
}
2282+
if (resource.volumes() != null) {
2283+
info.append("\n\tVolume mapping: ");
2284+
for (Map.Entry<String, Volume> entry: resource.volumes().entrySet()) {
2285+
info.append("\n\t\tName: ").append(entry.getKey()).append(" -> ").append(entry.getValue().azureFile().shareName());
2286+
}
2287+
}
2288+
if (resource.containers() != null) {
2289+
info.append("\n\tContainer instances: ");
2290+
for (Map.Entry<String, Container> entry: resource.containers().entrySet()) {
2291+
Container container = entry.getValue();
2292+
info.append("\n\t\tName: ").append(entry.getKey()).append(" -> ").append(container.image());
2293+
info.append("\n\t\t\tResources: ");
2294+
info.append(container.resources().requests().cpu()).append("CPUs ");
2295+
info.append(container.resources().requests().memoryInGB()).append("GB");
2296+
info.append("\n\t\t\tPorts:");
2297+
for (ContainerPort port : container.ports()) {
2298+
info.append(" ").append(port.port());
2299+
}
2300+
if (container.volumeMounts() != null) {
2301+
info.append("\n\t\t\tVolume mounts:");
2302+
for (VolumeMount volumeMount : container.volumeMounts()) {
2303+
info.append(" ").append(volumeMount.name()).append("->").append(volumeMount.mountPath());
2304+
}
2305+
}
2306+
if (container.command() != null) {
2307+
info.append("\n\t\t\tStart commands:");
2308+
for (String command : container.command()) {
2309+
info.append("\n\t\t\t\t").append(command);
2310+
}
2311+
}
2312+
if (container.environmentVariables() != null) {
2313+
info.append("\n\t\t\tENV vars:");
2314+
for (EnvironmentVariable envVar : container.environmentVariables()) {
2315+
info.append("\n\t\t\t\t").append(envVar.name()).append("=").append(envVar.value());
2316+
}
2317+
}
2318+
}
2319+
}
2320+
2321+
System.out.println(info.toString());
2322+
}
2323+
2324+
private static OkHttpClient httpClient;
2325+
2326+
/**
2327+
* Ensure the HTTP client is valid.
2328+
*
2329+
*/
2330+
private static OkHttpClient ensureValidHttpClient() {
2331+
if (httpClient == null) {
2332+
httpClient = new OkHttpClient.Builder().readTimeout(1, TimeUnit.MINUTES).build();
2333+
}
2334+
2335+
return httpClient;
2336+
}
2337+
2338+
/**
2339+
* Connect to a specified URL using "curl" like HTTP GET client.
2340+
*
2341+
* @param url URL to be tested
2342+
* @return the HTTP GET response content
2343+
*/
2344+
public static String curl(String url) {
2345+
Request request = new Request.Builder().url(url).get().build();
2346+
try {
2347+
return ensureValidHttpClient().newCall(request).execute().body().string();
2348+
} catch (IOException e) {
2349+
return null;
2350+
}
2351+
}
22142352
}

0 commit comments

Comments
 (0)