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

Enable parallel resource creation #973

Merged
merged 16 commits into from
Jul 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import com.microsoft.azure.SubResource;
import com.microsoft.azure.management.compute.AvailabilitySet;
import com.microsoft.azure.management.compute.InstanceViewStatus;
import com.microsoft.azure.management.resources.fluentcore.arm.models.Resource;
import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.GroupableResourceImpl;
import com.microsoft.azure.management.resources.fluentcore.utils.Utils;
import com.microsoft.rest.ServiceCall;
import com.microsoft.rest.ServiceCallback;
import com.microsoft.rest.ServiceResponse;
Expand Down Expand Up @@ -101,28 +101,32 @@ public ServiceCall applyAsync(ServiceCallback<AvailabilitySet> callback) {
return this.createAsync(callback);
}

// CreatorTaskGroup.ResourceCreator implementation

@Override
protected void createResource() throws Exception {
public Resource createResource() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense to change void to Resource but why public?

Copy link
Member Author

@anuchandy anuchandy Jul 25, 2016

Choose a reason for hiding this comment

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

we are trying to simplfy the logic we had earlier by removing two PUBLIC methods createRootResource and createRootResourceAsync exposed in every resource (via CreatableImpl inheritance). These two PUBLIC methods wraps calls to PROTECTED createResource and createResourceAsync methods. Removing createRoot* methods caused making the methods its wraps to public.

Copy link
Member Author

Choose a reason for hiding this comment

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

Btw I tried to explain the changes in this PR in the PR description, i can expand the description if anything is unclear.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it

ServiceResponse<AvailabilitySetInner> response = this.client.createOrUpdate(this.resourceGroupName(), this.name(), this.inner());
AvailabilitySetInner availabilitySetInner = response.getBody();
this.setInner(availabilitySetInner);
this.setInner(response.getBody());
this.idOfVMsInSet = null;
return this;
}

@Override
protected ServiceCall createResourceAsync(final ServiceCallback<Void> callback) {
public ServiceCall createResourceAsync(final ServiceCallback<Resource> callback) {
final AvailabilitySetImpl self = this;
return this.client.createOrUpdateAsync(this.resourceGroupName(), this.name(), this.inner(),
Utils.fromVoidCallback(this, new ServiceCallback<Void>() {
new ServiceCallback<AvailabilitySetInner>() {
@Override
public void failure(Throwable t) {
callback.failure(t);
}

@Override
public void success(ServiceResponse<Void> result) {
public void success(ServiceResponse<AvailabilitySetInner> response) {
self.setInner(response.getBody());
idOfVMsInSet = null;
callback.success(result);
callback.success(new ServiceResponse<Resource>(self, response.getResponse()));
}
}));
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@
import com.microsoft.azure.management.network.PublicIpAddress;
import com.microsoft.azure.management.network.implementation.NetworkManager;
import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils;
import com.microsoft.azure.management.resources.fluentcore.arm.models.Resource;
import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.GroupableResourceImpl;
import com.microsoft.azure.management.resources.fluentcore.model.Creatable;
import com.microsoft.azure.management.resources.fluentcore.utils.PagedListConverter;
import com.microsoft.azure.management.resources.fluentcore.utils.ResourceNamer;
import com.microsoft.azure.management.resources.fluentcore.utils.Utils;
import com.microsoft.azure.management.resources.implementation.PageImpl;
import com.microsoft.azure.management.storage.StorageAccount;
import com.microsoft.azure.management.storage.implementation.StorageManager;
Expand Down Expand Up @@ -853,13 +853,11 @@ public PowerState powerState() {
return null;
}

/**************************************************
* .
* CreatableImpl::createResource
**************************************************/

// CreatorTaskGroup.ResourceCreator implementation

@Override
protected void createResource() throws Exception {
public Resource createResource() throws Exception {
if (isInCreateMode()) {
setOSDiskAndOSProfileDefaults();
setHardwareProfileDefaults();
Expand All @@ -874,10 +872,11 @@ protected void createResource() throws Exception {
this.setInner(serviceResponse.getBody());
clearCachedRelatedResources();
initializeDataDisks();
return this;
}

@Override
protected ServiceCall createResourceAsync(final ServiceCallback<Void> callback) {
public ServiceCall createResourceAsync(final ServiceCallback<Resource> callback) {
if (isInCreateMode()) {
setOSDiskAndOSProfileDefaults();
setHardwareProfileDefaults();
Expand All @@ -896,19 +895,20 @@ public void success(ServiceResponse<Void> result) {
handleNetworkSettings();
handleAvailabilitySettings();
call.newCall(client.createOrUpdateAsync(resourceGroupName(), vmName, inner(),
Utils.fromVoidCallback(self, new ServiceCallback<Void>() {
new ServiceCallback<VirtualMachineInner>() {
@Override
public void failure(Throwable t) {
callback.failure(t);
}

@Override
public void success(ServiceResponse<Void> result) {
public void success(ServiceResponse<VirtualMachineInner> response) {
self.setInner(response.getBody());
clearCachedRelatedResources();
initializeDataDisks();
callback.success(result);
callback.success(new ServiceResponse<Resource>(self, response.getResponse()));
}
})).getCall());
}).getCall());
}
});
return call;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
import com.microsoft.azure.management.network.PublicIpAddress;
import com.microsoft.azure.management.network.PublicIpAddress.DefinitionStages.WithGroup;
import com.microsoft.azure.management.network.SupportsNetworkInterfaces;
import com.microsoft.azure.management.resources.fluentcore.arm.models.Resource;
import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.GroupableResourceImpl;
import com.microsoft.azure.management.resources.fluentcore.model.Creatable;
import com.microsoft.azure.management.resources.fluentcore.utils.Utils;
import com.microsoft.rest.ServiceCall;
import com.microsoft.rest.ServiceCallback;
import com.microsoft.rest.ServiceResponse;
Expand Down Expand Up @@ -201,48 +201,51 @@ public LoadBalancerImpl withExistingVirtualMachines(SupportsNetworkInterfaces...
// Getters

@Override
protected void createResource() throws Exception {
public List<String> publicIpAddressIds() {
List<String> publicIpAddressIds = new ArrayList<>();
if (this.inner().frontendIPConfigurations() != null) {
for (FrontendIPConfigurationInner frontEndIpConfig : this.inner().frontendIPConfigurations()) {
publicIpAddressIds.add(frontEndIpConfig.publicIPAddress().id());
}
}
return Collections.unmodifiableList(publicIpAddressIds);
}

// CreatorTaskGroup.ResourceCreator implementation

@Override
public Resource createResource() throws Exception {
ensureCreationPrerequisites();

ServiceResponse<LoadBalancerInner> response =
this.innerCollection.createOrUpdate(this.resourceGroupName(), this.name(), this.inner());
this.setInner(response.getBody());

runPostCreationTasks();
return this;
}

@Override
protected ServiceCall createResourceAsync(final ServiceCallback<Void> callback) {
public ServiceCall createResourceAsync(final ServiceCallback<Resource> callback) {
final LoadBalancerImpl self = this;
ensureCreationPrerequisites();
return this.innerCollection.createOrUpdateAsync(this.resourceGroupName(), this.name(), this.inner(),
Utils.fromVoidCallback(this, new ServiceCallback<Void>() {
new ServiceCallback<LoadBalancerInner>() {
@Override
public void failure(Throwable t) {
callback.failure(t);
}

@Override
public void success(ServiceResponse<Void> result) {
callback.success(result);
public void success(ServiceResponse<LoadBalancerInner> response) {
self.setInner(response.getBody());
callback.success(new ServiceResponse<Resource>(self, response.getResponse()));
try {
runPostCreationTasks();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}));
});
}

@Override
public List<String> publicIpAddressIds() {
List<String> publicIpAddressIds = new ArrayList<>();
if (this.inner().frontendIPConfigurations() != null) {
for (FrontendIPConfigurationInner frontEndIpConfig : this.inner().frontendIPConfigurations()) {
publicIpAddressIds.add(frontEndIpConfig.publicIPAddress().id());
}
}
return Collections.unmodifiableList(publicIpAddressIds);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@

import com.microsoft.azure.management.network.Network;
import com.microsoft.azure.management.network.Subnet;
import com.microsoft.azure.management.resources.fluentcore.arm.models.Resource;
import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.GroupableResourceImpl;
import com.microsoft.azure.management.resources.fluentcore.utils.Utils;
import com.microsoft.rest.ServiceCall;
import com.microsoft.rest.ServiceCallback;
import com.microsoft.rest.ServiceResponse;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -175,36 +174,40 @@ private void ensureCreationPrerequisites() {
}

@Override
protected void createResource() throws Exception {
public SubnetImpl updateSubnet(String name) {
return (SubnetImpl) this.subnets.get(name);
}

// CreatorTaskGroup.ResourceCreator implementation

@Override
public Resource createResource() throws Exception {
ensureCreationPrerequisites();

ServiceResponse<VirtualNetworkInner> response =
this.innerCollection.createOrUpdate(this.resourceGroupName(), this.name(), this.inner());
this.setInner(response.getBody());
initializeSubnetsFromInner();
return this;
}

@Override
protected ServiceCall createResourceAsync(final ServiceCallback<Void> callback) {
public ServiceCall createResourceAsync(final ServiceCallback<Resource> callback) {
final NetworkImpl self = this;
ensureCreationPrerequisites();

return this.innerCollection.createOrUpdateAsync(this.resourceGroupName(), this.name(), this.inner(),
Utils.fromVoidCallback(this, new ServiceCallback<Void>() {
new ServiceCallback<VirtualNetworkInner>() {
@Override
public void failure(Throwable t) {
callback.failure(t);
}

@Override
public void success(ServiceResponse<Void> result) {
public void success(ServiceResponse<VirtualNetworkInner> response) {
self.setInner(response.getBody());
initializeSubnetsFromInner();
callback.success(result);
callback.success(new ServiceResponse<Resource>(self, response.getResponse()));
}
}));
}

@Override
public SubnetImpl updateSubnet(String name) {
return (SubnetImpl) this.subnets.get(name);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,10 @@ public NicIpConfigurationImpl primaryIpConfiguration() {
}


/**************************************************.
* CreatableImpl::createResource
**************************************************/
// CreatorTaskGroup.ResourceCreator implementation

@Override
protected void createResource() throws Exception {
public Resource createResource() throws Exception {
NetworkSecurityGroup networkSecurityGroup = null;
if (creatableNetworkSecurityGroupKey != null) {
networkSecurityGroup = (NetworkSecurityGroup) this.createdResource(creatableNetworkSecurityGroupKey);
Expand All @@ -371,27 +369,30 @@ protected void createResource() throws Exception {
this.setInner(response.getBody());
clearCachedRelatedResources();
initializeNicIpConfigurations();
return this;
}

@Override
protected ServiceCall createResourceAsync(final ServiceCallback<Void> callback) {
public ServiceCall createResourceAsync(final ServiceCallback<Resource> callback) {
final NetworkInterfaceImpl self = this;
NicIpConfigurationImpl.ensureConfigurations(this.nicIpConfigurations);
return this.client.createOrUpdateAsync(this.resourceGroupName(),
this.nicName,
this.inner(),
Utils.fromVoidCallback(this, new ServiceCallback<Void>() {
new ServiceCallback<NetworkInterfaceInner>() {
@Override
public void failure(Throwable t) {
callback.failure(t);
}

@Override
public void success(ServiceResponse<Void> result) {
public void success(ServiceResponse<NetworkInterfaceInner> response) {
self.setInner(response.getBody());
clearCachedRelatedResources();
initializeNicIpConfigurations();
callback.success(result);
callback.success(new ServiceResponse<Resource>(self, response.getResponse()));
}
}));
});
}

/**************************************************.
Expand Down Expand Up @@ -455,7 +456,7 @@ NetworkInterfaceImpl withIpConfiguration(NicIpConfigurationImpl nicIpConfigurati
return this;
}

void addToCreatableDependencies(Creatable<?> creatableResource) {
void addToCreatableDependencies(Creatable<? extends Resource> creatableResource) {
super.addCreatableDependency(creatableResource);
}

Expand Down
Loading