Skip to content
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 @@ -11,6 +11,9 @@
import com.microsoft.azure.management.compute.implementation.api.AvailabilitySetsInner;
import com.microsoft.azure.management.compute.implementation.api.InstanceViewStatus;
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.azure.management.resources.implementation.ResourceManager;
import com.microsoft.rest.ServiceResponse;
import java.util.ArrayList;
Expand Down Expand Up @@ -90,11 +93,33 @@ public AvailabilitySetImpl apply() throws Exception {
return this.create();
}

@Override
public ServiceCall applyAsync(ServiceCallback<AvailabilitySet> callback) {
return this.createAsync(callback);
}

@Override
protected void createResource() throws Exception {
ServiceResponse<AvailabilitySetInner> response = this.client.createOrUpdate(this.resourceGroupName(), this.name(), this.inner());
AvailabilitySetInner availabilitySetInner = response.getBody();
this.setInner(availabilitySetInner);
this.idOfVMsInSet = null;
}

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Neat. One minor thing maybe is the callback naming. Nouns as method names (that are not merely simple property accessors) seem a little bit odd. Not sure if there is official guidance on this, but onFailure, onSuccess sounds a bit more intuitive to me. (example usage: http://www.gwtproject.org/javadoc/latest/com/google/gwt/user/client/rpc/AsyncCallback.html)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

..having said that, I see this is not from your code :-) So never mind.

callback.failure(t);
}

@Override
public void success(ServiceResponse<Void> result) {
idOfVMsInSet = null;
callback.success(result);
}
}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@
import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.GroupableResourceImpl;
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.ResourceManager;
import com.microsoft.azure.management.resources.implementation.api.PageImpl;
import com.microsoft.azure.management.storage.StorageAccount;
import com.microsoft.azure.management.storage.implementation.StorageManager;
import com.microsoft.rest.RestException;
import com.microsoft.rest.ServiceCall;
import com.microsoft.rest.ServiceCallback;
import com.microsoft.rest.ServiceResponse;

import java.io.IOException;
Expand Down Expand Up @@ -156,6 +159,11 @@ public VirtualMachineImpl apply() throws Exception {
return this.create();
}

@Override
public ServiceCall applyAsync(ServiceCallback<VirtualMachine> callback) {
return this.createAsync(callback);
}

@Override
public void deallocate() throws CloudException, IOException, InterruptedException {
this.client.deallocate(this.resourceGroupName(), this.name());
Expand Down Expand Up @@ -850,6 +858,43 @@ protected void createResource() throws Exception {
initializeDataDisks();
}

@Override
protected ServiceCall createResourceAsync(final ServiceCallback<Void> callback) {
if (isInCreateMode()) {
setOSDiskAndOSProfileDefaults();
setHardwareProfileDefaults();
}
DataDiskImpl.setDataDisksDefaults(this.dataDisks, this.vmName);
final VirtualMachineImpl self = this;
final ServiceCall call = new ServiceCall(null);
handleStorageSettingsAsync(new ServiceCallback<Void>() {
@Override
public void failure(Throwable t) {
callback.failure(t);
}

@Override
public void success(ServiceResponse<Void> result) {
handleNetworkSettings();
handleAvailabilitySettings();
call.newCall(client.createOrUpdateAsync(resourceGroupName(), vmName, inner(),
Utils.fromVoidCallback(self, new ServiceCallback<Void>() {
@Override
public void failure(Throwable t) {
callback.failure(t);
}

@Override
public void success(ServiceResponse<Void> result) {
initializeDataDisks();
callback.success(result);
}
})).getCall());
}
});
return call;
}

/**************************************************.
* Helper methods
**************************************************/
Expand Down Expand Up @@ -927,6 +972,61 @@ private void handleStorageSettings() throws Exception {
}
}

private void handleStorageSettingsAsync(final ServiceCallback<Void> callback) {
final ServiceCallback<StorageAccount> storageAccountServiceCallback = new ServiceCallback<StorageAccount>() {
@Override
public void failure(Throwable t) {
callback.failure(t);
}

@Override
public void success(ServiceResponse<StorageAccount> result) {
if (isInCreateMode()) {
if (isOSDiskFromImage(inner().storageProfile().osDisk())) {
String uri = inner()
.storageProfile()
.osDisk().vhd().uri()
.replaceFirst("\\{storage-base-url}", result.getBody().endPoints().primary().blob());
inner().storageProfile().osDisk().vhd().withUri(uri);
}
DataDiskImpl.ensureDisksVhdUri(dataDisks, result.getBody(), vmName);
} else {
if (result.getBody() != null) {
DataDiskImpl.ensureDisksVhdUri(dataDisks, result.getBody(), vmName);
} else {
DataDiskImpl.ensureDisksVhdUri(dataDisks, vmName);
}
}
callback.success(new ServiceResponse<Void>(result.getHeadResponse()));
}
};
if (this.creatableStorageAccountKey != null) {
storageAccountServiceCallback.success(new ServiceResponse<>(
(StorageAccount) this.createdResource(this.creatableStorageAccountKey), null));
} else if (this.existingStorageAccountToAssociate != null) {
storageAccountServiceCallback.success(new ServiceResponse<>(
this.existingStorageAccountToAssociate, null));
} else if (osDiskRequiresImplicitStorageAccountCreation()
|| dataDisksRequiresImplicitStorageAccountCreation()) {
this.storageManager.storageAccounts()
.define(this.namer.randomName("stg", 24))
.withRegion(this.region())
.withExistingGroup(this.resourceGroupName())
.createAsync(new ServiceCallback<StorageAccount>() {
@Override
public void failure(Throwable t) {
callback.failure(t);
}

@Override
public void success(ServiceResponse<StorageAccount> result) {
storageAccountServiceCallback.success(result);
}
});
}

}

private void handleNetworkSettings() {
if (isInCreateMode()) {
NetworkInterface primaryNetworkInterface = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,24 @@
*/
package com.microsoft.azure.management.network.implementation;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import com.microsoft.azure.management.network.Network;
import com.microsoft.azure.management.network.Subnet;
import com.microsoft.azure.management.network.implementation.api.SubnetInner;
import com.microsoft.azure.management.network.implementation.api.VirtualNetworkInner;
import com.microsoft.azure.management.network.implementation.api.VirtualNetworksInner;
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.azure.management.resources.implementation.ResourceManager;
import com.microsoft.rest.ServiceResponse;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

/**
* Internal virtual network implementation of the fluent interface.
* (Internal use only)
Expand Down Expand Up @@ -67,6 +70,11 @@ public NetworkImpl apply() throws Exception {
return this.create();
}

@Override
public ServiceCall applyAsync(ServiceCallback<Network> callback) {
return createAsync(callback);
}

// Setters (fluent)

@Override
Expand Down Expand Up @@ -165,4 +173,33 @@ protected void createResource() throws Exception {
this.setInner(response.getBody());
initializeSubnetsFromInner();
}

@Override
protected ServiceCall createResourceAsync(final ServiceCallback<Void> callback) {
// Ensure address spaces
if (this.addressSpaces().size() == 0) {
this.withAddressSpace("10.0.0.0/16");
}

if (isInCreateMode()) {
// Create a subnet as needed, covering the entire first address space
if (this.inner().subnets().size() == 0) {
this.withSubnet("subnet1", this.addressSpaces().get(0));
}
}

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

@Override
public void success(ServiceResponse<Void> result) {
initializeSubnetsFromInner();
callback.success(result);
}
}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import com.microsoft.azure.management.resources.fluentcore.model.Creatable;
import com.microsoft.azure.management.resources.fluentcore.utils.ResourceNamer;
import com.microsoft.azure.management.resources.fluentcore.utils.Utils;
import com.microsoft.rest.ServiceCall;
import com.microsoft.rest.ServiceCallback;
import com.microsoft.azure.management.resources.implementation.ResourceManager;
import com.microsoft.rest.ServiceResponse;

Expand Down Expand Up @@ -91,6 +93,11 @@ public NetworkInterfaceImpl apply() throws Exception {
return this.create();
}

@Override
public ServiceCall applyAsync(ServiceCallback<NetworkInterface> callback) {
return createAsync(callback);
}

/**************************************************.
* Setters
**************************************************/
Expand Down Expand Up @@ -352,6 +359,26 @@ protected void createResource() throws Exception {
initializeNicIpConfigurations();
}

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

@Override
public void success(ServiceResponse<Void> result) {
initializeNicIpConfigurations();
callback.success(result);
}
}));
}

/**************************************************.
* Helper methods
**************************************************/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,23 @@
*/
package com.microsoft.azure.management.network.implementation;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.microsoft.azure.management.network.NetworkSecurityGroup;
import com.microsoft.azure.management.network.NetworkSecurityRule;
import com.microsoft.azure.management.network.implementation.api.NetworkInterfaceInner;
import com.microsoft.azure.management.network.implementation.api.NetworkSecurityGroupInner;
import com.microsoft.azure.management.network.implementation.api.NetworkSecurityGroupsInner;
import com.microsoft.azure.management.network.implementation.api.SecurityRuleInner;
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.azure.management.resources.implementation.ResourceManager;
import com.microsoft.rest.ServiceResponse;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
* Implementation of the NetworkSecurityGroup interface.
* (Internal use only)
Expand Down Expand Up @@ -75,6 +78,11 @@ public NetworkSecurityGroupImpl apply() throws Exception {
return this.create();
}

@Override
public ServiceCall applyAsync(ServiceCallback<NetworkSecurityGroup> callback) {
return createAsync(callback);
}

@Override
protected void createResource() throws Exception {
ServiceResponse<NetworkSecurityGroupInner> response =
Expand All @@ -83,6 +91,23 @@ protected void createResource() throws Exception {
initializeRulesFromInner();
}

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

@Override
public void success(ServiceResponse<Void> result) {
initializeRulesFromInner();
callback.success(result);
}
}));
}


// Setters (fluent)

Expand Down
Loading