3333import java .util .Comparator ;
3434import java .util .HashMap ;
3535import java .util .HashSet ;
36+ import java .util .LinkedHashSet ;
3637import java .util .List ;
3738import java .util .Map ;
3839import java .util .Set ;
@@ -57,15 +58,15 @@ class CdnEndpointImpl extends ExternalChildResourceImpl<CdnEndpoint, EndpointInn
5758
5859 CdnEndpoint .UpdateStandardEndpoint , CdnEndpoint .UpdatePremiumEndpoint {
5960
60- private List < CustomDomainInner > customDomainList ;
61- private List < CustomDomainInner > deletedCustomDomainList ;
61+ private Set < String > customDomainHostnames ;
62+ private Set < String > deletedCustomDomainHostnames ;
6263 // rule map for rules engine in Standard Microsoft SKU, indexed by rule name
6364 private final Map <String , DeliveryRule > standardRulesEngineRuleMap = new HashMap <>();
6465
6566 CdnEndpointImpl (String name , CdnProfileImpl parent , EndpointInner inner ) {
6667 super (name , parent , inner );
67- this .customDomainList = new ArrayList <>();
68- this .deletedCustomDomainList = new ArrayList <>();
68+ this .customDomainHostnames = new LinkedHashSet <>();
69+ this .deletedCustomDomainHostnames = new HashSet <>();
6970 initializeRuleMapForStandardMicrosoftSku ();
7071 }
7172
@@ -94,8 +95,8 @@ public Mono<CdnEndpoint> createResourceAsync() {
9495 .createAsync (this .parent ().resourceGroupName (), this .parent ().name (), this .name (), this .innerModel ())
9596 .flatMap (inner -> {
9697 self .setInner (inner );
97- return Flux .fromIterable (self .customDomainList )
98- .flatMapDelayError (customDomainInner -> self .parent ()
98+ return Flux .fromIterable (self .customDomainHostnames )
99+ .flatMapDelayError (customDomain -> self .parent ()
99100 .manager ()
100101 .serviceClient ()
101102 .getCustomDomains ()
@@ -105,7 +106,7 @@ public Mono<CdnEndpoint> createResourceAsync() {
105106 .resourceManager ()
106107 .internalContext ()
107108 .randomResourceName ("CustomDomain" , 50 ),
108- new CustomDomainParameters ().withHostname (customDomainInner . hostname () )),
109+ new CustomDomainParameters ().withHostname (customDomain )),
109110 32 , 32 )
110111 .then (self .parent ()
111112 .manager ()
@@ -114,7 +115,9 @@ public Mono<CdnEndpoint> createResourceAsync() {
114115 .listByEndpointAsync (self .parent ().resourceGroupName (), self .parent ().name (), self .name ())
115116 .collectList ()
116117 .map (customDomainInners -> {
117- self .customDomainList .addAll (customDomainInners );
118+ self .customDomainHostnames .addAll (customDomainInners .stream ()
119+ .map (CustomDomainInner ::hostname )
120+ .collect (Collectors .toSet ()));
118121 return self ;
119122 }));
120123 });
@@ -166,31 +169,42 @@ public Mono<CdnEndpoint> updateResourceAsync() {
166169 .updateAsync (this .parent ().resourceGroupName (), this .parent ().name (), this .name (),
167170 endpointUpdateParameters );
168171
169- Flux <CustomDomainInner > customDomainCreateTask = Flux .fromIterable (this .customDomainList )
172+ Flux <CustomDomainInner > customDomainCreateTask = Flux .fromIterable (this .customDomainHostnames )
170173 .flatMapDelayError (itemToCreate -> this .parent ()
171174 .manager ()
172175 .serviceClient ()
173176 .getCustomDomains ()
174177 .createAsync (this .parent ().resourceGroupName (), this .parent ().name (), this .name (),
175178 self .parent ().manager ().resourceManager ().internalContext ().randomResourceName ("CustomDomain" , 50 ),
176- new CustomDomainParameters ().withHostname (itemToCreate . hostname () )),
179+ new CustomDomainParameters ().withHostname (itemToCreate )),
177180 32 , 32 );
178181
179- Flux <CustomDomainInner > customDomainDeleteTask = Flux .fromIterable (this .deletedCustomDomainList )
180- .flatMapDelayError (itemToDelete -> this .parent ()
182+ Flux <CustomDomainInner > customDomainDeleteTask ;
183+ if (this .deletedCustomDomainHostnames .isEmpty ()) {
184+ customDomainDeleteTask = Flux .empty ();
185+ } else {
186+ customDomainDeleteTask = this .parent ()
181187 .manager ()
182188 .serviceClient ()
183189 .getCustomDomains ()
184- .deleteAsync (this .parent ().resourceGroupName (), this .parent ().name (), this .name (), itemToDelete .name ()),
185- 32 , 32 );
190+ .listByEndpointAsync (this .parent ().resourceGroupName (), this .parent ().name (), this .name ())
191+ .filter (customDomain -> this .deletedCustomDomainHostnames .contains (customDomain .hostname ()))
192+ .flatMapDelayError (itemToDelete -> this .parent ()
193+ .manager ()
194+ .serviceClient ()
195+ .getCustomDomains ()
196+ .deleteAsync (this .parent ().resourceGroupName (), this .parent ().name (), this .name (),
197+ itemToDelete .name ()),
198+ 32 , 32 );
199+ }
186200
187201 Mono <EndpointInner > customDomainTask
188202 = Flux .concat (customDomainCreateTask , customDomainDeleteTask ).then (Mono .empty ());
189203
190204 return Flux .mergeDelayError (32 , customDomainTask , originUpdateTask , endpointUpdateTask ).last ().map (inner -> {
191205 self .setInner (inner );
192- self .customDomainList .clear ();
193- self .deletedCustomDomainList .clear ();
206+ self .customDomainHostnames .clear ();
207+ self .deletedCustomDomainHostnames .clear ();
194208 return self ;
195209 });
196210 }
@@ -208,8 +222,8 @@ public Mono<Void> deleteResourceAsync() {
208222 public Mono <CdnEndpoint > refreshAsync () {
209223 final CdnEndpointImpl self = this ;
210224 return super .refreshAsync ().flatMap (cdnEndpoint -> {
211- self .customDomainList .clear ();
212- self .deletedCustomDomainList .clear ();
225+ self .customDomainHostnames .clear ();
226+ self .deletedCustomDomainHostnames .clear ();
213227 initializeRuleMapForStandardMicrosoftSku ();
214228 return self .parent ()
215229 .manager ()
@@ -218,7 +232,8 @@ public Mono<CdnEndpoint> refreshAsync() {
218232 .listByEndpointAsync (self .parent ().resourceGroupName (), self .parent ().name (), self .name ())
219233 .collectList ()
220234 .map (customDomainInners -> {
221- self .customDomainList .addAll (customDomainInners );
235+ self .customDomainHostnames .addAll (
236+ customDomainInners .stream ().map (CustomDomainInner ::hostname ).collect (Collectors .toSet ()));
222237 return self ;
223238 });
224239 });
@@ -580,7 +595,7 @@ public CdnEndpointImpl withoutGeoFilter(String relativePath) {
580595
581596 @ Override
582597 public CdnEndpointImpl withCustomDomain (String hostName ) {
583- this .customDomainList .add (new CustomDomainInner (). withHostname ( hostName ) );
598+ this .customDomainHostnames .add (hostName );
584599 return this ;
585600 }
586601
@@ -607,7 +622,7 @@ public CdnEndpointImpl withoutStandardRulesEngineRule(String name) {
607622
608623 @ Override
609624 public CdnEndpointImpl withoutCustomDomain (String hostName ) {
610- deletedCustomDomainList .add (new CustomDomainInner (). withHostname ( hostName ) );
625+ deletedCustomDomainHostnames .add (hostName );
611626 return this ;
612627 }
613628
0 commit comments