AlgoMaster Logo
AlgoMasterDesign Cloud Provider Factoryhard

Design Cloud Provider Factory

hard

A deployment tool can target AWS or GCP. Each provider is a family of three related services: compute, object storage, and a database. Those services must be selected together; an accidental mix such as EC2, GCS, and RDS would describe a deployment split across clouds.

The service contracts, all six concrete services, ResourceRequest, and CloudDeployment are already implemented. Your job is to complete only the factory layer:

  • CloudFactory, the abstract factory contract.
  • AwsCloudFactory, which creates the AWS service family.
  • GcpCloudFactory, which creates the GCP service family.

CloudFactory must provide providerName(), createCompute(), createStorage(), and createDatabase(). Each concrete factory must return its own name and the matching pre-built services:

Scroll

Factory

Compute

Storage

Database

AwsCloudFactory

AwsCompute

AwsStorage

AwsDatabase

GcpCloudFactory

GcpCompute

GcpStorage

GcpDatabase

Do not reimplement the services, resource request, or deployment client. The tests exercise your factories through this pre-built CloudDeployment:

  • CloudDeployment() creates an empty deployment on the aws provider.
  • boolean setProvider(String name) switches to "aws" or "gcp" and returns true. It changes nothing and returns false when the name is not recognised, and also when the deployment already holds at least one resource.
  • String currentProvider() returns the name of the active provider.
  • boolean addCompute(String instanceType) records a compute resource and returns true, or returns false once 6 resources are held.
  • boolean addStorage(String bucketName) records a storage resource under the same limit.
  • boolean addDatabase(String engine, String size) records a database resource under the same limit.
  • String[] deploy() returns one line per resource, in the order the resources were added. An empty deployment returns a single line, "NOTHING TO DEPLOY".
  • String partsReport() returns "compute=<provider>, storage=<provider>, database=<provider>", naming the provider that each service currently in use belongs to.
  • boolean reset() drops every recorded resource and returns true, or returns false when there was nothing to drop.
  • int resourceCount() returns how many resources are held.

The AWS services produce these lines:

  • Launching EC2 instance: <instanceType>
  • Creating S3 bucket: <bucketName>
  • Provisioning RDS: <engine>, <size>

The GCP services produce these lines:

  • Launching GCE instance: <instanceType>
  • Creating GCS bucket: <bucketName>
  • Provisioning Cloud SQL: <engine>, <size>

reset drops resources and leaves the provider alone, so calling it is what unlocks a later provider switch. Although the tests call CloudDeployment, the only missing code is the abstract factory and its two implementations.

Example 1:

Input:

Output:

Explanation: A new deployment is on AWS, so the three added resources come back described in AWS terms and in the order they were added.

Example 2:

Input:

Output:

Explanation: Switching to GCP before anything is added replaces all three services at once, so the same three additions produce GCP wording throughout.

Constraints

  • 1 <= instanceType.length <= 30
  • 1 <= bucketName.length <= 30
  • 1 <= engine.length <= 20
  • 1 <= size.length <= 10
  • At most 6 resources are held at one time.
  • At most 100 calls in total are made across all methods.

Starter Code

Only CloudFactory, AwsCloudFactory, and GcpCloudFactory are unfinished. Complete those three types at the marked comments; leave the supplied services, ResourceRequest, and CloudDeployment unchanged.

How the design is graded

needs 7/10 to pass
  • Complete abstract factory contract

    Full marks when `CloudFactory` declares `providerName`, `createCompute`, `createStorage`, and `createDatabase` with the expected return types. Lose points when any service must be selected independently.

  • Consistent concrete families

    Full marks when the AWS factory returns only AWS services and the GCP factory returns only GCP services. Lose points heavily for any compute, storage, or database service from the wrong provider.

  • Focused implementation

    Full marks when only the three requested factory types are added, names and signatures match the scaffold, and methods return objects instead of printing. Lose points for rewriting the supplied services, `ResourceRequest`, or `CloudDeployment`.

Passing every test is not enough on its own. A submission is accepted only when the design also clears the bar.

Hints

Loading...
CallReturns
new CloudDeployment()null
currentProvider()"aws"
addCompute("t3.micro")true
addStorage("my-app-data")true
addDatabase("mysql", "100GB")true
deploy()["Launching EC2 instance: t3.micro","Creating S3 bucket: my-app-data","Provisioning RDS: mysql, 100GB"]

A new deployment is on AWS, so the three added resources come back described in AWS terms and in the order they were added.

Run checks these cases. Submit also runs a larger hidden set.