Search in sources :

Example 56 with Observable

use of rx.Observable in project azure-sdk-for-java by Azure.

the class RedisInner method regenerateKeyWithServiceResponseAsync.

/**
     * Regenerate Redis cache's access keys. This operation requires write permission to the cache resource.
     *
     * @param resourceGroupName The name of the resource group.
     * @param name The name of the Redis cache.
     * @param keyType The Redis access key to regenerate. Possible values include: 'Primary', 'Secondary'
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the RedisAccessKeysInner object
     */
public Observable<ServiceResponse<RedisAccessKeysInner>> regenerateKeyWithServiceResponseAsync(String resourceGroupName, String name, RedisKeyType keyType) {
    if (resourceGroupName == null) {
        throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.");
    }
    if (name == null) {
        throw new IllegalArgumentException("Parameter name is required and cannot be null.");
    }
    if (this.client.subscriptionId() == null) {
        throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.");
    }
    if (this.client.apiVersion() == null) {
        throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.");
    }
    if (keyType == null) {
        throw new IllegalArgumentException("Parameter keyType is required and cannot be null.");
    }
    RedisRegenerateKeyParameters parameters = new RedisRegenerateKeyParameters();
    parameters.withKeyType(keyType);
    return service.regenerateKey(resourceGroupName, name, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()).flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<RedisAccessKeysInner>>>() {

        @Override
        public Observable<ServiceResponse<RedisAccessKeysInner>> call(Response<ResponseBody> response) {
            try {
                ServiceResponse<RedisAccessKeysInner> clientResponse = regenerateKeyDelegate(response);
                return Observable.just(clientResponse);
            } catch (Throwable t) {
                return Observable.error(t);
            }
        }
    });
}
Also used : Response(retrofit2.Response) ServiceResponse(com.microsoft.rest.ServiceResponse) RedisRegenerateKeyParameters(com.microsoft.azure.management.redis.RedisRegenerateKeyParameters) ServiceResponse(com.microsoft.rest.ServiceResponse) Observable(rx.Observable) ResponseBody(okhttp3.ResponseBody)

Example 57 with Observable

use of rx.Observable in project azure-sdk-for-java by Azure.

the class VirtualNetworkGatewaysInner method generatevpnclientpackageWithServiceResponseAsync.

/**
     * Generates VPN client package for P2S client of the virtual network gateway in the specified resource group.
     *
     * @param resourceGroupName The name of the resource group.
     * @param virtualNetworkGatewayName The name of the virtual network gateway.
     * @param processorArchitecture VPN client Processor Architecture. Possible values are: 'AMD64' and 'X86'. Possible values include: 'Amd64', 'X86'
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the String object
     */
public Observable<ServiceResponse<String>> generatevpnclientpackageWithServiceResponseAsync(String resourceGroupName, String virtualNetworkGatewayName, ProcessorArchitecture processorArchitecture) {
    if (resourceGroupName == null) {
        throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.");
    }
    if (virtualNetworkGatewayName == null) {
        throw new IllegalArgumentException("Parameter virtualNetworkGatewayName is required and cannot be null.");
    }
    if (this.client.subscriptionId() == null) {
        throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.");
    }
    if (processorArchitecture == null) {
        throw new IllegalArgumentException("Parameter processorArchitecture is required and cannot be null.");
    }
    final String apiVersion = "2016-12-01";
    VpnClientParameters parameters = new VpnClientParameters();
    parameters.withProcessorArchitecture(processorArchitecture);
    return service.generatevpnclientpackage(resourceGroupName, virtualNetworkGatewayName, this.client.subscriptionId(), apiVersion, this.client.acceptLanguage(), parameters, this.client.userAgent()).flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<String>>>() {

        @Override
        public Observable<ServiceResponse<String>> call(Response<ResponseBody> response) {
            try {
                ServiceResponse<String> clientResponse = generatevpnclientpackageDelegate(response);
                return Observable.just(clientResponse);
            } catch (Throwable t) {
                return Observable.error(t);
            }
        }
    });
}
Also used : Response(retrofit2.Response) ServiceResponse(com.microsoft.rest.ServiceResponse) ServiceResponse(com.microsoft.rest.ServiceResponse) VpnClientParameters(com.microsoft.azure.management.network.VpnClientParameters) Observable(rx.Observable) ResponseBody(okhttp3.ResponseBody)

Example 58 with Observable

use of rx.Observable in project azure-sdk-for-java by Azure.

the class ExternalChildResourceCollectionImpl method commitAsync.

/**
     * Commits the changes in the external child resource childCollection.
     * <p/>
     * This method returns an observable stream, its observer's onNext will be called for each successfully
     * committed resource followed by one call to 'onCompleted' or one call to 'onError' with a
     * {@link CompositeException } containing the list of exceptions where each exception describes the reason
     * for failure of a resource commit.
     *
     * @return the observable stream
     */
public Observable<FluentModelTImpl> commitAsync() {
    final ExternalChildResourceCollectionImpl<FluentModelTImpl, FluentModelT, InnerModelT, ParentImplT, ParentT> self = this;
    List<FluentModelTImpl> items = new ArrayList<>();
    for (FluentModelTImpl item : this.childCollection.values()) {
        items.add(item);
    }
    final List<Throwable> exceptionsList = Collections.synchronizedList(new ArrayList<Throwable>());
    Observable<FluentModelTImpl> deleteStream = Observable.from(items).filter(new Func1<FluentModelTImpl, Boolean>() {

        @Override
        public Boolean call(FluentModelTImpl childResource) {
            return childResource.pendingOperation() == ExternalChildResourceImpl.PendingOperation.ToBeRemoved;
        }
    }).flatMap(new Func1<FluentModelTImpl, Observable<FluentModelTImpl>>() {

        @Override
        public Observable<FluentModelTImpl> call(final FluentModelTImpl childResource) {
            return childResource.deleteAsync().map(new Func1<Void, FluentModelTImpl>() {

                @Override
                public FluentModelTImpl call(Void response) {
                    return childResource;
                }
            }).doOnNext(new Action1<FluentModelTImpl>() {

                @Override
                public void call(FluentModelTImpl childResource) {
                    childResource.setPendingOperation(ExternalChildResourceImpl.PendingOperation.None);
                    self.childCollection.remove(childResource.name());
                }
            }).onErrorResumeNext(new Func1<Throwable, Observable<FluentModelTImpl>>() {

                @Override
                public Observable<FluentModelTImpl> call(Throwable throwable) {
                    exceptionsList.add(throwable);
                    return Observable.empty();
                }
            });
        }
    });
    Observable<FluentModelTImpl> createStream = Observable.from(items).filter(new Func1<FluentModelTImpl, Boolean>() {

        @Override
        public Boolean call(FluentModelTImpl childResource) {
            return childResource.pendingOperation() == ExternalChildResourceImpl.PendingOperation.ToBeCreated;
        }
    }).flatMap(new Func1<FluentModelTImpl, Observable<FluentModelTImpl>>() {

        @Override
        public Observable<FluentModelTImpl> call(final FluentModelTImpl childResource) {
            return childResource.createAsync().map(new Func1<FluentModelT, FluentModelTImpl>() {

                @Override
                public FluentModelTImpl call(FluentModelT fluentModelT) {
                    return childResource;
                }
            }).doOnNext(new Action1<FluentModelTImpl>() {

                @Override
                public void call(FluentModelTImpl fluentModelT) {
                    childResource.setPendingOperation(ExternalChildResourceImpl.PendingOperation.None);
                }
            }).onErrorResumeNext(new Func1<Throwable, Observable<? extends FluentModelTImpl>>() {

                @Override
                public Observable<FluentModelTImpl> call(Throwable throwable) {
                    self.childCollection.remove(childResource.name());
                    exceptionsList.add(throwable);
                    return Observable.empty();
                }
            });
        }
    });
    Observable<FluentModelTImpl> updateStream = Observable.from(items).filter(new Func1<FluentModelTImpl, Boolean>() {

        @Override
        public Boolean call(FluentModelTImpl childResource) {
            return childResource.pendingOperation() == ExternalChildResourceImpl.PendingOperation.ToBeUpdated;
        }
    }).flatMap(new Func1<FluentModelTImpl, Observable<FluentModelTImpl>>() {

        @Override
        public Observable<FluentModelTImpl> call(final FluentModelTImpl childResource) {
            return childResource.updateAsync().map(new Func1<FluentModelT, FluentModelTImpl>() {

                @Override
                public FluentModelTImpl call(FluentModelT e) {
                    return childResource;
                }
            }).doOnNext(new Action1<FluentModelTImpl>() {

                @Override
                public void call(FluentModelTImpl childResource) {
                    childResource.setPendingOperation(ExternalChildResourceImpl.PendingOperation.None);
                }
            }).onErrorResumeNext(new Func1<Throwable, Observable<? extends FluentModelTImpl>>() {

                @Override
                public Observable<FluentModelTImpl> call(Throwable throwable) {
                    exceptionsList.add(throwable);
                    return Observable.empty();
                }
            });
        }
    });
    final PublishSubject<FluentModelTImpl> aggregatedErrorStream = PublishSubject.create();
    Observable<FluentModelTImpl> operationsStream = Observable.merge(deleteStream, createStream, updateStream).doOnTerminate(new Action0() {

        @Override
        public void call() {
            if (clearAfterCommit()) {
                self.childCollection.clear();
            }
            if (exceptionsList.isEmpty()) {
                aggregatedErrorStream.onCompleted();
            } else {
                aggregatedErrorStream.onError(new CompositeException(exceptionsList));
            }
        }
    });
    Observable<FluentModelTImpl> stream = Observable.concat(operationsStream, aggregatedErrorStream);
    return stream;
}
Also used : Action0(rx.functions.Action0) CompositeException(rx.exceptions.CompositeException) ArrayList(java.util.ArrayList) Observable(rx.Observable) Func1(rx.functions.Func1)

Example 59 with Observable

use of rx.Observable in project azure-sdk-for-java by Azure.

the class NetworkWatchersInner method getTopologyWithServiceResponseAsync.

/**
     * Gets the current network topology by resource group.
     *
     * @param resourceGroupName The name of the resource group.
     * @param networkWatcherName The name of the network watcher.
     * @param targetResourceGroupName The name of the target resource group to perform topology on.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the TopologyInner object
     */
public Observable<ServiceResponse<TopologyInner>> getTopologyWithServiceResponseAsync(String resourceGroupName, String networkWatcherName, String targetResourceGroupName) {
    if (resourceGroupName == null) {
        throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.");
    }
    if (networkWatcherName == null) {
        throw new IllegalArgumentException("Parameter networkWatcherName is required and cannot be null.");
    }
    if (this.client.subscriptionId() == null) {
        throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.");
    }
    if (targetResourceGroupName == null) {
        throw new IllegalArgumentException("Parameter targetResourceGroupName is required and cannot be null.");
    }
    final String apiVersion = "2016-12-01";
    TopologyParameters parameters = new TopologyParameters();
    parameters.withTargetResourceGroupName(targetResourceGroupName);
    return service.getTopology(resourceGroupName, networkWatcherName, this.client.subscriptionId(), apiVersion, this.client.acceptLanguage(), parameters, this.client.userAgent()).flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<TopologyInner>>>() {

        @Override
        public Observable<ServiceResponse<TopologyInner>> call(Response<ResponseBody> response) {
            try {
                ServiceResponse<TopologyInner> clientResponse = getTopologyDelegate(response);
                return Observable.just(clientResponse);
            } catch (Throwable t) {
                return Observable.error(t);
            }
        }
    });
}
Also used : Response(retrofit2.Response) ServiceResponse(com.microsoft.rest.ServiceResponse) ServiceResponse(com.microsoft.rest.ServiceResponse) Observable(rx.Observable) TopologyParameters(com.microsoft.azure.management.network.TopologyParameters) ResponseBody(okhttp3.ResponseBody)

Example 60 with Observable

use of rx.Observable in project azure-sdk-for-java by Azure.

the class KeyVaultClientImpl method setCertificateIssuerWithServiceResponseAsync.

/**
     * Sets the specified certificate issuer.
     *
     * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net.
     * @param issuerName The name of the issuer.
     * @param provider The issuer provider.
     * @return the observable to the IssuerBundle object
     */
public Observable<ServiceResponse<IssuerBundle>> setCertificateIssuerWithServiceResponseAsync(String vaultBaseUrl, String issuerName, String provider) {
    if (vaultBaseUrl == null) {
        throw new IllegalArgumentException("Parameter vaultBaseUrl is required and cannot be null.");
    }
    if (issuerName == null) {
        throw new IllegalArgumentException("Parameter issuerName is required and cannot be null.");
    }
    if (this.apiVersion() == null) {
        throw new IllegalArgumentException("Parameter this.apiVersion() is required and cannot be null.");
    }
    if (provider == null) {
        throw new IllegalArgumentException("Parameter provider is required and cannot be null.");
    }
    final IssuerCredentials credentials = null;
    final OrganizationDetails organizationDetails = null;
    final IssuerAttributes attributes = null;
    CertificateIssuerSetParameters parameter = new CertificateIssuerSetParameters();
    parameter.withProvider(provider);
    parameter.withCredentials(null);
    parameter.withOrganizationDetails(null);
    parameter.withAttributes(null);
    String parameterizedHost = Joiner.on(", ").join("{vaultBaseUrl}", vaultBaseUrl);
    return service.setCertificateIssuer(issuerName, this.apiVersion(), this.acceptLanguage(), parameter, parameterizedHost, this.userAgent()).flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<IssuerBundle>>>() {

        @Override
        public Observable<ServiceResponse<IssuerBundle>> call(Response<ResponseBody> response) {
            try {
                ServiceResponse<IssuerBundle> clientResponse = setCertificateIssuerDelegate(response);
                return Observable.just(clientResponse);
            } catch (Throwable t) {
                return Observable.error(t);
            }
        }
    });
}
Also used : OrganizationDetails(com.microsoft.azure.keyvault.models.OrganizationDetails) IssuerAttributes(com.microsoft.azure.keyvault.models.IssuerAttributes) CertificateIssuerSetParameters(com.microsoft.azure.keyvault.models.CertificateIssuerSetParameters) Observable(rx.Observable) ResponseBody(okhttp3.ResponseBody) Response(retrofit2.Response) ServiceResponse(com.microsoft.rest.ServiceResponse) IssuerBundle(com.microsoft.azure.keyvault.models.IssuerBundle) ServiceResponse(com.microsoft.rest.ServiceResponse) IssuerCredentials(com.microsoft.azure.keyvault.models.IssuerCredentials)

Aggregations

Observable (rx.Observable)205 ResponseBody (okhttp3.ResponseBody)97 Response (retrofit2.Response)93 ServiceResponse (com.microsoft.rest.ServiceResponse)92 ArrayList (java.util.ArrayList)35 List (java.util.List)33 Test (org.junit.Test)29 Func1 (rx.functions.Func1)26 IOException (java.io.IOException)15 Subscription (rx.Subscription)15 Context (android.content.Context)14 Schedulers (rx.schedulers.Schedulers)13 ByteBuf (io.netty.buffer.ByteBuf)10 Intent (android.content.Intent)9 NonNull (android.support.annotation.NonNull)9 Collections (java.util.Collections)9 AndroidSchedulers (rx.android.schedulers.AndroidSchedulers)9 Action1 (rx.functions.Action1)9 SharedPreferences (android.content.SharedPreferences)8 Nullable (android.support.annotation.Nullable)8