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

AvailabilitySet refinements, javadocs, bug fixes #725

Merged
merged 11 commits into from
May 23, 2016
Original file line number Diff line number Diff line change
Expand Up @@ -3,66 +3,113 @@
import com.microsoft.azure.management.compute.implementation.api.AvailabilitySetInner;
import com.microsoft.azure.management.compute.implementation.api.InstanceViewStatus;
import com.microsoft.azure.management.resources.fluentcore.arm.models.GroupableResource;
import com.microsoft.azure.management.resources.fluentcore.arm.models.Resource;
import com.microsoft.azure.management.resources.fluentcore.model.Appliable;
import com.microsoft.azure.management.resources.fluentcore.model.Creatable;
import com.microsoft.azure.management.resources.fluentcore.model.Refreshable;
import com.microsoft.azure.management.resources.fluentcore.model.Updatable;
import com.microsoft.azure.management.resources.fluentcore.model.Wrapper;

import java.util.List;

/**
* An immutable client-side representation of an Azure availability set.
*/
public interface AvailabilitySet extends
GroupableResource,
Refreshable<AvailabilitySet>,
Wrapper<AvailabilitySetInner> {
Wrapper<AvailabilitySetInner>,
Updatable<AvailabilitySet.Update> {

/**
* Get the update domain count of availability set, an update domain represents the group of virtual
* Returns the update domain count of an availability set.
* <p>
* An update domain represents the group of virtual
* machines and underlying physical hardware that can be rebooted at the same time.
*
* @return the platformUpdateDomainCount value
* @return the update domain count
*/
Integer updateDomainCount();
int updateDomainCount();

/**
* Get the fault domain count of availability set., a fault domain represents the group of virtual
* Returns the fault domain count of availability set.
* <p>
* A fault domain represents the group of virtual
* machines that shares common power source and network switch.
*
* @return the platformUpdateDomainCount value
* @return the fault domain count
*/
Integer FaultDomainCount();
int faultDomainCount();

/**
* Get the list of ids of virtual machines in the availability set.
* Lists the resource IDs of the virtual machines in the availability set.
*
* @return the virtualMachineIds value
* @return list of resource ID strings
*/
List<String> virtualMachineIds();

/**
* Get the list of virtual machines in the availability set.
* Lists the virtual machines in the availability set.
*
* @return the virtualMachineIds value
* @return list of virtual machines
*/
List<VirtualMachine> virtualMachines() throws Exception;

/**
* Get the statuses value.
* Lists the statuses of the existing virtual machines in the availability set.
*
* @return the statuses value
* @return list of virtual machine statuses
*/
List<InstanceViewStatus> statuses();


/**************************************************************
* Fluent interfaces to provision an AvailabilitySet
**************************************************************/

/**
* The first stage of an availability set definition
*/
interface DefinitionBlank extends GroupableResource.DefinitionWithRegion<DefinitionWithGroup> {
}

/**
* The stage of the availability set definition allowing to specify the resource group
*/
interface DefinitionWithGroup extends GroupableResource.DefinitionWithGroup<DefinitionCreatable> {
}

interface DefinitionCreatable extends Creatable<AvailabilitySet> {
DefinitionCreatable withUpdateDomainCount(Integer updateDomainCount);
DefinitionCreatable withFaultDomainCount(Integer faultDomainCount);
/**
* The stage of an availability set definition which contains all the minimum required inputs for
* the resource to be created (via {@link DefinitionCreatable#create()}), but also allows
* for any other optional settings to be specified.
*/
interface DefinitionCreatable extends
Creatable<AvailabilitySet>,
Resource.DefinitionWithTags<DefinitionCreatable> {
/**
* Specifies the update domain count for the availability set.
* @param updateDomainCount update domain count
* @return the next stage of the resource definition
*/
DefinitionCreatable withUpdateDomainCount(int updateDomainCount);

/**
* Specifies the fault domain count for the availability set.
* @param faultDomainCount fault domain count
* @return the next stage of the resource definition
*/
DefinitionCreatable withFaultDomainCount(int faultDomainCount);
}

/**
* The template for an availability set update operation, containing all the settings that
* can be modified.
* <p>
* Call {@link Update#apply()} to apply the changes to the resource in Azure.
*/
interface Update extends
Appliable<AvailabilitySet>,
Resource.UpdateWithTags<Update> {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@
import com.microsoft.azure.management.resources.fluentcore.collection.SupportsDeleting;
import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing;

/**
* Entry point to availability set management API.
*/
public interface AvailabilitySets extends
SupportsListing<AvailabilitySet>,
SupportsListingByGroup<AvailabilitySet>,
SupportsGettingByGroup<AvailabilitySet>,
SupportsCreating<AvailabilitySet.DefinitionBlank>,
SupportsDeleting,
SupportsDeletingByGroup {
/**
* Entry point to availability set management API within a specific resource group.
*/
interface InGroup extends
SupportsListing<AvailabilitySet>,
SupportsCreating<AvailabilitySet.DefinitionCreatable>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*/
package com.microsoft.azure.management.compute.implementation;

import com.microsoft.azure.SubResource;
Expand All @@ -14,16 +19,18 @@
import com.microsoft.rest.ServiceResponse;

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

class AvailabilitySetImpl
extends GroupableResourceImpl<AvailabilitySet, AvailabilitySetInner, AvailabilitySetImpl>
implements
extends
GroupableResourceImpl<AvailabilitySet, AvailabilitySetInner, AvailabilitySetImpl>
implements
AvailabilitySet,
AvailabilitySet.DefinitionBlank,
AvailabilitySet.DefinitionWithGroup,
AvailabilitySet.DefinitionCreatable {
private String name;
AvailabilitySet.DefinitionCreatable,
AvailabilitySet.Update {
private List<String> idOfVMsInSet;
private List<VirtualMachine> vmsInSet;

Expand All @@ -37,19 +44,18 @@ class AvailabilitySetImpl
final AvailabilitySetsInner client,
final ResourceGroups resourceGroups,
final VirtualMachines virtualMachines) {
super(innerModel.id(), innerModel, resourceGroups);
this.name = name;
super(name, innerModel, resourceGroups);
this.client = client;
this.virtualMachines = virtualMachines;
}

@Override
public Integer updateDomainCount() {
public int updateDomainCount() {
return this.inner().platformUpdateDomainCount();
}

@Override
public Integer FaultDomainCount() {
public int faultDomainCount() {
return this.inner().platformFaultDomainCount();
}

Expand All @@ -62,7 +68,7 @@ public List<String> virtualMachineIds() {
}
}

return idOfVMsInSet;
return Collections.unmodifiableList(idOfVMsInSet);
}

@Override
Expand All @@ -75,18 +81,12 @@ public VirtualMachine load(String resourceGroupName, String resourceName) throws
}
});
}
return vmsInSet;
return Collections.unmodifiableList(vmsInSet);
}

@Override
public List<InstanceViewStatus> statuses() {
return this.inner().statuses();
}

@Override
public String name() {
// TODO: This method should be removed once once Runtime::Resource::setName is available.
return this.name;
return Collections.unmodifiableList(this.inner().statuses());
}

@Override
Expand All @@ -99,13 +99,13 @@ public AvailabilitySet refresh() throws Exception {
}

@Override
public AvailabilitySetImpl withUpdateDomainCount(Integer updateDomainCount) {
public AvailabilitySetImpl withUpdateDomainCount(int updateDomainCount) {
this.inner().setPlatformUpdateDomainCount(updateDomainCount);
return this;
}

@Override
public AvailabilitySetImpl withFaultDomainCount(Integer faultDomainCount) {
public AvailabilitySetImpl withFaultDomainCount(int faultDomainCount) {
this.inner().setPlatformFaultDomainCount(faultDomainCount);
return this;
}
Expand All @@ -115,11 +115,21 @@ public AvailabilitySetImpl create() throws Exception {
for (Creatable<?> provisionable : prerequisites().values()) {
provisionable.create();
}
ServiceResponse<AvailabilitySetInner> response = this.client.createOrUpdate(this.resourceGroupName(), this.name(), this.inner());
ServiceResponse<AvailabilitySetInner> response = this.client.createOrUpdate(this.resourceGroupName(), this.key, this.inner());
AvailabilitySetInner availabilitySetInner = response.getBody();
this.setInner(availabilitySetInner);
this.idOfVMsInSet = null;
this.vmsInSet = null;
return this;
}

@Override
public AvailabilitySetImpl update() throws Exception {
return this;
}

@Override
public AvailabilitySetImpl apply() throws Exception {
return create();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public AvailabilitySetsImpl(final AvailabilitySetsInner client,
this.virtualMachines = virtualMachines;
this.converter = new PagedListConverter<AvailabilitySetInner, AvailabilitySet>() {
@Override
public AvailabilitySet typeConvert(AvailabilitySetInner availabilitySetInner) {
return createFluentModel(availabilitySetInner);
public AvailabilitySet typeConvert(AvailabilitySetInner inner) {
return createFluentModel(inner);
}
};
}
Expand Down Expand Up @@ -71,13 +71,13 @@ public Page<AvailabilitySetInner> nextPage(String nextPageLink) throws RestExcep
}

@Override
public AvailabilitySet get(String groupName, String name) throws CloudException, IOException {
public AvailabilitySetImpl get(String groupName, String name) throws CloudException, IOException {
ServiceResponse<AvailabilitySetInner> response = this.client.get(groupName, name);
return createFluentModel(response.getBody());
}

@Override
public AvailabilitySet.DefinitionBlank define(String name) {
public AvailabilitySetImpl define(String name) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this change? Returning an AvailabilitySetImpl exposes all methods to the user at once.

Copy link
Author

Choose a reason for hiding this comment

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

nope. remember, the user can only view this object through interfaces. The impl is package-internal. The impls should always return impls, not interfaces. Otherwise, we wouldn't be able to implement Update and Definition using the same impl.

Copy link
Contributor

Choose a reason for hiding this comment

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

Make sense.

return createFluentModel(name);
}

Expand Down
Loading