Skip to content

Commit

Permalink
Merge pull request #983 from anuchandy/parallel-create
Browse files Browse the repository at this point in the history
Fixing the issue of circular depedency due to the use of non-unique key
  • Loading branch information
jianghaolu authored Aug 2, 2016
2 parents 5de017b + 5d51ee6 commit c0b09ce
Show file tree
Hide file tree
Showing 29 changed files with 90 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class DataDiskImpl
VirtualMachineDataDisk.UpdateDefinition<VirtualMachine.Update>,
VirtualMachineDataDisk.Update {

protected DataDiskImpl(String name, DataDisk inner, VirtualMachineImpl parent) {
super(name, inner, parent);
protected DataDiskImpl(DataDisk inner, VirtualMachineImpl parent) {
super(inner, parent);
}

protected static DataDiskImpl prepareDataDisk(String name, DiskCreateOptionTypes createOption, VirtualMachineImpl parent) {
Expand All @@ -34,7 +34,7 @@ protected static DataDiskImpl prepareDataDisk(String name, DiskCreateOptionTypes
dataDiskInner.withName(name);
dataDiskInner.withCreateOption(createOption);
dataDiskInner.withVhd(null);
return new DataDiskImpl(name, dataDiskInner, parent);
return new DataDiskImpl(dataDiskInner, parent);
}

protected static DataDiskImpl createNewDataDisk(int sizeInGB, VirtualMachineImpl parent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class VirtualMachineImageImpl
private ImageReference imageReference;

VirtualMachineImageImpl(Region location, String publisher, String offer, String sku, String version) {
super(null, null);
super(null);
this.location = location;
this.imageReference = new ImageReference();
this.imageReference.withPublisher(publisher);
Expand All @@ -30,7 +30,7 @@ class VirtualMachineImageImpl
}

VirtualMachineImageImpl(Region location, String publisher, String offer, String sku, String version, VirtualMachineImageInner innerModel) {
super(innerModel.id(), innerModel);
super(innerModel);
this.location = location;
this.imageReference = new ImageReference();
this.imageReference.withPublisher(publisher);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,7 @@ private void initializeDataDisks() {
}
this.dataDisks = new ArrayList<>();
for (DataDisk dataDiskInner : this.storageProfile().dataDisks()) {
this.dataDisks().add(new DataDiskImpl(dataDiskInner.name(), dataDiskInner, this));
this.dataDisks().add(new DataDiskImpl(dataDiskInner, this));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class NetworkImpl
private void initializeSubnetsFromInner() {
this.subnets = new TreeMap<>();
for (SubnetInner subnetInner : this.inner().subnets()) {
SubnetImpl subnet = new SubnetImpl(subnetInner.name(), subnetInner, this);
SubnetImpl subnet = new SubnetImpl(subnetInner, this);
this.subnets.put(subnetInner.name(), subnet);
}
}
Expand Down Expand Up @@ -139,7 +139,7 @@ public NetworkImpl withAddressSpace(String cidr) {
public SubnetImpl defineSubnet(String name) {
SubnetInner inner = new SubnetInner();
inner.withName(name);
return new SubnetImpl(name, inner, this);
return new SubnetImpl(inner, this);
}

// Getters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,7 @@ private void initializeNicIpConfigurations() {

this.nicIpConfigurations = new ArrayList<>();
for (NetworkInterfaceIPConfigurationInner ipConfig : this.inner().ipConfigurations()) {
NicIpConfigurationImpl nicIpConfiguration = new NicIpConfigurationImpl(ipConfig.name(),
ipConfig,
NicIpConfigurationImpl nicIpConfiguration = new NicIpConfigurationImpl(ipConfig,
this,
super.myManager,
false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ private void initializeRulesFromInner() {
this.rules = new ArrayList<>();
if (this.inner().securityRules() != null) {
for (SecurityRuleInner ruleInner : this.inner().securityRules()) {
this.rules.add(new NetworkSecurityRuleImpl(ruleInner.name(), ruleInner, this));
this.rules.add(new NetworkSecurityRuleImpl(ruleInner, this));
}
}

this.defaultRules = new ArrayList<>();
if (this.inner().defaultSecurityRules() != null) {
for (SecurityRuleInner ruleInner : this.inner().defaultSecurityRules()) {
this.defaultRules.add(new NetworkSecurityRuleImpl(ruleInner.name(), ruleInner, this));
this.defaultRules.add(new NetworkSecurityRuleImpl(ruleInner, this));
}
}
}
Expand All @@ -78,7 +78,7 @@ public NetworkSecurityRuleImpl defineRule(String name) {
SecurityRuleInner inner = new SecurityRuleInner();
inner.withName(name);
inner.withPriority(100); // Must be at least 100
return new NetworkSecurityRuleImpl(name, inner, this);
return new NetworkSecurityRuleImpl(inner, this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class NetworkSecurityRuleImpl
NetworkSecurityRule.UpdateDefinition<NetworkSecurityGroup.Update>,
NetworkSecurityRule.Update {

protected NetworkSecurityRuleImpl(String name, SecurityRuleInner inner, NetworkSecurityGroupImpl parent) {
super(name, inner, parent);
protected NetworkSecurityRuleImpl(SecurityRuleInner inner, NetworkSecurityGroupImpl parent) {
super(inner, parent);
}

// Getters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,11 @@ class NicIpConfigurationImpl
// Reference to an existing load balancer whose back end pool is to be associated with this IP config
private LoadBalancer loadBalancerToAssociate;

protected NicIpConfigurationImpl(String name,
NetworkInterfaceIPConfigurationInner inner,
protected NicIpConfigurationImpl(NetworkInterfaceIPConfigurationInner inner,
NetworkInterfaceImpl parent,
NetworkManager networkManager,
final boolean isInCreateModel) {
super(name, inner, parent);
super(inner, parent);
this.isInCreateMode = isInCreateModel;
this.networkManager = networkManager;
}
Expand All @@ -69,8 +68,7 @@ protected static NicIpConfigurationImpl prepareNicIpConfiguration(String name,
final NetworkManager networkManager) {
NetworkInterfaceIPConfigurationInner ipConfigurationInner = new NetworkInterfaceIPConfigurationInner();
ipConfigurationInner.withName(name);
return new NicIpConfigurationImpl(name,
ipConfigurationInner,
return new NicIpConfigurationImpl(ipConfigurationInner,
parent,
networkManager,
true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class SubnetImpl
Subnet.UpdateDefinition<Network.Update>,
Subnet.Update {

protected SubnetImpl(String name, SubnetInner inner, NetworkImpl parent) {
super(name, inner, parent);
protected SubnetImpl(SubnetInner inner, NetworkImpl parent) {
super(inner, parent);
}

// Getters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ public abstract class ChildResourceImpl<InnerT, ParentImplT>

private final ParentImplT parent;

protected ChildResourceImpl(String name,
InnerT innerObject,
ParentImplT parent) {
super(name, innerObject);
protected ChildResourceImpl(InnerT innerObject, ParentImplT parent) {
super(innerObject);
this.parent = parent;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ public abstract class GroupableResourceImpl<
private String groupName;

protected GroupableResourceImpl(
String key,
String name,
InnerModelT innerObject,
ManagerT manager) {
super(key, innerObject);
super(name, innerObject);
this.myManager = manager;
}

Expand Down Expand Up @@ -91,7 +91,7 @@ public final FluentModelImplT withNewResourceGroup() {
*/
@SuppressWarnings("unchecked")
public final FluentModelImplT withNewResourceGroup(Creatable<ResourceGroup> creatable) {
this.groupName = creatable.key();
this.groupName = creatable.name();
this.creatableGroup = creatable;
addCreatableDependency(creatable);
return (FluentModelImplT) this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,8 @@ public abstract class ResourceImpl<
CreatableUpdatableImpl<FluentModelT, InnerModelT, FluentModelImplT, Resource>
implements
Resource {


protected ResourceImpl(String key, InnerModelT innerObject) {
super(key, innerObject);

protected ResourceImpl(String name, InnerModelT innerObject) {
super(name, innerObject);
// Initialize tags
if (innerObject.getTags() == null) {
innerObject.withTags(new TreeMap<String, String>());
Expand All @@ -61,7 +58,7 @@ public Region region() {
public Map<String, String> tags() {
Map<String, String> tags = this.inner().getTags();
if (tags == null) {
tags = new TreeMap<String, String>();
tags = new TreeMap<>();
}
return Collections.unmodifiableMap(tags);
}
Expand All @@ -79,7 +76,7 @@ public String type() {
@Override
public String name() {
if (this.inner().name() == null) {
return this.key(); // Not yet created, so use the key
return super.name();
} else {
return this.inner().name();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
* @param <T> the fluent type of the resource to be created
*/
public interface Creatable<T> extends Indexable {
/**
* @return the name of the creatable resource.
*/
String name();

/**
* Execute the create request.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,20 @@
public abstract class CreatableImpl<FluentModelT extends ResourceT, InnerModelT, FluentModelImplT, ResourceT>
extends IndexableRefreshableWrapperImpl<FluentModelT, InnerModelT>
implements CreatorTaskGroup.ResourceCreator<ResourceT> {
/**
* The name of the creatable resource.
*/
private String name;

/**
* The group of tasks to create this resource and it's dependencies.
*/
private CreatorTaskGroup<ResourceT> creatorTaskGroup;

protected CreatableImpl(String name, InnerModelT innerObject) {
super(name, innerObject);
creatorTaskGroup = new CreatorTaskGroup<>(name, this);
super(innerObject);
this.name = name;
creatorTaskGroup = new CreatorTaskGroup<>(this.key(), this);
}

/**
Expand All @@ -44,7 +49,14 @@ protected void addCreatableDependency(Creatable<? extends ResourceT> creatableRe
}

protected ResourceT createdResource(String key) {
return this.creatorTaskGroup.taskResult(key);
return this.creatorTaskGroup.createdResource(key);
}

/**
* @return the name of the creatable resource.
*/
public String name() {
return this.name;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
* @param <ResourceT> the type of the resource this group creates
*/
public class CreatorTaskGroup<ResourceT> extends TaskGroupBase<ResourceT> {
public class CreatorTaskGroup<ResourceT> extends TaskGroupBase<ResourceT, CreatorTaskItem<ResourceT>> {
/**
* Represents a type that know how to create resource.
*
Expand Down Expand Up @@ -41,11 +41,11 @@ interface ResourceCreator<T> {
/**
* Creates CreatorTaskGroup.
*
* @param rootCreatableId the id of the root creatable
* @param key the key of the root task
* @param resourceCreator represents the resource creator that this group want to create ultimately
*/
public CreatorTaskGroup(String rootCreatableId, ResourceCreator<ResourceT> resourceCreator) {
this(rootCreatableId, new CreatorTaskItem<>(resourceCreator));
public CreatorTaskGroup(String key, ResourceCreator<ResourceT> resourceCreator) {
this(key, new CreatorTaskItem<>(resourceCreator));
}

/**
Expand All @@ -62,9 +62,9 @@ public CreatorTaskGroup(String key, CreatorTaskItem<ResourceT> rootTask) {
* Gets a resource created by a creator task in this group.
* <p>
* This method can return null if the resource has not yet created that happens if the responsible task
* is not yet selected for execution or it's it progress
* is not yet selected for execution or it's it progress or provided key is invalid.
*
* @param key the resource id
* @param key the resource key
* @return the created resource
*/
public ResourceT createdResource(String key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,16 @@

import com.microsoft.azure.management.resources.fluentcore.model.Indexable;

import java.util.UUID;

/**
* The base implementation for {@link Indexable}.
*/
public abstract class IndexableImpl implements Indexable {
protected String key;

protected IndexableImpl(String key) {
this.key = key;
}

/**
* Set the indexing key.
*
* @param key the indexing key
*/
public void setKey(String key) {
this.key = key;
protected IndexableImpl() {
this.key = UUID.randomUUID().toString();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ public abstract class IndexableRefreshableImpl<T>
extends IndexableImpl
implements Refreshable<T> {

protected IndexableRefreshableImpl(String name) {
super(name);
protected IndexableRefreshableImpl() {
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public abstract class IndexableRefreshableWrapperImpl<FluentModelT, InnerModelT>
implements Wrapper<InnerModelT> {

private InnerModelT innerObject;
protected IndexableRefreshableWrapperImpl(String name, InnerModelT innerObject) {
super(name);
protected IndexableRefreshableWrapperImpl(InnerModelT innerObject) {
this.innerObject = innerObject;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public abstract class IndexableWrapperImpl<InnerT>
extends IndexableImpl
implements Wrapper<InnerT> {
private InnerT innerObject;
protected IndexableWrapperImpl(String name, InnerT innerObject) {
super(name);
protected IndexableWrapperImpl(InnerT innerObject) {
super();
this.innerObject = innerObject;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public DeploymentImpl withNewResourceGroup(String resourceGroupName, Region regi

@Override
public DeploymentImpl withNewResourceGroup(Creatable<ResourceGroup> resourceGroupDefinition) {
this.resourceGroupName = resourceGroupDefinition.key();
this.resourceGroupName = resourceGroupDefinition.name();
this.creatableResourceGroup = resourceGroupDefinition;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class DeploymentOperationImpl extends
private final DeploymentOperationsInner client;

DeploymentOperationImpl(DeploymentOperationInner innerModel, final DeploymentOperationsInner client) {
super(innerModel.id(), innerModel);
super(innerModel);
this.client = client;
this.resourceGroupName = ResourceUtils.groupFromResourceId(innerModel.id());
this.deploymentName = ResourceUtils.extractFromResourceId(innerModel.id(), "deployments");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class FeatureImpl extends
Feature {

FeatureImpl(FeatureResultInner innerModel) {
super(innerModel.id(), innerModel);
super(innerModel);
}

@Override
Expand Down
Loading

0 comments on commit c0b09ce

Please sign in to comment.