Skip to content

Commit

Permalink
Merge pull request #1005 from anuchandy/generic-resource
Browse files Browse the repository at this point in the history
Extending DeploymentOperationsImpl  from ReadableWrappersIm…
  • Loading branch information
Martin Sawicki authored Aug 3, 2016
2 parents 0fdd748 + 654f089 commit ae00855
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 149 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
public interface GenericResource extends
GroupableResource,
Refreshable<GenericResource>,
Updatable<GenericResource.UpdateWithApiVersion>,
Updatable<GenericResource.UpdateStages.WithApiVersion>,
Wrapper<GenericResourceInner> {
/**
* @return the namespace of the resource provider
Expand Down Expand Up @@ -54,179 +54,204 @@ public interface GenericResource extends
Object properties();

/**
* A generic resource definition allowing region to be specified.
* The entirety of the generic resource definition.
*/
interface DefinitionBlank extends GroupableResource.DefinitionWithRegion<DefinitionWithGroup> {
interface Definition extends
DefinitionStages.Blank,
DefinitionStages.WithGroup,
DefinitionStages.WithResourceType,
DefinitionStages.WithProviderNamespace,
DefinitionStages.WithParentResource,
DefinitionStages.WithPlan,
DefinitionStages.WithApiVersion,
DefinitionStages.WithCreate {
}

/**
* A generic resource definition allowing resource group to be specified.
* Grouping of generic resource definition stages.
*/
interface DefinitionWithGroup extends GroupableResource.DefinitionStages.WithGroup<DefinitionWithResourceType> {
}

/**
* A generic resource definition allowing resource type to be specified.
*/
interface DefinitionWithResourceType {
interface DefinitionStages {
/**
* Specifies the resource's type.
*
* @param resourceType the type of the resources
* @return the next stage of generic resource definition
* A generic resource definition allowing region to be specified.
*/
DefinitionWithProviderNamespace withResourceType(String resourceType);
}
interface Blank extends GroupableResource.DefinitionWithRegion<WithGroup> {
}

/**
* A generic resource definition allowing provider namespace to be specified.
*/
interface DefinitionWithProviderNamespace {
/**
* Specifies the resource provider's namespace.
*
* @param resourceProviderNamespace the namespace of the resource provider
* @return the next stage of the generic resource definition
* A generic resource definition allowing resource group to be specified.
*/
DefinitionWithOrWithoutParentResource withProviderNamespace(String resourceProviderNamespace);
}
interface WithGroup extends GroupableResource.DefinitionStages.WithGroup<WithResourceType> {
}

/**
* A generic resource definition allowing parent resource to be specified.
*/
interface DefinitionWithOrWithoutParentResource extends DefinitionWithPlan {
/**
* Specifies the parent resource.
*
* @param parentResourceId the parent resource id
* @return the next stage of the generic resource definition
* A generic resource definition allowing resource type to be specified.
*/
DefinitionWithPlan withParentResource(String parentResourceId); // ParentResource is optional so user can navigate to DefinitionWithPlan with or without it.
}
interface WithResourceType {
/**
* Specifies the resource's type.
*
* @param resourceType the type of the resources
* @return the next stage of generic resource definition
*/
WithProviderNamespace withResourceType(String resourceType);
}

/**
* A generic resource definition allowing plan to be specified.
*/
interface DefinitionWithPlan {
/**
* Specifies the plan of the resource. The plan can only be set for 3rd party resources.
*
* @param name the name of the plan
* @param publisher the publisher of the plan
* @param product the name of the product
* @param promotionCode the promotion code, if any
* @return the next stage of the generic resource definition
* A generic resource definition allowing provider namespace to be specified.
*/
DefinitionWithApiVersion withPlan(String name, String publisher, String product, String promotionCode);
interface WithProviderNamespace {
/**
* Specifies the resource provider's namespace.
*
* @param resourceProviderNamespace the namespace of the resource provider
* @return the next stage of the generic resource definition
*/
WithPlan withProviderNamespace(String resourceProviderNamespace);
}

/**
* Specifies the plan of the resource.
*
* @return the next stage of the generic resource definition
* A generic resource definition allowing plan to be specified.
*/
DefinitionWithApiVersion withoutPlan();
}
interface WithPlan {
/**
* Specifies the plan of the resource. The plan can only be set for 3rd party resources.
*
* @param name the name of the plan
* @param publisher the publisher of the plan
* @param product the name of the product
* @param promotionCode the promotion code, if any
* @return the next stage of the generic resource definition
*/
WithApiVersion withPlan(String name, String publisher, String product, String promotionCode);

/**
* Specifies the plan of the resource.
*
* @return the next stage of the generic resource definition
*/
WithApiVersion withoutPlan();
}

/**
* A generic resource definition allowing api version to be specified.
*/
interface DefinitionWithApiVersion {
/**
* Specifies the api version.
*
* @param apiVersion the API version of the resource
* @return the next stage of the generic resource definition
* A generic resource definition allowing api version to be specified.
*/
DefinitionCreatable withApiVersion(String apiVersion);
}
interface WithApiVersion {
/**
* Specifies the api version.
*
* @param apiVersion the API version of the resource
* @return the next stage of the generic resource definition
*/
WithCreate withApiVersion(String apiVersion);
}

/**
* A deployment definition with sufficient inputs to create a new
* resource in the cloud, but exposing additional optional inputs to
* specify.
*/
interface DefinitionCreatable extends
Creatable<GenericResource>,
Resource.DefinitionWithTags<DefinitionCreatable> {
/**
* Specifies other properties.
*
* @param properties the properties object
* @return the next stage of generic resource definition
* A generic resource definition allowing parent resource to be specified.
*/
DefinitionCreatable withProperties(Object properties);
}
interface WithParentResource {
/**
* Specifies the parent resource.
*
* @param parentResourceId the parent resource id
* @return the next stage of the generic resource definition
*/
WithCreate withParentResource(String parentResourceId);
}

/**
* A generic resource update allowing to change the resource properties.
*/
interface UpdateWithProperties {
/**
* Specifies other properties of the resource.
*
* @param properties the properties object
* @return the next stage of generic resource update
* A deployment definition with sufficient inputs to create a new
* resource in the cloud, but exposing additional optional inputs to
* specify.
*/
Update withProperties(Object properties);
interface WithCreate extends
WithParentResource,
Creatable<GenericResource>,
Resource.DefinitionWithTags<WithCreate> {
/**
* Specifies other properties.
*
* @param properties the properties object
* @return the next stage of generic resource definition
*/
WithCreate withProperties(Object properties);
}
}

/**
* A generic resource update allowing to change the parent resource.
* Grouping of generic resource update stages.
*/
interface UpdateWithParentResource {
interface UpdateStages {
/**
* Specifies the parent resource.
*
* @param parentResourceId the parent resource ID
* @return the next stage of the generic resource definition
* A generic resource update allowing to change the resource properties.
*/
Update withParentResource(String parentResourceId);
}
interface WithProperties {
/**
* Specifies other properties of the resource.
*
* @param properties the properties object
* @return the next stage of generic resource update
*/
Update withProperties(Object properties);
}

/**
* A generic resource update allowing to change the resource plan.
*/
interface UpdateWithPlan {
/**
* Specifies the plan of the resource.
*
* @param name the name of the plan
* @param publisher the publisher of the plan
* @param product the name of the product
* @param promotionCode the promotion code, if any
* @return the next stage of the generic resource update
* A generic resource update allowing to change the parent resource.
*/
Update withPlan(String name, String publisher, String product, String promotionCode);
interface WithParentResource {
/**
* Specifies the parent resource.
*
* @param parentResourceId the parent resource ID
* @return the next stage of the generic resource definition
*/
Update withParentResource(String parentResourceId);
}

/**
* Specifies the plan of the resource.
*
* @return the next stage of the generic resource update
* A generic resource update allowing to change the resource plan.
*/
Update withoutPlan();
}
interface WithPlan {
/**
* Specifies the plan of the resource.
*
* @param name the name of the plan
* @param publisher the publisher of the plan
* @param product the name of the product
* @param promotionCode the promotion code, if any
* @return the next stage of the generic resource update
*/
Update withPlan(String name, String publisher, String product, String promotionCode);

/**
* Specifies the plan of the resource.
*
* @return the next stage of the generic resource update
*/
Update withoutPlan();
}

/**
* The template for a generic resource update operation for specifying the resource provider API version.
*/
interface UpdateWithApiVersion {
/**
* Specifies the API version of the resource provider.
*
* @param apiVersion the API version
* @return the next stage of the generic resource update
* The template for a generic resource update operation for specifying the resource provider API version.
*/
Update withApiVersion(String apiVersion);
interface WithApiVersion {
/**
* Specifies the API version of the resource provider.
*
* @param apiVersion the API version
* @return the next stage of the generic resource update
*/
Update withApiVersion(String apiVersion);
}
}

/**
* The template for a generic resource update operation, containing all the settings that can be modified.
*/
interface Update extends
Appliable<GenericResource>,
UpdateWithPlan,
UpdateWithParentResource,
UpdateWithProperties,
UpdateStages.WithPlan,
UpdateStages.WithParentResource,
UpdateStages.WithProperties,
Resource.UpdateWithTags<Update> {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
public interface GenericResources extends
SupportsListingByGroup<GenericResource>,
SupportsGettingById<GenericResource>,
SupportsCreating<GenericResource.DefinitionBlank> {
SupportsCreating<GenericResource.DefinitionStages.Blank> {
/**
* Checks if a resource exists in a resource group.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,36 @@
import com.microsoft.azure.management.resources.Deployment;
import com.microsoft.azure.management.resources.DeploymentOperation;
import com.microsoft.azure.management.resources.DeploymentOperations;
import com.microsoft.azure.management.resources.fluentcore.utils.PagedListConverter;

import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.ReadableWrappersImpl;
import java.io.IOException;

/**
* The implementation of {@link DeploymentOperations}.
*/
final class DeploymentOperationsImpl
extends ReadableWrappersImpl<DeploymentOperation, DeploymentOperationImpl, DeploymentOperationInner>
implements DeploymentOperations {
private final DeploymentOperationsInner client;
private final Deployment deployment;
private final PagedListConverter<DeploymentOperationInner, DeploymentOperation> converter;

DeploymentOperationsImpl(final DeploymentOperationsInner client,
final Deployment deployment) {
this.client = client;
this.deployment = deployment;
converter = new PagedListConverter<DeploymentOperationInner, DeploymentOperation>() {
@Override
public DeploymentOperation typeConvert(DeploymentOperationInner deploymentInner) {
return createFluentModel(deploymentInner);
}
};
}

@Override
public PagedList<DeploymentOperation> list() throws CloudException, IOException {
return converter.convert(client.list(deployment.resourceGroupName(), deployment.name()).getBody());
return wrapList(client.list(deployment.resourceGroupName(), deployment.name()).getBody());
}

@Override
public DeploymentOperation getById(String operationId) throws CloudException, IllegalArgumentException, IOException {
return createFluentModel(client.get(deployment.resourceGroupName(), deployment.name(), operationId).getBody());
return wrapModel(client.get(deployment.resourceGroupName(), deployment.name(), operationId).getBody());
}

private DeploymentOperationImpl createFluentModel(DeploymentOperationInner deploymentOperationInner) {
return new DeploymentOperationImpl(deploymentOperationInner, this.client);
@Override
protected DeploymentOperationImpl wrapModel(DeploymentOperationInner inner) {
return new DeploymentOperationImpl(inner, this.client);
}
}
Loading

0 comments on commit ae00855

Please sign in to comment.