{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.SageMaker.Types.DeviceSelectionConfig
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.SageMaker.Types.DeviceSelectionConfig where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude
import Amazonka.SageMaker.Types.DeviceSubsetType

-- | Contains information about the configurations of selected devices.
--
-- /See:/ 'newDeviceSelectionConfig' smart constructor.
data DeviceSelectionConfig = DeviceSelectionConfig'
  { -- | A filter to select devices with names containing this name.
    DeviceSelectionConfig -> Maybe Text
deviceNameContains :: Prelude.Maybe Prelude.Text,
    -- | List of devices chosen to deploy.
    DeviceSelectionConfig -> Maybe [Text]
deviceNames :: Prelude.Maybe [Prelude.Text],
    -- | Percentage of devices in the fleet to deploy to the current stage.
    DeviceSelectionConfig -> Maybe Int
percentage :: Prelude.Maybe Prelude.Int,
    -- | Type of device subsets to deploy to the current stage.
    DeviceSelectionConfig -> DeviceSubsetType
deviceSubsetType :: DeviceSubsetType
  }
  deriving (DeviceSelectionConfig -> DeviceSelectionConfig -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeviceSelectionConfig -> DeviceSelectionConfig -> Bool
$c/= :: DeviceSelectionConfig -> DeviceSelectionConfig -> Bool
== :: DeviceSelectionConfig -> DeviceSelectionConfig -> Bool
$c== :: DeviceSelectionConfig -> DeviceSelectionConfig -> Bool
Prelude.Eq, ReadPrec [DeviceSelectionConfig]
ReadPrec DeviceSelectionConfig
Int -> ReadS DeviceSelectionConfig
ReadS [DeviceSelectionConfig]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeviceSelectionConfig]
$creadListPrec :: ReadPrec [DeviceSelectionConfig]
readPrec :: ReadPrec DeviceSelectionConfig
$creadPrec :: ReadPrec DeviceSelectionConfig
readList :: ReadS [DeviceSelectionConfig]
$creadList :: ReadS [DeviceSelectionConfig]
readsPrec :: Int -> ReadS DeviceSelectionConfig
$creadsPrec :: Int -> ReadS DeviceSelectionConfig
Prelude.Read, Int -> DeviceSelectionConfig -> ShowS
[DeviceSelectionConfig] -> ShowS
DeviceSelectionConfig -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeviceSelectionConfig] -> ShowS
$cshowList :: [DeviceSelectionConfig] -> ShowS
show :: DeviceSelectionConfig -> String
$cshow :: DeviceSelectionConfig -> String
showsPrec :: Int -> DeviceSelectionConfig -> ShowS
$cshowsPrec :: Int -> DeviceSelectionConfig -> ShowS
Prelude.Show, forall x. Rep DeviceSelectionConfig x -> DeviceSelectionConfig
forall x. DeviceSelectionConfig -> Rep DeviceSelectionConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeviceSelectionConfig x -> DeviceSelectionConfig
$cfrom :: forall x. DeviceSelectionConfig -> Rep DeviceSelectionConfig x
Prelude.Generic)

-- |
-- Create a value of 'DeviceSelectionConfig' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'deviceNameContains', 'deviceSelectionConfig_deviceNameContains' - A filter to select devices with names containing this name.
--
-- 'deviceNames', 'deviceSelectionConfig_deviceNames' - List of devices chosen to deploy.
--
-- 'percentage', 'deviceSelectionConfig_percentage' - Percentage of devices in the fleet to deploy to the current stage.
--
-- 'deviceSubsetType', 'deviceSelectionConfig_deviceSubsetType' - Type of device subsets to deploy to the current stage.
newDeviceSelectionConfig ::
  -- | 'deviceSubsetType'
  DeviceSubsetType ->
  DeviceSelectionConfig
newDeviceSelectionConfig :: DeviceSubsetType -> DeviceSelectionConfig
newDeviceSelectionConfig DeviceSubsetType
pDeviceSubsetType_ =
  DeviceSelectionConfig'
    { $sel:deviceNameContains:DeviceSelectionConfig' :: Maybe Text
deviceNameContains =
        forall a. Maybe a
Prelude.Nothing,
      $sel:deviceNames:DeviceSelectionConfig' :: Maybe [Text]
deviceNames = forall a. Maybe a
Prelude.Nothing,
      $sel:percentage:DeviceSelectionConfig' :: Maybe Int
percentage = forall a. Maybe a
Prelude.Nothing,
      $sel:deviceSubsetType:DeviceSelectionConfig' :: DeviceSubsetType
deviceSubsetType = DeviceSubsetType
pDeviceSubsetType_
    }

-- | A filter to select devices with names containing this name.
deviceSelectionConfig_deviceNameContains :: Lens.Lens' DeviceSelectionConfig (Prelude.Maybe Prelude.Text)
deviceSelectionConfig_deviceNameContains :: Lens' DeviceSelectionConfig (Maybe Text)
deviceSelectionConfig_deviceNameContains = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeviceSelectionConfig' {Maybe Text
deviceNameContains :: Maybe Text
$sel:deviceNameContains:DeviceSelectionConfig' :: DeviceSelectionConfig -> Maybe Text
deviceNameContains} -> Maybe Text
deviceNameContains) (\s :: DeviceSelectionConfig
s@DeviceSelectionConfig' {} Maybe Text
a -> DeviceSelectionConfig
s {$sel:deviceNameContains:DeviceSelectionConfig' :: Maybe Text
deviceNameContains = Maybe Text
a} :: DeviceSelectionConfig)

-- | List of devices chosen to deploy.
deviceSelectionConfig_deviceNames :: Lens.Lens' DeviceSelectionConfig (Prelude.Maybe [Prelude.Text])
deviceSelectionConfig_deviceNames :: Lens' DeviceSelectionConfig (Maybe [Text])
deviceSelectionConfig_deviceNames = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeviceSelectionConfig' {Maybe [Text]
deviceNames :: Maybe [Text]
$sel:deviceNames:DeviceSelectionConfig' :: DeviceSelectionConfig -> Maybe [Text]
deviceNames} -> Maybe [Text]
deviceNames) (\s :: DeviceSelectionConfig
s@DeviceSelectionConfig' {} Maybe [Text]
a -> DeviceSelectionConfig
s {$sel:deviceNames:DeviceSelectionConfig' :: Maybe [Text]
deviceNames = Maybe [Text]
a} :: DeviceSelectionConfig) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Percentage of devices in the fleet to deploy to the current stage.
deviceSelectionConfig_percentage :: Lens.Lens' DeviceSelectionConfig (Prelude.Maybe Prelude.Int)
deviceSelectionConfig_percentage :: Lens' DeviceSelectionConfig (Maybe Int)
deviceSelectionConfig_percentage = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeviceSelectionConfig' {Maybe Int
percentage :: Maybe Int
$sel:percentage:DeviceSelectionConfig' :: DeviceSelectionConfig -> Maybe Int
percentage} -> Maybe Int
percentage) (\s :: DeviceSelectionConfig
s@DeviceSelectionConfig' {} Maybe Int
a -> DeviceSelectionConfig
s {$sel:percentage:DeviceSelectionConfig' :: Maybe Int
percentage = Maybe Int
a} :: DeviceSelectionConfig)

-- | Type of device subsets to deploy to the current stage.
deviceSelectionConfig_deviceSubsetType :: Lens.Lens' DeviceSelectionConfig DeviceSubsetType
deviceSelectionConfig_deviceSubsetType :: Lens' DeviceSelectionConfig DeviceSubsetType
deviceSelectionConfig_deviceSubsetType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeviceSelectionConfig' {DeviceSubsetType
deviceSubsetType :: DeviceSubsetType
$sel:deviceSubsetType:DeviceSelectionConfig' :: DeviceSelectionConfig -> DeviceSubsetType
deviceSubsetType} -> DeviceSubsetType
deviceSubsetType) (\s :: DeviceSelectionConfig
s@DeviceSelectionConfig' {} DeviceSubsetType
a -> DeviceSelectionConfig
s {$sel:deviceSubsetType:DeviceSelectionConfig' :: DeviceSubsetType
deviceSubsetType = DeviceSubsetType
a} :: DeviceSelectionConfig)

instance Data.FromJSON DeviceSelectionConfig where
  parseJSON :: Value -> Parser DeviceSelectionConfig
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"DeviceSelectionConfig"
      ( \Object
x ->
          Maybe Text
-> Maybe [Text]
-> Maybe Int
-> DeviceSubsetType
-> DeviceSelectionConfig
DeviceSelectionConfig'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"DeviceNameContains")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"DeviceNames" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Percentage")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"DeviceSubsetType")
      )

instance Prelude.Hashable DeviceSelectionConfig where
  hashWithSalt :: Int -> DeviceSelectionConfig -> Int
hashWithSalt Int
_salt DeviceSelectionConfig' {Maybe Int
Maybe [Text]
Maybe Text
DeviceSubsetType
deviceSubsetType :: DeviceSubsetType
percentage :: Maybe Int
deviceNames :: Maybe [Text]
deviceNameContains :: Maybe Text
$sel:deviceSubsetType:DeviceSelectionConfig' :: DeviceSelectionConfig -> DeviceSubsetType
$sel:percentage:DeviceSelectionConfig' :: DeviceSelectionConfig -> Maybe Int
$sel:deviceNames:DeviceSelectionConfig' :: DeviceSelectionConfig -> Maybe [Text]
$sel:deviceNameContains:DeviceSelectionConfig' :: DeviceSelectionConfig -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
deviceNameContains
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Text]
deviceNames
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Int
percentage
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` DeviceSubsetType
deviceSubsetType

instance Prelude.NFData DeviceSelectionConfig where
  rnf :: DeviceSelectionConfig -> ()
rnf DeviceSelectionConfig' {Maybe Int
Maybe [Text]
Maybe Text
DeviceSubsetType
deviceSubsetType :: DeviceSubsetType
percentage :: Maybe Int
deviceNames :: Maybe [Text]
deviceNameContains :: Maybe Text
$sel:deviceSubsetType:DeviceSelectionConfig' :: DeviceSelectionConfig -> DeviceSubsetType
$sel:percentage:DeviceSelectionConfig' :: DeviceSelectionConfig -> Maybe Int
$sel:deviceNames:DeviceSelectionConfig' :: DeviceSelectionConfig -> Maybe [Text]
$sel:deviceNameContains:DeviceSelectionConfig' :: DeviceSelectionConfig -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
deviceNameContains
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [Text]
deviceNames
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Int
percentage
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf DeviceSubsetType
deviceSubsetType

instance Data.ToJSON DeviceSelectionConfig where
  toJSON :: DeviceSelectionConfig -> Value
toJSON DeviceSelectionConfig' {Maybe Int
Maybe [Text]
Maybe Text
DeviceSubsetType
deviceSubsetType :: DeviceSubsetType
percentage :: Maybe Int
deviceNames :: Maybe [Text]
deviceNameContains :: Maybe Text
$sel:deviceSubsetType:DeviceSelectionConfig' :: DeviceSelectionConfig -> DeviceSubsetType
$sel:percentage:DeviceSelectionConfig' :: DeviceSelectionConfig -> Maybe Int
$sel:deviceNames:DeviceSelectionConfig' :: DeviceSelectionConfig -> Maybe [Text]
$sel:deviceNameContains:DeviceSelectionConfig' :: DeviceSelectionConfig -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"DeviceNameContains" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
deviceNameContains,
            (Key
"DeviceNames" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Text]
deviceNames,
            (Key
"Percentage" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Int
percentage,
            forall a. a -> Maybe a
Prelude.Just
              (Key
"DeviceSubsetType" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= DeviceSubsetType
deviceSubsetType)
          ]
      )