Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mgmt: make createAsync return Mono<ModelT> #15212

Merged
merged 16 commits into from
Sep 16, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.azure.resourcemanager.keyvault.models.Vault;
import com.azure.resourcemanager.resources.fluentcore.arm.Region;
import com.azure.resourcemanager.resources.fluentcore.arm.models.implementation.GroupableResourceImpl;
import com.azure.resourcemanager.resources.fluentcore.model.Indexable;
import com.azure.resourcemanager.resources.fluentcore.utils.Utils;
import reactor.core.publisher.Mono;

Expand Down Expand Up @@ -246,7 +245,7 @@ public AppServiceCertificateOrderImpl withExistingKeyVault(Vault vault) {

@Override
public AppServiceCertificateOrderImpl withNewKeyVault(String vaultName, Region region) {
Mono<Indexable> resourceStream =
this.bindingVault =
myManager
.keyVaultManager()
.vaults()
Expand All @@ -261,9 +260,7 @@ public AppServiceCertificateOrderImpl withNewKeyVault(String vaultName, Region r
.forServicePrincipal("abfa0a7c-a6b6-4736-8310-5855508787cd")
.allowSecretPermissions(SecretPermissions.GET)
.attach()
.createAsync()
.last();
this.bindingVault = Utils.rootResource(resourceStream);
.createAsync();
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,23 @@
package com.azure.resourcemanager.appservice.implementation;

import com.azure.resourcemanager.appservice.AppServiceManager;
import com.azure.resourcemanager.appservice.fluent.DomainsClient;
import com.azure.resourcemanager.appservice.fluent.inner.DomainInner;
import com.azure.resourcemanager.appservice.fluent.inner.DomainOwnershipIdentifierInner;
import com.azure.resourcemanager.appservice.fluent.inner.TldLegalAgreementInner;
import com.azure.resourcemanager.appservice.models.AppServiceDomain;
import com.azure.resourcemanager.appservice.models.Contact;
import com.azure.resourcemanager.appservice.models.DnsType;
import com.azure.resourcemanager.appservice.models.DomainPurchaseConsent;
import com.azure.resourcemanager.appservice.models.DomainStatus;
import com.azure.resourcemanager.appservice.models.Hostname;
import com.azure.resourcemanager.appservice.models.TopLevelDomainAgreementOption;
import com.azure.resourcemanager.appservice.fluent.inner.DomainInner;
import com.azure.resourcemanager.appservice.fluent.inner.DomainOwnershipIdentifierInner;
import com.azure.resourcemanager.appservice.fluent.DomainsClient;
import com.azure.resourcemanager.appservice.fluent.inner.TldLegalAgreementInner;
import com.azure.resourcemanager.dns.models.DnsZone;
import com.azure.resourcemanager.resources.fluentcore.arm.models.implementation.GroupableResourceImpl;
import com.azure.resourcemanager.resources.fluentcore.model.Creatable;
import com.azure.resourcemanager.resources.fluentcore.model.Indexable;
import com.azure.resourcemanager.resources.fluentcore.utils.Utils;
import reactor.core.publisher.Mono;

import java.net.Inet4Address;
import java.net.UnknownHostException;
import java.time.OffsetDateTime;
Expand All @@ -29,9 +30,6 @@
import java.util.function.Function;
import java.util.stream.Collectors;

import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

/** The implementation for AppServiceDomain. */
class AppServiceDomainImpl
extends GroupableResourceImpl<AppServiceDomain, DomainInner, AppServiceDomainImpl, AppServiceManager>
Expand All @@ -51,7 +49,7 @@ class AppServiceDomainImpl
}

@Override
public Flux<Indexable> createAsync() {
public Mono<AppServiceDomain> createAsync() {
if (this.isInCreateMode()) {
// create a default DNS zone, if not specified
if (this.inner().dnsZoneId() == null && dnsZoneCreatable == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ public void zipDeploy(InputStream zipFile) {
}

@Override
public Flux<Indexable> createAsync() {
public Mono<FunctionApp> createAsync() {
if (this.isInCreateMode()) {
if (inner().serverFarmId() == null) {
withNewConsumptionPlan();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,23 @@
package com.azure.resourcemanager.appservice.implementation;

import com.azure.core.util.logging.ClientLogger;
import com.azure.resourcemanager.appservice.fluent.inner.HostnameBindingInner;
import com.azure.resourcemanager.appservice.models.AppServiceDomain;
import com.azure.resourcemanager.appservice.models.AzureResourceType;
import com.azure.resourcemanager.appservice.models.CustomHostnameDnsRecordType;
import com.azure.resourcemanager.appservice.models.DeploymentSlot;
import com.azure.resourcemanager.appservice.models.HostnameBinding;
import com.azure.resourcemanager.appservice.models.HostnameType;
import com.azure.resourcemanager.appservice.models.WebAppBase;
import com.azure.resourcemanager.appservice.fluent.inner.HostnameBindingInner;
import com.azure.resourcemanager.resources.fluentcore.arm.Region;
import com.azure.resourcemanager.resources.fluentcore.model.Creatable;
import com.azure.resourcemanager.resources.fluentcore.model.Indexable;
import com.azure.resourcemanager.resources.fluentcore.model.implementation.IndexableWrapperImpl;
import reactor.core.publisher.Mono;

import java.util.Map;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

/**
* Implementation for {@link HostnameBinding} and its create and update interfaces.
Expand Down Expand Up @@ -168,20 +167,19 @@ public Mono<HostnameBinding> refreshAsync() {

@Override
public HostnameBinding create() {
createAsync().blockLast();
return this;
return createAsync().block();
}

@Override
public Flux<Indexable> createAsync() {
public Mono<HostnameBinding> createAsync() {
final HostnameBinding self = this;
Function<HostnameBindingInner, HostnameBinding> mapper =
hostnameBindingInner -> {
setInner(hostnameBindingInner);
return self;
};

Mono<Indexable> hostnameBindingObservable;
Mono<HostnameBinding> hostnameBindingObservable;
if (parent instanceof DeploymentSlot) {
hostnameBindingObservable =
this
Expand All @@ -207,7 +205,7 @@ public Flux<Indexable> createAsync() {
.map(mapper);
}

return hostnameBindingObservable.flux();
return hostnameBindingObservable;
}

private String normalizeHostNameBindingName(String hostname, String domainName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
import com.azure.resourcemanager.appservice.models.WebAppBase;
import com.azure.resourcemanager.keyvault.models.Vault;
import com.azure.resourcemanager.resources.fluentcore.arm.Region;
import com.azure.resourcemanager.resources.fluentcore.model.Indexable;
import com.azure.resourcemanager.resources.fluentcore.model.implementation.IndexableWrapperImpl;
import com.azure.resourcemanager.resources.fluentcore.utils.Utils;
import reactor.core.publisher.Mono;

import java.io.File;
Expand Down Expand Up @@ -83,19 +81,16 @@ public HostnameSslBindingImpl<FluentT, FluentImplT> withPfxCertificateToUpload(
final File pfxFile, final String password) {
String thumbprint = getCertificateThumbprint(pfxFile.getPath(), password);
newCertificate =
Utils
.rootResource(
this
.parent()
.manager()
.certificates()
.define(getCertificateUniqueName(thumbprint, parent().region()))
.withRegion(parent().region())
.withExistingResourceGroup(parent().resourceGroupName())
.withPfxFile(pfxFile)
.withPfxPassword(password)
.createAsync()
.last());
this
.parent()
.manager()
.certificates()
.define(getCertificateUniqueName(thumbprint, parent().region()))
.withRegion(parent().region())
.withExistingResourceGroup(parent().resourceGroupName())
.withPfxFile(pfxFile)
.withPfxPassword(password)
.createAsync();
return this;
}

Expand Down Expand Up @@ -148,7 +143,7 @@ public HostnameSslBindingImpl<FluentT, FluentImplT> withNewStandardSslCertificat
@Override
public HostnameSslBindingImpl<FluentT, FluentImplT> withExistingAppServiceCertificateOrder(
final AppServiceCertificateOrder certificateOrder) {
Mono<Indexable> resourceStream =
newCertificate =
this
.parent()
.manager()
Expand All @@ -157,9 +152,7 @@ public HostnameSslBindingImpl<FluentT, FluentImplT> withExistingAppServiceCertif
.withRegion(parent().region())
.withExistingResourceGroup(parent().resourceGroupName())
.withExistingCertificateOrder(certificateOrder)
.createAsync()
.last();
newCertificate = Utils.rootResource(resourceStream);
.createAsync();
return this;
}

Expand Down Expand Up @@ -204,46 +197,38 @@ public HostnameSslBindingImpl<FluentT, FluentImplT> forHostname(String hostname)
@Override
public HostnameSslBindingImpl<FluentT, FluentImplT> withExistingKeyVault(final Vault vault) {
Mono<AppServiceCertificateOrder> appServiceCertificateOrderObservable =
Utils.rootResource(certificateInDefinition.withExistingKeyVault(vault).createAsync().last());
certificateInDefinition.withExistingKeyVault(vault).createAsync();
final AppServiceManager manager = this.parent().manager();
this.newCertificate =
appServiceCertificateOrderObservable
.flatMap(
appServiceCertificateOrder ->
Utils
.rootResource(
manager
.certificates()
.define(appServiceCertificateOrder.name())
.withRegion(parent().regionName())
.withExistingResourceGroup(parent().resourceGroupName())
.withExistingCertificateOrder(appServiceCertificateOrder)
.createAsync()
.last()));
manager
.certificates()
.define(appServiceCertificateOrder.name())
.withRegion(parent().regionName())
.withExistingResourceGroup(parent().resourceGroupName())
.withExistingCertificateOrder(appServiceCertificateOrder)
.createAsync());
return this;
}

@Override
public HostnameSslBindingImpl<FluentT, FluentImplT> withNewKeyVault(String vaultName) {
Mono<AppServiceCertificateOrder> appServiceCertificateOrderObservable =
Utils
.rootResource(
certificateInDefinition.withNewKeyVault(vaultName, parent().region()).createAsync().last());
certificateInDefinition.withNewKeyVault(vaultName, parent().region()).createAsync();
final AppServiceManager manager = this.parent().manager();
this.newCertificate =
appServiceCertificateOrderObservable
.flatMap(
appServiceCertificateOrder ->
Utils
.rootResource(
manager
.certificates()
.define(appServiceCertificateOrder.name())
.withRegion(parent().regionName())
.withExistingResourceGroup(parent().resourceGroupName())
.withExistingCertificateOrder(appServiceCertificateOrder)
.createAsync()
.last()));
manager
.certificates()
.define(appServiceCertificateOrder.name())
.withRegion(parent().regionName())
.withExistingResourceGroup(parent().resourceGroupName())
.withExistingCertificateOrder(appServiceCertificateOrder)
.createAsync());
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@
import com.azure.core.management.AzureEnvironment;
import com.azure.core.util.logging.ClientLogger;
import com.azure.resourcemanager.appservice.AppServiceManager;
import com.azure.resourcemanager.appservice.fluent.inner.ConnectionStringDictionaryInner;
import com.azure.resourcemanager.appservice.fluent.inner.HostnameBindingInner;
import com.azure.resourcemanager.appservice.fluent.inner.MSDeployStatusInner;
import com.azure.resourcemanager.appservice.fluent.inner.SiteAuthSettingsInner;
import com.azure.resourcemanager.appservice.fluent.inner.SiteConfigInner;
import com.azure.resourcemanager.appservice.fluent.inner.SiteConfigResourceInner;
import com.azure.resourcemanager.appservice.fluent.inner.SiteInner;
import com.azure.resourcemanager.appservice.fluent.inner.SiteLogsConfigInner;
import com.azure.resourcemanager.appservice.fluent.inner.SitePatchResourceInner;
import com.azure.resourcemanager.appservice.fluent.inner.SiteSourceControlInner;
import com.azure.resourcemanager.appservice.fluent.inner.SlotConfigNamesResourceInner;
import com.azure.resourcemanager.appservice.fluent.inner.StringDictionaryInner;
import com.azure.resourcemanager.appservice.models.AppServiceCertificate;
import com.azure.resourcemanager.appservice.models.AppServiceDomain;
import com.azure.resourcemanager.appservice.models.AppSetting;
Expand Down Expand Up @@ -42,21 +54,9 @@
import com.azure.resourcemanager.appservice.models.WebAppAuthentication;
import com.azure.resourcemanager.appservice.models.WebAppBase;
import com.azure.resourcemanager.appservice.models.WebContainer;
import com.azure.resourcemanager.appservice.fluent.inner.ConnectionStringDictionaryInner;
import com.azure.resourcemanager.appservice.fluent.inner.HostnameBindingInner;
import com.azure.resourcemanager.appservice.fluent.inner.MSDeployStatusInner;
import com.azure.resourcemanager.appservice.fluent.inner.SiteAuthSettingsInner;
import com.azure.resourcemanager.appservice.fluent.inner.SiteConfigInner;
import com.azure.resourcemanager.appservice.fluent.inner.SiteConfigResourceInner;
import com.azure.resourcemanager.appservice.fluent.inner.SiteInner;
import com.azure.resourcemanager.appservice.fluent.inner.SiteLogsConfigInner;
import com.azure.resourcemanager.appservice.fluent.inner.SitePatchResourceInner;
import com.azure.resourcemanager.appservice.fluent.inner.SiteSourceControlInner;
import com.azure.resourcemanager.appservice.fluent.inner.SlotConfigNamesResourceInner;
import com.azure.resourcemanager.appservice.fluent.inner.StringDictionaryInner;
import com.azure.resourcemanager.appservice.models.WebSiteBase;
import com.azure.resourcemanager.authorization.models.BuiltInRole;
import com.azure.resourcemanager.authorization.implementation.RoleAssignmentHelper;
import com.azure.resourcemanager.authorization.models.BuiltInRole;
import com.azure.resourcemanager.msi.models.Identity;
import com.azure.resourcemanager.resources.fluentcore.arm.models.implementation.GroupableResourceImpl;
import com.azure.resourcemanager.resources.fluentcore.dag.FunctionalTaskItem;
Expand All @@ -65,6 +65,11 @@
import com.azure.resourcemanager.resources.fluentcore.model.Indexable;
import com.azure.resourcemanager.resources.fluentcore.utils.SdkContext;
import com.azure.resourcemanager.resources.fluentcore.utils.Utils;
import reactor.core.Disposable;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Schedulers;

import java.io.IOException;
import java.io.InputStream;
import java.io.PipedInputStream;
Expand All @@ -82,10 +87,6 @@
import java.util.Set;
import java.util.TreeMap;
import java.util.stream.Collectors;
import reactor.core.Disposable;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Schedulers;

/**
* The implementation for WebAppBase.
Expand Down Expand Up @@ -893,7 +894,7 @@ Mono<SiteInner> submitSite(final SitePatchResourceInner siteUpdate) {
Mono<FluentT> submitHostNameBindings() {
final List<Mono<HostnameBinding>> bindingObservables = new ArrayList<>();
for (HostnameBindingImpl<FluentT, FluentImplT> binding : hostNameBindingsToCreate.values()) {
bindingObservables.add(Utils.<HostnameBinding>rootResource(binding.createAsync().last()));
bindingObservables.add(binding.createAsync());
}
for (String binding : hostNameBindingsToDelete) {
bindingObservables.add(deleteHostnameBinding(binding).then(Mono.empty()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public RoleAssignmentHelper withAccessTo(final String scope, final BuiltInRole a
.withBuiltInRole(asRole)
.withScope(resourceScope)
.createAsync()
.last()
.cast(Indexable.class)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why need a cast? Does it need Flux<Indexable>?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some are dependency or post dependency, some are in test for Flux

.onErrorResume(
throwable -> {
if (isRoleAssignmentExists(throwable)) {
Expand Down Expand Up @@ -147,7 +147,7 @@ public RoleAssignmentHelper withAccessTo(final String scope, final String roleDe
.withRoleDefinition(roleDefinitionId)
.withScope(resourceScope)
.createAsync()
.last()
.cast(Indexable.class)
.onErrorResume(
throwable -> {
if (isRoleAssignmentExists(throwable)) {
Expand Down
Loading