66import com .azure .core .credential .TokenCredential ;
77import com .azure .core .http .policy .HttpLogDetailLevel ;
88import com .azure .core .management .AzureEnvironment ;
9+ import com .azure .core .management .profile .AzureProfile ;
10+ import com .azure .core .management .Region ;
911import com .azure .identity .DefaultAzureCredentialBuilder ;
1012import com .azure .resourcemanager .AzureResourceManager ;
1113import com .azure .resourcemanager .compute .models .CachingTypes ;
1921import com .azure .resourcemanager .network .models .PublicIpAddress ;
2022import com .azure .resourcemanager .network .models .TransportProtocol ;
2123import com .azure .resourcemanager .network .models .VirtualMachineScaleSetNicIpConfiguration ;
22- import com .azure .core .management .Region ;
23- import com .azure .resourcemanager .resources .fluentcore .model .Indexable ;
24- import com .azure .core .management .profile .AzureProfile ;
2524import com .azure .resourcemanager .samples .Utils ;
2625import reactor .core .publisher .Flux ;
2726
@@ -80,7 +79,7 @@ public static boolean runSample(final AzureResourceManager azureResourceManager)
8079 System .out .println ("Creating a public IP address..." );
8180 System .out .println ("Creating a load balancer" );
8281
83- final List <Indexable > createdResources = new ArrayList <>();
82+ final List <Object > createdResources = new ArrayList <>();
8483
8584 azureResourceManager .resourceGroups ().define (rgName )
8685 .withRegion (region )
@@ -94,118 +93,110 @@ public static boolean runSample(final AzureResourceManager azureResourceManager)
9493 .defineSubnet ("Front-end" )
9594 .withAddressPrefix ("172.16.1.0/24" )
9695 .attach ()
97- .createAsync ()
98- .cast (Indexable .class ),
96+ .createAsync (),
9997 azureResourceManager .publicIpAddresses ().define (publicIpName )
10098 .withRegion (region )
10199 .withExistingResourceGroup (rgName )
102100 .withLeafDomainLabel (publicIpName )
103101 .createAsync ()
104- .cast (Indexable .class )
105- .flatMapMany (indexable -> {
106- if (indexable instanceof PublicIpAddress ) {
107- PublicIpAddress publicIp = (PublicIpAddress ) indexable ;
108- //=============================================================
109- // Create an Internet facing load balancer with
110- // One frontend IP address
111- // Two backend address pools which contain network interfaces for the virtual
112- // machines to receive HTTP and HTTPS network traffic from the load balancer
113- // Two load balancing rules for HTTP and HTTPS to map public ports on the load
114- // balancer to ports in the backend address pool
115- // Two probes which contain HTTP and HTTPS health probes used to check availability
116- // of virtual machines in the backend address pool
117- // Three inbound NAT rules which contain rules that map a public port on the load
118- // balancer to a port for a specific virtual machine in the backend address pool
119- // - this provides direct VM connectivity for SSH to port 22 and TELNET to port 23
120-
121- System .out .println ("Creating a Internet facing load balancer with ..." );
122- System .out .println ("- A frontend IP address" );
123- System .out .println ("- Two backend address pools which contain network interfaces for the virtual\n "
124- + " machines to receive HTTP and HTTPS network traffic from the load balancer" );
125- System .out .println ("- Two load balancing rules for HTTP and HTTPS to map public ports on the load\n "
126- + " balancer to ports in the backend address pool" );
127- System .out .println ("- Two probes which contain HTTP and HTTPS health probes used to check availability\n "
128- + " of virtual machines in the backend address pool" );
129- System .out .println ("- Two inbound NAT rules which contain rules that map a public port on the load\n "
130- + " balancer to a port for a specific virtual machine in the backend address pool\n "
131- + " - this provides direct VM connectivity for SSH to port 22 and TELNET to port 23" );
132-
133- return Flux .merge (
134- Flux .just (indexable ),
135- azureResourceManager .loadBalancers ().define (loadBalancerName1 )
136- .withRegion (region )
137- .withExistingResourceGroup (rgName )
138- // Add two rules that uses above backend and probe
139- .defineLoadBalancingRule (httpLoadBalancingRule )
140- .withProtocol (TransportProtocol .TCP )
141- .fromFrontend (frontendName )
142- .fromFrontendPort (80 )
143- .toBackend (backendPoolName1 )
144- .withProbe (httpProbe )
145- .attach ()
146- .defineLoadBalancingRule (httpsLoadBalancingRule )
147- .withProtocol (TransportProtocol .TCP )
148- .fromFrontend (frontendName )
149- .fromFrontendPort (443 )
150- .toBackend (backendPoolName2 )
151- .withProbe (httpsProbe )
152- .attach ()
153- // Add nat pools to enable direct VM connectivity for
154- // SSH to port 22 and TELNET to port 23
155- .defineInboundNatPool (natPool50XXto22 )
156- .withProtocol (TransportProtocol .TCP )
157- .fromFrontend (frontendName )
158- .fromFrontendPortRange (5000 , 5099 )
159- .toBackendPort (22 )
160- .attach ()
161- .defineInboundNatPool (natPool60XXto23 )
162- .withProtocol (TransportProtocol .TCP )
163- .fromFrontend (frontendName )
164- .fromFrontendPortRange (6000 , 6099 )
165- .toBackendPort (23 )
166- .attach ()
167-
168- // Explicitly define the frontend
169- .definePublicFrontend (frontendName )
170- .withExistingPublicIpAddress (publicIp )
171- .attach ()
172-
173- // Add two probes one per rule
174- .defineHttpProbe (httpProbe )
175- .withRequestPath ("/" )
176- .withPort (80 )
177- .attach ()
178- .defineHttpProbe (httpsProbe )
179- .withRequestPath ("/" )
180- .withPort (443 )
181- .attach ()
182- .createAsync ()
183- .cast (Indexable .class ));
184- }
185- return Flux .just (indexable );
102+ .flatMapMany (publicIp -> {
103+ //=============================================================
104+ // Create an Internet facing load balancer with
105+ // One frontend IP address
106+ // Two backend address pools which contain network interfaces for the virtual
107+ // machines to receive HTTP and HTTPS network traffic from the load balancer
108+ // Two load balancing rules for HTTP and HTTPS to map public ports on the load
109+ // balancer to ports in the backend address pool
110+ // Two probes which contain HTTP and HTTPS health probes used to check availability
111+ // of virtual machines in the backend address pool
112+ // Three inbound NAT rules which contain rules that map a public port on the load
113+ // balancer to a port for a specific virtual machine in the backend address pool
114+ // - this provides direct VM connectivity for SSH to port 22 and TELNET to port 23
115+
116+ System .out .println ("Creating a Internet facing load balancer with ..." );
117+ System .out .println ("- A frontend IP address" );
118+ System .out .println ("- Two backend address pools which contain network interfaces for the virtual\n "
119+ + " machines to receive HTTP and HTTPS network traffic from the load balancer" );
120+ System .out .println ("- Two load balancing rules for HTTP and HTTPS to map public ports on the load\n "
121+ + " balancer to ports in the backend address pool" );
122+ System .out .println ("- Two probes which contain HTTP and HTTPS health probes used to check availability\n "
123+ + " of virtual machines in the backend address pool" );
124+ System .out .println ("- Two inbound NAT rules which contain rules that map a public port on the load\n "
125+ + " balancer to a port for a specific virtual machine in the backend address pool\n "
126+ + " - this provides direct VM connectivity for SSH to port 22 and TELNET to port 23" );
127+
128+ return Flux .merge (
129+ Flux .just (publicIp ),
130+ azureResourceManager .loadBalancers ().define (loadBalancerName1 )
131+ .withRegion (region )
132+ .withExistingResourceGroup (rgName )
133+ // Add two rules that uses above backend and probe
134+ .defineLoadBalancingRule (httpLoadBalancingRule )
135+ .withProtocol (TransportProtocol .TCP )
136+ .fromFrontend (frontendName )
137+ .fromFrontendPort (80 )
138+ .toBackend (backendPoolName1 )
139+ .withProbe (httpProbe )
140+ .attach ()
141+ .defineLoadBalancingRule (httpsLoadBalancingRule )
142+ .withProtocol (TransportProtocol .TCP )
143+ .fromFrontend (frontendName )
144+ .fromFrontendPort (443 )
145+ .toBackend (backendPoolName2 )
146+ .withProbe (httpsProbe )
147+ .attach ()
148+ // Add nat pools to enable direct VM connectivity for
149+ // SSH to port 22 and TELNET to port 23
150+ .defineInboundNatPool (natPool50XXto22 )
151+ .withProtocol (TransportProtocol .TCP )
152+ .fromFrontend (frontendName )
153+ .fromFrontendPortRange (5000 , 5099 )
154+ .toBackendPort (22 )
155+ .attach ()
156+ .defineInboundNatPool (natPool60XXto23 )
157+ .withProtocol (TransportProtocol .TCP )
158+ .fromFrontend (frontendName )
159+ .fromFrontendPortRange (6000 , 6099 )
160+ .toBackendPort (23 )
161+ .attach ()
162+
163+ // Explicitly define the frontend
164+ .definePublicFrontend (frontendName )
165+ .withExistingPublicIpAddress (publicIp )
166+ .attach ()
167+
168+ // Add two probes one per rule
169+ .defineHttpProbe (httpProbe )
170+ .withRequestPath ("/" )
171+ .withPort (80 )
172+ .attach ()
173+ .defineHttpProbe (httpsProbe )
174+ .withRequestPath ("/" )
175+ .withPort (443 )
176+ .attach ()
177+ .createAsync ());
186178 })
187- ).flatMap (indexable -> {
188- createdResources .add (indexable );
189- return Flux .just (indexable );
190- }).last ().block ();
179+ )
180+ .doOnNext (createdResources ::add )
181+ .blockLast ();
191182
192183 Network network = null ;
193184 PublicIpAddress publicIPAddress = null ;
194185 LoadBalancer loadBalancer1 = null ;
195186
196- for (Indexable indexable : createdResources ) {
197- if (indexable instanceof PublicIpAddress ) {
198- publicIPAddress = (PublicIpAddress ) indexable ;
187+ for (Object resource : createdResources ) {
188+ if (resource instanceof PublicIpAddress ) {
189+ publicIPAddress = (PublicIpAddress ) resource ;
199190 System .out .println ("Created a public IP address" );
200191 // Print the virtual network details
201192 Utils .print (publicIPAddress );
202- } else if (indexable instanceof Network ) {
203- network = (Network ) indexable ;
193+ } else if (resource instanceof Network ) {
194+ network = (Network ) resource ;
204195 System .out .println ("Created a virtual network" );
205196 // Print the virtual network details
206197 Utils .print (network );
207- } else if (indexable instanceof LoadBalancer ) {
208- loadBalancer1 = (LoadBalancer ) indexable ;
198+ } else if (resource instanceof LoadBalancer ) {
199+ loadBalancer1 = (LoadBalancer ) resource ;
209200 // Print load balancer details
210201 System .out .println ("Created a load balancer" );
211202 Utils .print (loadBalancer1 );
0 commit comments