Skip to content

Commit

Permalink
Merge pull request #1085 from anuchandy/dag-task-rework
Browse files Browse the repository at this point in the history
[Ready for review] Enable updateResourceAsync
  • Loading branch information
anuchandy authored Sep 22, 2016
2 parents 915af8b + 2c2a8d7 commit 243a323
Show file tree
Hide file tree
Showing 25 changed files with 391 additions and 351 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public BatchAccount call(BatchAccountInner batchAccountInner) {
}

@Override
public Observable<BatchAccount> applyUpdateAsync() {
public Observable<BatchAccount> updateResourceAsync() {
// TODO - ans - remove call to createResourceAsync and uncomment code below, after PATCH start sending the nulls.
return createResourceAsync();
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,7 @@ public AvailabilitySetImpl withFaultDomainCount(int faultDomainCount) {
return this;
}

@Override
public Observable<AvailabilitySet> applyUpdateAsync() {
return this.createResourceAsync();
}

// CreatorTaskGroup.ResourceCreator implementation
// CreateUpdateTaskGroup.ResourceCreator.createResourceAsync implementation

@Override
public Observable<AvailabilitySet> createResourceAsync() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,6 @@ public VirtualMachine refresh() {
return this;
}

@Override
public Observable<VirtualMachine> applyUpdateAsync() {
return this.createResourceAsync();
}

@Override
public void deallocate() {
this.client.deallocate(this.resourceGroupName(), this.name());
Expand Down Expand Up @@ -876,7 +871,7 @@ public PowerState powerState() {
return null;
}

// CreatorTaskGroup.ResourceCreator implementation
// CreateUpdateTaskGroup.ResourceCreator.createResourceAsync implementation
@Override
public Observable<VirtualMachine> createResourceAsync() {
if (isInCreateMode()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -837,16 +837,6 @@ protected void afterCreating() {
this.initializeChildrenFromInner();
}

@Override
public Observable<VirtualMachineScaleSet> applyAsync() {
return this.createAsync();
}

@Override
public Observable<VirtualMachineScaleSet> applyUpdateAsync() {
return this.createResourceAsync();
}

@Override
public VirtualMachineScaleSetImpl refresh() {
VirtualMachineScaleSetInner inner = this.client.get(this.resourceGroupName(), this.name());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public Observable<ServicePrincipal> createResourceAsync() {
}

@Override
public Observable<ServicePrincipal> applyAsync() {
throw new UnsupportedOperationException("not implemented yet");
public boolean isInCreateMode() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public Observable<User> createResourceAsync() {
}

@Override
public Observable<User> applyAsync() {
throw new UnsupportedOperationException("not implemented yet");
public boolean isInCreateMode() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,4 @@ public VaultImpl refresh() {
setInner(client.get(resourceGroupName(), name()));
return this;
}

@Override
public Observable<Vault> applyUpdateAsync() {
return createAsync();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,6 @@ public LoadBalancerImpl refresh() {
return this;
}

@Override
public Observable<LoadBalancer> applyUpdateAsync() {
return createResourceAsync();
}

// Helpers

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ public NetworkImpl refresh() {
return this;
}

@Override
public Observable<Network> applyUpdateAsync() {
return createResourceAsync();
}

// Helpers

NetworkImpl withSubnet(SubnetImpl subnet) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,6 @@ public NetworkInterface refresh() {
return this;
}

@Override
public Observable<NetworkInterface> applyUpdateAsync() {
return createResourceAsync();
}

// Setters (fluent)

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,6 @@ public NetworkSecurityGroupImpl refresh() {
return this;
}

@Override
public Observable<NetworkSecurityGroup> applyUpdateAsync() {
return createResourceAsync();
}

@Override
public List<Subnet> listAssociatedSubnets() {
final List<SubnetInner> subnetRefs = this.inner().subnets();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ class PublicIpAddressImpl

// Verbs

@Override
public Observable<PublicIpAddress> applyUpdateAsync() {
return this.createResourceAsync();
}

@Override
public PublicIpAddress refresh() {
PublicIPAddressInner response = this.client.get(this.resourceGroupName(), this.name());
Expand Down Expand Up @@ -149,7 +144,7 @@ public String leafDomainLabel() {
}
}

// CreatorTaskGroup.ResourceCreator implementation
// CreateUpdateTaskGroup.ResourceCreator implementation
@Override
public Observable<PublicIpAddress> createResourceAsync() {
// Clean up empty DNS settings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ public RedisCacheImpl update() {
}

@Override
public Observable<RedisCache> applyUpdateAsync() {
public Observable<RedisCache> updateResourceAsync() {
return client.updateAsync(resourceGroupName(), name(), updateParameters)
.map(innerToFluentMap(this))
.doOnNext(new Action1<RedisCache>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.microsoft.azure.management.resources.fluentcore.collection.SupportsBatchCreation;
import com.microsoft.azure.management.resources.fluentcore.model.Creatable;
import com.microsoft.azure.management.resources.fluentcore.model.CreatedResources;
import com.microsoft.azure.management.resources.fluentcore.model.implementation.CreatableImpl;
import com.microsoft.azure.management.resources.fluentcore.model.implementation.CreatableUpdatableImpl;
import com.microsoft.rest.ServiceCall;
import com.microsoft.rest.ServiceCallback;
import com.microsoft.rest.ServiceResponse;
Expand Down Expand Up @@ -51,28 +51,28 @@ public final CreatedResources<T> create(List<Creatable<T>> creatables) {
@Override
@SafeVarargs
public final Observable<CreatedResources<T>> createAsync(Creatable<T> ... creatables) {
CreatableResourcesRootImpl<T> rootResource = new CreatableResourcesRootImpl<>();
CreatableUpdatableResourcesRootImpl<T> rootResource = new CreatableUpdatableResourcesRootImpl<>();
rootResource.addCreatableDependencies(creatables);

return rootResource.createAsync()
.map(new Func1<CreatableResourcesRoot<T>, CreatedResources<T>>() {
.map(new Func1<CreatableUpdatableResourcesRoot<T>, CreatedResources<T>>() {
@Override
public CreatedResources<T> call(CreatableResourcesRoot<T> tCreatableResourcesRoot) {
return new CreatedResourcesImpl<T>(tCreatableResourcesRoot);
public CreatedResources<T> call(CreatableUpdatableResourcesRoot<T> tCreatableUpdatableResourcesRoot) {
return new CreatedResourcesImpl<T>(tCreatableUpdatableResourcesRoot);
}
});
}

@Override
public final Observable<CreatedResources<T>> createAsync(List<Creatable<T>> creatables) {
CreatableResourcesRootImpl<T> rootResource = new CreatableResourcesRootImpl<>();
CreatableUpdatableResourcesRootImpl<T> rootResource = new CreatableUpdatableResourcesRootImpl<>();
rootResource.addCreatableDependencies(creatables);

return rootResource.createAsync()
.map(new Func1<CreatableResourcesRoot<T>, CreatedResources<T>>() {
.map(new Func1<CreatableUpdatableResourcesRoot<T>, CreatedResources<T>>() {
@Override
public CreatedResources<T> call(CreatableResourcesRoot<T> tCreatableResourcesRoot) {
return new CreatedResourcesImpl<T>(tCreatableResourcesRoot);
public CreatedResources<T> call(CreatableUpdatableResourcesRoot<T> tCreatableUpdatableResourcesRoot) {
return new CreatedResourcesImpl<T>(tCreatableUpdatableResourcesRoot);
}
});
}
Expand Down Expand Up @@ -105,17 +105,17 @@ public ServiceResponse<CreatedResources<T>> call(CreatedResources<T> ts) {
* @param <ResourceT> the type of the resources in the batch.
*/
private class CreatedResourcesImpl<ResourceT extends Resource> implements CreatedResources<ResourceT> {
private CreatableResourcesRoot<ResourceT> creatableResourcesRoot;
private CreatableUpdatableResourcesRoot<ResourceT> creatableUpdatableResourcesRoot;
private final List<ResourceT> list;

CreatedResourcesImpl(CreatableResourcesRoot<ResourceT> creatableResourcesRoot) {
this.creatableResourcesRoot = creatableResourcesRoot;
this.list = this.creatableResourcesRoot.createdTopLevelResources();
CreatedResourcesImpl(CreatableUpdatableResourcesRoot<ResourceT> creatableUpdatableResourcesRoot) {
this.creatableUpdatableResourcesRoot = creatableUpdatableResourcesRoot;
this.list = this.creatableUpdatableResourcesRoot.createdTopLevelResources();
}

@Override
public Resource createdRelatedResource(String key) {
return this.creatableResourcesRoot.createdRelatedResource(key);
return this.creatableUpdatableResourcesRoot.createdRelatedResource(key);
}

@Override
Expand Down Expand Up @@ -240,41 +240,41 @@ public List<ResourceT> subList(int fromIndex, int toIndex) {
*
* @param <ResourceT> the type of the resources in the batch.
*/
interface CreatableResourcesRoot<ResourceT extends Resource> extends Resource {
interface CreatableUpdatableResourcesRoot<ResourceT extends Resource> extends Resource {
List<ResourceT> createdTopLevelResources();
Resource createdRelatedResource(String key);
}

/**
* Implementation of {@link CreatableResourcesRoot}.
* Implementation of {@link CreatableUpdatableResourcesRoot}.
*
* @param <ResourceT> the type of the resources in the batch.
*/
private class CreatableResourcesRootImpl<ResourceT extends Resource>
extends CreatableImpl<CreatableResourcesRoot<ResourceT>, Object, CreatableResourcesRootImpl<ResourceT>>
implements CreatableResourcesRoot<ResourceT> {
private class CreatableUpdatableResourcesRootImpl<ResourceT extends Resource>
extends CreatableUpdatableImpl<CreatableUpdatableResourcesRoot<ResourceT>, Object, CreatableUpdatableResourcesRootImpl<ResourceT>>
implements CreatableUpdatableResourcesRoot<ResourceT> {
/**
* Collection of keys of top level resources in this batch.
*/
private List<String> keys;

CreatableResourcesRootImpl() {
super("CreatableResourcesRoot", null);
CreatableUpdatableResourcesRootImpl() {
super("CreatableUpdatableResourcesRoot", null);
this.keys = new ArrayList<>();
}

@Override
public List<ResourceT> createdTopLevelResources() {
List<ResourceT> resources = new ArrayList<>();
for (String resourceKey : keys) {
resources.add((ResourceT) creatorTaskGroup().createdResource(resourceKey));
resources.add((ResourceT) creatorUpdatorTaskGroup().createdResource(resourceKey));
}
return Collections.unmodifiableList(resources);
}

@Override
public Resource createdRelatedResource(String key) {
return creatorTaskGroup().createdResource(key);
return creatorUpdatorTaskGroup().createdResource(key);
}

void addCreatableDependencies(Creatable<T> ... creatables) {
Expand All @@ -292,21 +292,26 @@ void addCreatableDependencies(List<Creatable<T>> creatables) {
}

@Override
public Observable<CreatableResourcesRoot<ResourceT>> createResourceAsync() {
return Observable.just((CreatableResourcesRoot<ResourceT>) this);
public Observable<CreatableUpdatableResourcesRoot<ResourceT>> createResourceAsync() {
return Observable.just((CreatableUpdatableResourcesRoot<ResourceT>) this);
}

@Override
public CreatableResourcesRoot<ResourceT> createResource() {
return this;
public Observable<CreatableUpdatableResourcesRoot<ResourceT>> updateResourceAsync() {
return createResourceAsync();
}

@Override
public boolean isInCreateMode() {
return true;
}

// Below overrides returns null as this is not a real resource in Azure
// but a dummy resource representing parent of a batch of creatable Azure
// resources.

@Override
public CreatableResourcesRoot<ResourceT> refresh() {
public CreatableUpdatableResourcesRoot<ResourceT> refresh() {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.microsoft.azure.management.resources.fluentcore.arm.models.Resource;
import com.microsoft.azure.management.resources.fluentcore.model.Wrapper;
import com.microsoft.azure.management.resources.fluentcore.model.implementation.CreatableUpdatableImpl;
import rx.Observable;

import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -39,7 +38,6 @@ public abstract class ResourceImpl<
Resource {
protected ResourceImpl(String name, InnerModelT innerObject) {
super(name, innerObject);
// Initialize tags
if (innerObject.getTags() == null) {
innerObject.withTags(new TreeMap<String, String>());
}
Expand Down Expand Up @@ -149,59 +147,29 @@ public final FluentModelImplT withRegion(Region region) {
return this.withRegion(region.toString());
}


@Override
public Observable<FluentModelT> applyAsync() {
if (super.creatorTaskGroup.isPreparer()) {
super.creatorTaskGroup.prepare();
return super.creatorTaskGroup.executeAsync().last();
}
throw new IllegalStateException("Internal Error: createAsync can be called only on preparer");
}

/**
* Execute the update request asynchronously.
*
* @return the handle to the REST call
*/
public abstract Observable<FluentModelT> applyUpdateAsync();

@Override
public Observable<FluentModelT> executeCreateOrUpdateAsync() {
if (this.isInCreateMode()) {
return createResourceAsync();
}
else {
return applyUpdateAsync();
}
}

/**
* @return <tt>true</tt> if currently in define..create mode
*/
@Override
public boolean isInCreateMode() {
return this.inner().id() == null;
}

protected <InnerT> List<InnerT> innersFromWrappers(
Collection<? extends Wrapper<InnerT>> wrappers) {
protected <InnerT> List<InnerT> innersFromWrappers(Collection<? extends Wrapper<InnerT>> wrappers) {
return innersFromWrappers(wrappers, null);
}

protected <InnerT> List<InnerT> innersFromWrappers(
Collection<? extends Wrapper<InnerT>> wrappers,
protected <InnerT> List<InnerT> innersFromWrappers(Collection<? extends Wrapper<InnerT>> wrappers,
List<InnerT> inners) {
if (wrappers == null || wrappers.size() == 0) {
return inners;
} else {
if (inners == null) {
inners = new ArrayList<>();
}

for (Wrapper<InnerT> wrapper : wrappers) {
inners.add(wrapper.inner());
}

return inners;
}
}
Expand Down
Loading

0 comments on commit 243a323

Please sign in to comment.