Skip to content

Commit

Permalink
move CloudProvider enum to its own crate
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-hunt-materialize committed Dec 16, 2024
1 parent c9092f9 commit 3b0aaa8
Show file tree
Hide file tree
Showing 11 changed files with 132 additions and 87 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ members = [
"src/catalog-debug",
"src/catalog-protos",
"src/cloud-api",
"src/cloud-provider",
"src/cluster",
"src/clusterd",
"src/cluster-client",
Expand Down Expand Up @@ -134,6 +135,7 @@ default-members = [
"src/catalog-protos",
"src/ccsr",
"src/cloud-api",
"src/cloud-provider",
"src/cloud-resources",
"src/cluster",
"src/cluster-client",
Expand Down
1 change: 1 addition & 0 deletions src/adapter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ mz-audit-log = { path = "../audit-log" }
mz-build-info = { path = "../build-info" }
mz-catalog = { path = "../catalog" }
mz-ccsr = { path = "../ccsr" }
mz-cloud-provider = { path = "../cloud-provider", default-features = false }
mz-cloud-resources = { path = "../cloud-resources" }
mz-cluster-client = { path = "../cluster-client" }
mz-compute-client = { path = "../compute-client" }
Expand Down
3 changes: 2 additions & 1 deletion src/adapter/src/config/frontend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ use std::time::Duration;
use derivative::Derivative;
use launchdarkly_server_sdk as ld;
use mz_build_info::BuildInfo;
use mz_cloud_provider::CloudProvider;
use mz_ore::now::NowFn;
use mz_sql::catalog::{CloudProvider, EnvironmentId};
use mz_sql::catalog::EnvironmentId;
use tokio::time;

use crate::config::{Metrics, SynchronizedParameters, SystemParameterSyncConfig};
Expand Down
18 changes: 18 additions & 0 deletions src/cloud-provider/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "mz-cloud-provider"
description = "Representation of a cloud provider"
version = "0.1.0"
authors = ["Materialize, Inc."]
license = "proprietary"
edition.workspace = true
rust-version.workspace = true
publish = false

[dependencies]
workspace-hack = { version = "0.0.0", path = "../workspace-hack", optional = true }

[features]
default = ["workspace-hack"]

[lints]
workspace = true
85 changes: 85 additions & 0 deletions src/cloud-provider/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// Copyright Materialize, Inc. and contributors. All rights reserved.
//
// Use of this software is governed by the Business Source License
// included in the LICENSE file.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0.

use std::fmt;
use std::str::FromStr;

/// Identifies a supported cloud provider.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum CloudProvider {
/// A pseudo-provider value used by local development environments.
Local,
/// A pseudo-provider value used by Docker.
Docker,
/// A deprecated psuedo-provider value used by mzcompose.
// TODO(benesch): remove once v0.39 ships.
MzCompose,
/// A pseudo-provider value used by cloudtest.
Cloudtest,
/// Amazon Web Services.
Aws,
/// Google Cloud Platform
Gcp,
/// Microsoft Azure
Azure,
/// Other generic cloud provider
Generic,
}

impl CloudProvider {
/// Returns true if this provider actually runs in the cloud
pub fn is_cloud(&self) -> bool {
matches!(self, Self::Aws | Self::Gcp | Self::Azure | Self::Generic)
}
}

impl fmt::Display for CloudProvider {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
CloudProvider::Local => f.write_str("local"),
CloudProvider::Docker => f.write_str("docker"),
CloudProvider::MzCompose => f.write_str("mzcompose"),
CloudProvider::Cloudtest => f.write_str("cloudtest"),
CloudProvider::Aws => f.write_str("aws"),
CloudProvider::Gcp => f.write_str("gcp"),
CloudProvider::Azure => f.write_str("azure"),
CloudProvider::Generic => f.write_str("generic"),
}
}
}

impl FromStr for CloudProvider {
type Err = InvalidCloudProviderError;

fn from_str(s: &str) -> Result<CloudProvider, InvalidCloudProviderError> {
match s.to_lowercase().as_ref() {
"local" => Ok(CloudProvider::Local),
"docker" => Ok(CloudProvider::Docker),
"mzcompose" => Ok(CloudProvider::MzCompose),
"cloudtest" => Ok(CloudProvider::Cloudtest),
"aws" => Ok(CloudProvider::Aws),
"gcp" => Ok(CloudProvider::Gcp),
"azure" => Ok(CloudProvider::Azure),
"generic" => Ok(CloudProvider::Generic),
_ => Err(InvalidCloudProviderError),
}
}
}

/// The error type for [`CloudProvider::from_str`].
#[derive(Debug, Clone, PartialEq)]
pub struct InvalidCloudProviderError;

impl fmt::Display for InvalidCloudProviderError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("invalid cloud provider")
}
}

impl std::error::Error for InvalidCloudProviderError {}
20 changes: 10 additions & 10 deletions src/orchestratord/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ k8s-controller = "0.3.3"
k8s-openapi = { version = "0.22.0", features = ["v1_29"] }
kube = { version = "0.92.1", default-features = false, features = ["client", "runtime", "ws"] }
maplit = "1.0.2"
mz-alloc = { path = "../alloc" }
mz-alloc-default = { path = "../alloc-default", optional = true }
mz-build-info = { path = "../build-info" }
mz-cloud-resources = { path = "../cloud-resources" }
mz-ore = { path = "../ore" }
mz-orchestrator-kubernetes = { path = "../orchestrator-kubernetes" }
mz-orchestrator-tracing = { path = "../orchestrator-tracing" }
mz-prof-http = { path = "../prof-http" }
mz-sql = { path = "../sql" }
mz-tls-util = { path = "../tls-util" }
mz-alloc = { path = "../alloc", default-features = false }
mz-alloc-default = { path = "../alloc-default", optional = true, default-features = false }
mz-build-info = { path = "../build-info", default-features = false }
mz-cloud-provider = { path = "../cloud-provider", default-features = false }
mz-cloud-resources = { path = "../cloud-resources", default-features = false }
mz-ore = { path = "../ore", default-features = false }
mz-orchestrator-kubernetes = { path = "../orchestrator-kubernetes", default-features = false }
mz-orchestrator-tracing = { path = "../orchestrator-tracing", default-features = false }
mz-prof-http = { path = "../prof-http", default-features = false }
mz-tls-util = { path = "../tls-util", default-features = false }
prometheus = { version = "0.13.3", default-features = false }
rand = "0.8.5"
reqwest = { version = "0.11.13", features = ["json"] }
Expand Down
2 changes: 1 addition & 1 deletion src/orchestratord/src/controller/materialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ use serde::Deserialize;
use tracing::{debug, trace};

use crate::metrics::Metrics;
use mz_cloud_provider::CloudProvider;
use mz_cloud_resources::crd::materialize::v1alpha1::{
Materialize, MaterializeCertSpec, MaterializeStatus,
};
use mz_orchestrator_kubernetes::KubernetesImagePullPolicy;
use mz_orchestrator_tracing::TracingCliArgs;
use mz_ore::{cast::CastFrom, cli::KeyValueArg, instrument};
use mz_sql::catalog::CloudProvider;

pub mod balancer;
pub mod console;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ use tracing::trace;
use super::matching_image_from_environmentd_image_ref;
use crate::controller::materialize::tls::{create_certificate, issuer_ref_defined};
use crate::k8s::{apply_resource, delete_resource, get_resource};
use mz_cloud_provider::CloudProvider;
use mz_cloud_resources::crd::gen::cert_manager::certificates::Certificate;
use mz_cloud_resources::crd::materialize::v1alpha1::Materialize;
use mz_orchestrator_tracing::TracingCliArgs;
use mz_ore::instrument;
use mz_sql::catalog::CloudProvider;

/// Describes the status of a deployment.
///
Expand Down
1 change: 1 addition & 0 deletions src/sql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ mz-adapter-types = { path = "../adapter-types" }
mz-audit-log = { path = "../audit-log" }
mz-build-info = { path = "../build-info" }
mz-ccsr = { path = "../ccsr" }
mz-cloud-provider = { path = "../cloud-provider", default-features = false }
mz-cloud-resources = { path = "../cloud-resources" }
mz-controller-types = { path = "../controller-types" }
mz-dyncfg = { path = "../dyncfg" }
Expand Down
75 changes: 1 addition & 74 deletions src/sql/src/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use std::time::{Duration, Instant};

use chrono::{DateTime, Utc};
use mz_build_info::BuildInfo;
use mz_cloud_provider::{CloudProvider, InvalidCloudProviderError};
use mz_controller_types::{ClusterId, ReplicaId};
use mz_expr::MirScalarExpr;
use mz_ore::now::{EpochMillis, NowFn};
Expand Down Expand Up @@ -1186,80 +1187,6 @@ impl From<InvalidCloudProviderError> for InvalidEnvironmentIdError {
}
}

/// Identifies a supported cloud provider.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum CloudProvider {
/// A pseudo-provider value used by local development environments.
Local,
/// A pseudo-provider value used by Docker.
Docker,
/// A deprecated psuedo-provider value used by mzcompose.
// TODO(benesch): remove once v0.39 ships.
MzCompose,
/// A pseudo-provider value used by cloudtest.
Cloudtest,
/// Amazon Web Services.
Aws,
/// Google Cloud Platform
Gcp,
/// Microsoft Azure
Azure,
/// Other generic cloud provider
Generic,
}

impl CloudProvider {
/// Returns true if this provider actually runs in the cloud
pub fn is_cloud(&self) -> bool {
matches!(self, Self::Aws | Self::Gcp | Self::Azure | Self::Generic)
}
}

impl fmt::Display for CloudProvider {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
CloudProvider::Local => f.write_str("local"),
CloudProvider::Docker => f.write_str("docker"),
CloudProvider::MzCompose => f.write_str("mzcompose"),
CloudProvider::Cloudtest => f.write_str("cloudtest"),
CloudProvider::Aws => f.write_str("aws"),
CloudProvider::Gcp => f.write_str("gcp"),
CloudProvider::Azure => f.write_str("azure"),
CloudProvider::Generic => f.write_str("generic"),
}
}
}

impl FromStr for CloudProvider {
type Err = InvalidCloudProviderError;

fn from_str(s: &str) -> Result<CloudProvider, InvalidCloudProviderError> {
match s.to_lowercase().as_ref() {
"local" => Ok(CloudProvider::Local),
"docker" => Ok(CloudProvider::Docker),
"mzcompose" => Ok(CloudProvider::MzCompose),
"cloudtest" => Ok(CloudProvider::Cloudtest),
"aws" => Ok(CloudProvider::Aws),
"gcp" => Ok(CloudProvider::Gcp),
"azure" => Ok(CloudProvider::Azure),
"generic" => Ok(CloudProvider::Generic),
_ => Err(InvalidCloudProviderError),
}
}
}

/// The error type for [`CloudProvider::from_str`].
#[derive(Debug, Clone, PartialEq)]
pub struct InvalidCloudProviderError;

impl fmt::Display for InvalidCloudProviderError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("invalid cloud provider")
}
}

impl Error for InvalidCloudProviderError {}

/// An error returned by the catalog.
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum CatalogError {
Expand Down

0 comments on commit 3b0aaa8

Please sign in to comment.