Skip to content

Commit

Permalink
Merge pull request #803 from martinsawicki/martin-creatable
Browse files Browse the repository at this point in the history
Moving create(), update() into base impl classes; other corrections
  • Loading branch information
jianghaolu authored Jun 14, 2016
2 parents 786aeb7 + 5c5388f commit 0a44c7b
Show file tree
Hide file tree
Showing 31 changed files with 91 additions and 260 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.microsoft.azure.management.compute.implementation;
package com.microsoft.azure.management.compute;

import com.microsoft.azure.management.compute.implementation.api.ImageReference;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.microsoft.azure.management.compute.implementation;
package com.microsoft.azure.management.compute;

import com.microsoft.azure.management.compute.implementation.api.ImageReference;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import com.microsoft.azure.CloudException;
import com.microsoft.azure.PagedList;
import com.microsoft.azure.management.compute.implementation.KnownLinuxVirtualMachineImage;
import com.microsoft.azure.management.compute.implementation.KnownWindowsVirtualMachineImage;
import com.microsoft.azure.management.compute.implementation.api.VirtualMachineInner;
import com.microsoft.azure.management.compute.implementation.api.OperatingSystemTypes;
import com.microsoft.azure.management.compute.implementation.api.CachingTypes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,9 @@ public AvailabilitySetImpl withFaultDomainCount(int faultDomainCount) {
return this;
}

@Override
public AvailabilitySetImpl create() throws Exception {
super.creatablesCreate();
return this;
}

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

@Override
public AvailabilitySetImpl apply() throws Exception {
return create();
return this.create();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
class VirtualMachineImageImpl
extends IndexableWrapperImpl<VirtualMachineImageInner>
implements VirtualMachineImage {
private final VirtualMachineImagesInner client;
private final Region location;
private ImageReference imageReference;

Expand All @@ -30,7 +29,6 @@ class VirtualMachineImageImpl
this.imageReference.withOffer(offer);
this.imageReference.withSku(sku);
this.imageReference.withVersion(version);
this.client = client;
}

VirtualMachineImageImpl(Region location, String publisher, String offer, String sku, String version, VirtualMachineImageInner innerModel, VirtualMachineImagesInner client) {
Expand All @@ -41,7 +39,6 @@ class VirtualMachineImageImpl
this.imageReference.withOffer(offer);
this.imageReference.withSku(sku);
this.imageReference.withVersion(version);
this.client = client;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import com.microsoft.azure.management.compute.AvailabilitySet;
import com.microsoft.azure.management.compute.AvailabilitySets;
import com.microsoft.azure.management.compute.DataDisk;
import com.microsoft.azure.management.compute.KnownLinuxVirtualMachineImage;
import com.microsoft.azure.management.compute.KnownWindowsVirtualMachineImage;
import com.microsoft.azure.management.compute.PowerState;
import com.microsoft.azure.management.compute.VirtualMachine;
import com.microsoft.azure.management.compute.VirtualMachineSize;
Expand Down Expand Up @@ -154,18 +156,7 @@ public VirtualMachine refresh() throws Exception {
}

@Override
public VirtualMachine create() throws Exception {
super.creatablesCreate();
return this;
}

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

@Override
public VirtualMachine apply() throws Exception {
public VirtualMachineImpl apply() throws Exception {
return this.create();
}

Expand Down Expand Up @@ -1047,10 +1038,6 @@ private boolean dataDisksRequiresImplicitStorageAccountCreation() {
return false;
}

private boolean isStoredImage(OSDisk osDisk) {
return osDisk.image() != null;
}

private boolean isOSDiskAttached(OSDisk osDisk) {
return osDisk.createOption() == DiskCreateOptionTypes.ATTACH;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@
import java.util.List;

/**
<<<<<<< HEAD
* The implementation for {@link VirtualMachines}.
=======
* The type representing Azure virtual machines.
>>>>>>> eca873299bef401bbca4c7084dc790063446e986
*/
class VirtualMachinesImpl
implements VirtualMachines {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,6 @@ public NetworkImpl refresh() throws Exception {
return this;
}

@Override
public NetworkImpl create() throws Exception {
super.creatablesCreate();
return this;
}

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

@Override
public NetworkImpl apply() throws Exception {
return this.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,6 @@ public NetworkInterface refresh() throws Exception {
return this;
}

@Override
public NetworkInterfaceImpl create() throws Exception {
this.creatablesCreate();
return this;
}

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

@Override
public NetworkInterfaceImpl apply() throws Exception {
return this.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,6 @@ public NetworkSecurityGroupImpl refresh() throws Exception {
return this;
}

@Override
public NetworkSecurityGroupImpl create() throws Exception {
super.creatablesCreate();
return this;
}

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

@Override
public NetworkSecurityGroupImpl apply() throws Exception {
return this.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ public PublicIpAddressImpl apply() throws Exception {
return this.create();
}

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

@Override
public PublicIpAddress refresh() throws Exception {
ServiceResponse<PublicIPAddressInner> response =
Expand All @@ -56,12 +51,6 @@ public PublicIpAddress refresh() throws Exception {
return this;
}

@Override
public PublicIpAddressImpl create() throws Exception {
super.creatablesCreate();
return this;
}

// Setters (fluent)

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,4 @@
public interface DeploymentOperations extends
SupportsListing<DeploymentOperation>,
SupportsGettingByName<DeploymentOperation> {

/**
* Filter the deployment operations by a specific resource group.
*
* @param resourceGroup the resource group to filter by
* @return the entry point to deployment operation management API in the resource group
*/
InGroup resourceGroup(ResourceGroup resourceGroup);

/**
* Entry point to deployment operation management API in a specific resource group.
*/
interface InGroup extends
SupportsListing<DeploymentOperation>,
SupportsGettingByName<DeploymentOperation> {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ public enum ResourceGroupExportTemplateOptions {
public String toString() {
return this.value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,21 @@ protected AzureConfigurableImpl() {
this.restClientBuilder = AzureEnvironment.AZURE.newRestClientBuilder();
}

@SuppressWarnings("unchecked")
@Override
public T withLogLevel(HttpLoggingInterceptor.Level level) {
this.restClientBuilder = this.restClientBuilder.withLogLevel(level);
return (T) this;
}

@SuppressWarnings("unchecked")
@Override
public T withInterceptor(Interceptor interceptor) {
this.restClientBuilder = this.restClientBuilder.withInterceptor(interceptor);
return (T) this;
}

@SuppressWarnings("unchecked")
@Override
public T withUserAgent(String userAgent) {
this.restClientBuilder = this.restClientBuilder.withUserAgent(userAgent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import com.microsoft.azure.management.resources.fluentcore.arm.models.GroupableResource;

/**
* The implemenation for {@link GroupableResource}.
* The implementation for {@link GroupableResource}.
* (Internal use only)
*
* @param <FluentModelT> The fluent model type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import com.microsoft.azure.management.resources.fluentcore.arm.Region;
import com.microsoft.azure.management.resources.fluentcore.arm.models.Resource;
import com.microsoft.azure.management.resources.fluentcore.model.implementation.CreatableImpl;
import com.microsoft.azure.management.resources.fluentcore.model.implementation.CreatableUpdatableImpl;

import java.util.Collections;
import java.util.HashMap;
Expand All @@ -29,7 +29,7 @@ public abstract class ResourceImpl<
InnerModelT extends com.microsoft.azure.Resource,
FluentModelImplT extends ResourceImpl<FluentModelT, InnerModelT, FluentModelImplT>>
extends
CreatableImpl<FluentModelT, InnerModelT>
CreatableUpdatableImpl<FluentModelT, InnerModelT, FluentModelImplT>
implements
Resource {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
*
* @param <FluentModelT> the fluent model type representing the creatable resource
* @param <InnerModelT> the model inner type that the fluent model type wraps
* @param <FluentModelImplT> the fluent model implementation type
*/
public abstract class CreatableImpl<FluentModelT, InnerModelT>
public abstract class CreatableImpl<FluentModelT, InnerModelT, FluentModelImplT>
extends IndexableRefreshableWrapperImpl<FluentModelT, InnerModelT>
implements CreatableTaskGroup.RootResourceCreator {
/**
Expand All @@ -28,22 +29,6 @@ protected CreatableImpl(String name, InnerModelT innerObject) {
creatableTaskGroup = new CreatableTaskGroup(name, (Creatable<?>) this, this);
}

/**
* create this resource and creatable resources it depends on.
* <p>
* dependency resources will be created only if this is the root group otherwise
* it creates the main resource.
*
* @throws Exception the exception
*/
protected void creatablesCreate() throws Exception {
if (creatableTaskGroup.isRoot()) {
creatableTaskGroup.execute();
} else {
createResource();
}
}

/**
* add a creatable resource dependency for this resource.
*
Expand All @@ -63,6 +48,21 @@ protected Resource createdResource(String key) {
return this.creatableTaskGroup.taskResult(key);
}

/**
* Default implementation of create().
* @return the created resource
* @throws Exception when anything goes wrong
*/
@SuppressWarnings("unchecked")
public FluentModelImplT create() throws Exception {
if (creatableTaskGroup.isRoot()) {
creatableTaskGroup.execute();
} else {
createResource();
}
return (FluentModelImplT) this;
}

/**
* Creates this resource.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* 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.resources.fluentcore.model.implementation;

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

/**
* The base class for all updatable resource.
*
* @param <FluentModelT> the fluent model type representing the resource
* @param <InnerModelT> the model inner type that the fluent model type wraps
* @param <FluentModelImplT> the implementation type of the fluent model
*/
public abstract class CreatableUpdatableImpl<FluentModelT, InnerModelT, FluentModelImplT>
extends CreatableImpl<FluentModelT, InnerModelT, FluentModelImplT> {

protected CreatableUpdatableImpl(String name, InnerModelT innerObject) {
super(name, innerObject);
}

/**
* Begins an update for a new resource.
* <p>
* This is the beginning of the builder pattern used to update top level resources
* in Azure. The final method completing the definition and starting the actual resource creation
* process in Azure is {@link Appliable#apply()}.
*
* @return the stage of new resource update
*/
@SuppressWarnings("unchecked")
public FluentModelImplT update() {
return (FluentModelImplT) this;
}
}
Loading

0 comments on commit 0a44c7b

Please sign in to comment.