Skip to content

Commit

Permalink
Squashed 'runtimes/' changes from 3010c5c..64c3003
Browse files Browse the repository at this point in the history
64c3003 Merge pull request Azure#54 from Azure/sdk_1045
a29b72b Merge pull request Azure#53 from Azure/sdk_1060
524db4a Merge pull request Azure#42 from Azure/sdk_1008
ffab45d Merge pull request Azure#1060 from jianghaolu/unwrap
626b093 Merge ad3a89b into cc5fdb3
9be12ef Fix errors from merge
9732907 Merge commit '14c789805ffe68c1ced5dbe0f71448095216fcc1' into unwrap
0a85d84 applyAsync on a root resource should create a dependency resource only if it is not already created and root resource always needs to be updated in this case
65a9fd6 Merge f8a29d6 into ae00855
3c266c4 Add graph tests

git-subtree-dir: runtimes
git-subtree-split: 64c3003
  • Loading branch information
jianghaolu committed Sep 23, 2016
1 parent 14c7898 commit 122f582
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
* Token based credentials for use with a REST Service Client.
*/
public class ApplicationTokenCredentials extends TokenCredentials {
/** The endpoint of the target resource. */
private String resourceEndpoint;
/** The active directory application client id. */
private String clientId;
/** The tenant or domain the containing the application. */
Expand Down Expand Up @@ -56,6 +58,30 @@ public ApplicationTokenCredentials(String clientId, String domain, String secret
} else {
this.environment = environment;
}
this.resourceEndpoint = this.environment.getTokenAudience();
}

/**
* Initializes a new instance of the UserTokenCredentials.
*
* @param clientId the active directory application client id.
* @param domain the domain or tenant id containing this application.
* @param secret the authentication secret for the application.
* @param resourceEndpoint the endpoint of the target resource.
* @param environment the Azure environment to authenticate with.
* If null is provided, AzureEnvironment.AZURE will be used.
*/
public ApplicationTokenCredentials(String clientId, String domain, String secret, String resourceEndpoint, AzureEnvironment environment) {
super(null, null); // defer token acquisition
this.clientId = clientId;
this.domain = domain;
this.secret = secret;
this.resourceEndpoint = resourceEndpoint;
if (environment == null) {
this.environment = AzureEnvironment.AZURE;
} else {
this.environment = environment;
}
}

/**
Expand Down Expand Up @@ -212,7 +238,7 @@ private void acquireAccessToken() throws IOException {
AuthenticationContext context = new AuthenticationContext(authorityUrl, this.getEnvironment().isValidateAuthority(), executor);
try {
authenticationResult = context.acquireToken(
this.getEnvironment().getTokenAudience(),
this.resourceEndpoint,
new ClientCredential(this.getClientId(), this.getSecret()),
null).get();
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
* Token based credentials for use with a REST Service Client.
*/
public class UserTokenCredentials extends TokenCredentials {
/** The endpoint of the target resource. */
private String resourceEndpoint;
/** The Active Directory application client id. */
private String clientId;
/** The domain or tenant id containing this application. */
Expand Down Expand Up @@ -59,6 +61,34 @@ public UserTokenCredentials(String clientId, String domain, String username, Str
} else {
this.environment = environment;
}
this.resourceEndpoint = this.environment.getTokenAudience();
}

/**
* Initializes a new instance of the UserTokenCredentials.
*
* @param clientId the active directory application client id.
* @param domain the domain or tenant id containing this application.
* @param username the user name for the Organization Id account.
* @param password the password for the Organization Id account.
* @param clientRedirectUri the Uri where the user will be redirected after authenticating with AD.
* @param resourceEndpoint the endpoint of the target resource.
* @param environment the Azure environment to authenticate with.
* If null is provided, AzureEnvironment.AZURE will be used.
*/
public UserTokenCredentials(String clientId, String domain, String username, String password, String clientRedirectUri, String resourceEndpoint, AzureEnvironment environment) {
super(null, null); // defer token acquisition
this.clientId = clientId;
this.domain = domain;
this.username = username;
this.password = password;
this.clientRedirectUri = clientRedirectUri;
this.resourceEndpoint = resourceEndpoint;
if (environment == null) {
this.environment = AzureEnvironment.AZURE;
} else {
this.environment = environment;
}
}

/**
Expand Down Expand Up @@ -136,7 +166,7 @@ private void acquireAccessToken() throws IOException {
AuthenticationContext context = new AuthenticationContext(authorityUrl, this.getEnvironment().isValidateAuthority(), Executors.newSingleThreadExecutor());
try {
authenticationResult = context.acquireToken(
this.getEnvironment().getTokenAudience(),
this.resourceEndpoint,
this.getClientId(),
this.getUsername(),
this.getPassword(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public AzureEnvironment(
* Provides the settings for authentication with Azure.
*/
public static final AzureEnvironment AZURE = new AzureEnvironment(
"https://login.windows.net/",
"https://login.microsoftonline.com/",
"https://management.core.windows.net/",
true,
"https://management.azure.com/");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
import com.microsoft.rest.ServiceCall;
import com.microsoft.rest.ServiceResponse;
import com.microsoft.rest.ServiceResponseWithHeaders;

import java.util.List;

import rx.Observable;
import rx.Subscriber;
import rx.functions.Func1;

import java.util.List;

/**
* An instance of this class provides access to the underlying REST call invocation.
* This class wraps around the Retrofit Call object and allows updates to it in the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,31 @@ public Observable<T> executeAsync() {
final List<Observable<T>> observables = new ArrayList<>();
while (nextNode != null) {
final DAGNode<U> thisNode = nextNode;
observables.add(nextNode.data().executeAsync()
.flatMap(new Func1<T, Observable<T>>() {
@Override
public Observable<T> call(T t) {
dag().reportedCompleted(thisNode);
if (dag().isRootNode(thisNode)) {
return Observable.just(t);
} else {
T cachedResult = nextNode.data().result();
if (cachedResult != null && !this.dag().isRootNode(nextNode)) {
observables.add(Observable.just(cachedResult)
.flatMap(new Func1<T, Observable<T>>() {
@Override
public Observable<T> call(T t) {
dag().reportedCompleted(thisNode);
return executeAsync();
}
}
}));
})
);
} else {
observables.add(nextNode.data().executeAsync()
.flatMap(new Func1<T, Observable<T>>() {
@Override
public Observable<T> call(T t) {
dag().reportedCompleted(thisNode);
if (dag().isRootNode(thisNode)) {
return Observable.just(t);
} else {
return executeAsync();
}
}
}));
}
nextNode = dag.getNext();
}
return Observable.merge(observables);
Expand Down
12 changes: 11 additions & 1 deletion client-runtime/src/main/java/com/microsoft/rest/ServiceCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
package com.microsoft.rest;

import com.google.common.util.concurrent.AbstractFuture;

import rx.Observable;
import rx.Subscription;
import rx.functions.Action1;
Expand Down Expand Up @@ -130,6 +129,17 @@ protected void setSubscription(Subscription subscription) {
this.subscription = subscription;
}

/**
* Invoke this method to report completed, allowing
* {@link AbstractFuture#get()} to be unblocked.
*
* @param result the service response returned.
* @return true if successfully reported; false otherwise.
*/
public boolean success(T result) {
return set(result);
}

@Override
public boolean cancel(boolean mayInterruptIfRunning) {
subscription.unsubscribe();
Expand Down

0 comments on commit 122f582

Please sign in to comment.