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

Extending DeploymentOperationsImpl from ReadableWrappersIm… #1005

Merged
merged 2 commits into from
Aug 3, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -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,203 @@ 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.WithOrWithoutParentResource,
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
*/
WithOrWithoutParentResource withProviderNamespace(String resourceProviderNamespace);
}

/**
* Specifies the plan of the resource.
*
* @return the next stage of the generic resource definition
* A generic resource definition allowing parent resource to be specified.
*/
DefinitionWithApiVersion withoutPlan();
}
interface WithOrWithoutParentResource extends WithPlan {

Choose a reason for hiding this comment

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

Why the "OrWithout" part?

Choose a reason for hiding this comment

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

Based on the comment, I think I understand the intent, but then why idn't WithPlan the next interface in the required chain (instead of WithOrWithoutParentResource) and then this interface (renamed as WithParentResource) simply becomes one of the optionals? (WithCreate)

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a good point!, will update the PR.

/**
* Specifies the parent resource.
*
* @param parentResourceId the parent resource id
* @return the next stage of the generic resource definition
*/
WithPlan withParentResource(String parentResourceId); // ParentResource is optional so user can navigate to WithPlan with or without it.
}

/**
* 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 plan to be specified.
*/
DefinitionCreatable withApiVersion(String apiVersion);
}
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 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 api version to be specified.
*/
DefinitionCreatable withProperties(Object properties);
}
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 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
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