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

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

-- |
-- Module      : Amazonka.MGN.StartTest
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Lauches a Test Instance for specific Source Servers. This command starts
-- a LAUNCH job whose initiatedBy property is StartTest and changes the
-- SourceServer.lifeCycle.state property to TESTING.
module Amazonka.MGN.StartTest
  ( -- * Creating a Request
    StartTest (..),
    newStartTest,

    -- * Request Lenses
    startTest_tags,
    startTest_sourceServerIDs,

    -- * Destructuring the Response
    StartTestResponse (..),
    newStartTestResponse,

    -- * Response Lenses
    startTestResponse_job,
    startTestResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.MGN.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newStartTest' smart constructor.
data StartTest = StartTest'
  { -- | Start Test by Tags.
    StartTest -> Maybe (Sensitive (HashMap Text Text))
tags :: Prelude.Maybe (Core.Sensitive (Prelude.HashMap Prelude.Text Prelude.Text)),
    -- | Start Test for Source Server IDs.
    StartTest -> NonEmpty Text
sourceServerIDs :: Prelude.NonEmpty Prelude.Text
  }
  deriving (StartTest -> StartTest -> Bool
(StartTest -> StartTest -> Bool)
-> (StartTest -> StartTest -> Bool) -> Eq StartTest
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StartTest -> StartTest -> Bool
$c/= :: StartTest -> StartTest -> Bool
== :: StartTest -> StartTest -> Bool
$c== :: StartTest -> StartTest -> Bool
Prelude.Eq, Int -> StartTest -> ShowS
[StartTest] -> ShowS
StartTest -> String
(Int -> StartTest -> ShowS)
-> (StartTest -> String)
-> ([StartTest] -> ShowS)
-> Show StartTest
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StartTest] -> ShowS
$cshowList :: [StartTest] -> ShowS
show :: StartTest -> String
$cshow :: StartTest -> String
showsPrec :: Int -> StartTest -> ShowS
$cshowsPrec :: Int -> StartTest -> ShowS
Prelude.Show, (forall x. StartTest -> Rep StartTest x)
-> (forall x. Rep StartTest x -> StartTest) -> Generic StartTest
forall x. Rep StartTest x -> StartTest
forall x. StartTest -> Rep StartTest x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StartTest x -> StartTest
$cfrom :: forall x. StartTest -> Rep StartTest x
Prelude.Generic)

-- |
-- Create a value of 'StartTest' 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:
--
-- 'tags', 'startTest_tags' - Start Test by Tags.
--
-- 'sourceServerIDs', 'startTest_sourceServerIDs' - Start Test for Source Server IDs.
newStartTest ::
  -- | 'sourceServerIDs'
  Prelude.NonEmpty Prelude.Text ->
  StartTest
newStartTest :: NonEmpty Text -> StartTest
newStartTest NonEmpty Text
pSourceServerIDs_ =
  StartTest' :: Maybe (Sensitive (HashMap Text Text)) -> NonEmpty Text -> StartTest
StartTest'
    { $sel:tags:StartTest' :: Maybe (Sensitive (HashMap Text Text))
tags = Maybe (Sensitive (HashMap Text Text))
forall a. Maybe a
Prelude.Nothing,
      $sel:sourceServerIDs:StartTest' :: NonEmpty Text
sourceServerIDs =
        Tagged (NonEmpty Text) (Identity (NonEmpty Text))
-> Tagged (NonEmpty Text) (Identity (NonEmpty Text))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged (NonEmpty Text) (Identity (NonEmpty Text))
 -> Tagged (NonEmpty Text) (Identity (NonEmpty Text)))
-> NonEmpty Text -> NonEmpty Text
forall t b. AReview t b -> b -> t
Lens.# NonEmpty Text
pSourceServerIDs_
    }

-- | Start Test by Tags.
startTest_tags :: Lens.Lens' StartTest (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
startTest_tags :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> StartTest -> f StartTest
startTest_tags = (StartTest -> Maybe (Sensitive (HashMap Text Text)))
-> (StartTest
    -> Maybe (Sensitive (HashMap Text Text)) -> StartTest)
-> Lens
     StartTest
     StartTest
     (Maybe (Sensitive (HashMap Text Text)))
     (Maybe (Sensitive (HashMap Text Text)))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartTest' {Maybe (Sensitive (HashMap Text Text))
tags :: Maybe (Sensitive (HashMap Text Text))
$sel:tags:StartTest' :: StartTest -> Maybe (Sensitive (HashMap Text Text))
tags} -> Maybe (Sensitive (HashMap Text Text))
tags) (\s :: StartTest
s@StartTest' {} Maybe (Sensitive (HashMap Text Text))
a -> StartTest
s {$sel:tags:StartTest' :: Maybe (Sensitive (HashMap Text Text))
tags = Maybe (Sensitive (HashMap Text Text))
a} :: StartTest) ((Maybe (Sensitive (HashMap Text Text))
  -> f (Maybe (Sensitive (HashMap Text Text))))
 -> StartTest -> f StartTest)
-> ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
    -> Maybe (Sensitive (HashMap Text Text))
    -> f (Maybe (Sensitive (HashMap Text Text))))
-> (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> StartTest
-> f StartTest
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (Sensitive (HashMap Text Text))
  (Sensitive (HashMap Text Text))
  (HashMap Text Text)
  (HashMap Text Text)
-> Iso
     (Maybe (Sensitive (HashMap Text Text)))
     (Maybe (Sensitive (HashMap Text Text)))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
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 (AnIso
  (Sensitive (HashMap Text Text))
  (Sensitive (HashMap Text Text))
  (HashMap Text Text)
  (HashMap Text Text)
forall a. Iso' (Sensitive a) a
Core._Sensitive AnIso
  (Sensitive (HashMap Text Text))
  (Sensitive (HashMap Text Text))
  (HashMap Text Text)
  (HashMap Text Text)
-> (Exchange
      (HashMap Text Text)
      (HashMap Text Text)
      (HashMap Text Text)
      (Identity (HashMap Text Text))
    -> Exchange
         (HashMap Text Text)
         (HashMap Text Text)
         (HashMap Text Text)
         (Identity (HashMap Text Text)))
-> AnIso
     (Sensitive (HashMap Text Text))
     (Sensitive (HashMap Text Text))
     (HashMap Text Text)
     (HashMap Text Text)
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. Exchange
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (Identity (HashMap Text Text))
-> Exchange
     (HashMap Text Text)
     (HashMap Text Text)
     (HashMap Text Text)
     (Identity (HashMap Text Text))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced)

-- | Start Test for Source Server IDs.
startTest_sourceServerIDs :: Lens.Lens' StartTest (Prelude.NonEmpty Prelude.Text)
startTest_sourceServerIDs :: (NonEmpty Text -> f (NonEmpty Text)) -> StartTest -> f StartTest
startTest_sourceServerIDs = (StartTest -> NonEmpty Text)
-> (StartTest -> NonEmpty Text -> StartTest)
-> Lens StartTest StartTest (NonEmpty Text) (NonEmpty Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartTest' {NonEmpty Text
sourceServerIDs :: NonEmpty Text
$sel:sourceServerIDs:StartTest' :: StartTest -> NonEmpty Text
sourceServerIDs} -> NonEmpty Text
sourceServerIDs) (\s :: StartTest
s@StartTest' {} NonEmpty Text
a -> StartTest
s {$sel:sourceServerIDs:StartTest' :: NonEmpty Text
sourceServerIDs = NonEmpty Text
a} :: StartTest) ((NonEmpty Text -> f (NonEmpty Text)) -> StartTest -> f StartTest)
-> ((NonEmpty Text -> f (NonEmpty Text))
    -> NonEmpty Text -> f (NonEmpty Text))
-> (NonEmpty Text -> f (NonEmpty Text))
-> StartTest
-> f StartTest
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty Text -> f (NonEmpty Text))
-> NonEmpty Text -> f (NonEmpty Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest StartTest where
  type AWSResponse StartTest = StartTestResponse
  request :: StartTest -> Request StartTest
request = Service -> StartTest -> Request StartTest
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy StartTest
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse StartTest)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse StartTest))
-> Logger
-> Service
-> Proxy StartTest
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse StartTest)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Job -> Int -> StartTestResponse
StartTestResponse'
            (Maybe Job -> Int -> StartTestResponse)
-> Either String (Maybe Job)
-> Either String (Int -> StartTestResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Job)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"job")
            Either String (Int -> StartTestResponse)
-> Either String Int -> Either String StartTestResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable StartTest

instance Prelude.NFData StartTest

instance Core.ToHeaders StartTest where
  toHeaders :: StartTest -> ResponseHeaders
toHeaders =
    ResponseHeaders -> StartTest -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON StartTest where
  toJSON :: StartTest -> Value
toJSON StartTest' {Maybe (Sensitive (HashMap Text Text))
NonEmpty Text
sourceServerIDs :: NonEmpty Text
tags :: Maybe (Sensitive (HashMap Text Text))
$sel:sourceServerIDs:StartTest' :: StartTest -> NonEmpty Text
$sel:tags:StartTest' :: StartTest -> Maybe (Sensitive (HashMap Text Text))
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"tags" Text -> Sensitive (HashMap Text Text) -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Sensitive (HashMap Text Text) -> Pair)
-> Maybe (Sensitive (HashMap Text Text)) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (Sensitive (HashMap Text Text))
tags,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"sourceServerIDs" Text -> NonEmpty Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NonEmpty Text
sourceServerIDs)
          ]
      )

instance Core.ToPath StartTest where
  toPath :: StartTest -> ByteString
toPath = ByteString -> StartTest -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/StartTest"

instance Core.ToQuery StartTest where
  toQuery :: StartTest -> QueryString
toQuery = QueryString -> StartTest -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newStartTestResponse' smart constructor.
data StartTestResponse = StartTestResponse'
  { -- | Start Test Job response.
    StartTestResponse -> Maybe Job
job :: Prelude.Maybe Job,
    -- | The response's http status code.
    StartTestResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (StartTestResponse -> StartTestResponse -> Bool
(StartTestResponse -> StartTestResponse -> Bool)
-> (StartTestResponse -> StartTestResponse -> Bool)
-> Eq StartTestResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StartTestResponse -> StartTestResponse -> Bool
$c/= :: StartTestResponse -> StartTestResponse -> Bool
== :: StartTestResponse -> StartTestResponse -> Bool
$c== :: StartTestResponse -> StartTestResponse -> Bool
Prelude.Eq, Int -> StartTestResponse -> ShowS
[StartTestResponse] -> ShowS
StartTestResponse -> String
(Int -> StartTestResponse -> ShowS)
-> (StartTestResponse -> String)
-> ([StartTestResponse] -> ShowS)
-> Show StartTestResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StartTestResponse] -> ShowS
$cshowList :: [StartTestResponse] -> ShowS
show :: StartTestResponse -> String
$cshow :: StartTestResponse -> String
showsPrec :: Int -> StartTestResponse -> ShowS
$cshowsPrec :: Int -> StartTestResponse -> ShowS
Prelude.Show, (forall x. StartTestResponse -> Rep StartTestResponse x)
-> (forall x. Rep StartTestResponse x -> StartTestResponse)
-> Generic StartTestResponse
forall x. Rep StartTestResponse x -> StartTestResponse
forall x. StartTestResponse -> Rep StartTestResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StartTestResponse x -> StartTestResponse
$cfrom :: forall x. StartTestResponse -> Rep StartTestResponse x
Prelude.Generic)

-- |
-- Create a value of 'StartTestResponse' 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:
--
-- 'job', 'startTestResponse_job' - Start Test Job response.
--
-- 'httpStatus', 'startTestResponse_httpStatus' - The response's http status code.
newStartTestResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  StartTestResponse
newStartTestResponse :: Int -> StartTestResponse
newStartTestResponse Int
pHttpStatus_ =
  StartTestResponse' :: Maybe Job -> Int -> StartTestResponse
StartTestResponse'
    { $sel:job:StartTestResponse' :: Maybe Job
job = Maybe Job
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:StartTestResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Start Test Job response.
startTestResponse_job :: Lens.Lens' StartTestResponse (Prelude.Maybe Job)
startTestResponse_job :: (Maybe Job -> f (Maybe Job))
-> StartTestResponse -> f StartTestResponse
startTestResponse_job = (StartTestResponse -> Maybe Job)
-> (StartTestResponse -> Maybe Job -> StartTestResponse)
-> Lens StartTestResponse StartTestResponse (Maybe Job) (Maybe Job)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartTestResponse' {Maybe Job
job :: Maybe Job
$sel:job:StartTestResponse' :: StartTestResponse -> Maybe Job
job} -> Maybe Job
job) (\s :: StartTestResponse
s@StartTestResponse' {} Maybe Job
a -> StartTestResponse
s {$sel:job:StartTestResponse' :: Maybe Job
job = Maybe Job
a} :: StartTestResponse)

-- | The response's http status code.
startTestResponse_httpStatus :: Lens.Lens' StartTestResponse Prelude.Int
startTestResponse_httpStatus :: (Int -> f Int) -> StartTestResponse -> f StartTestResponse
startTestResponse_httpStatus = (StartTestResponse -> Int)
-> (StartTestResponse -> Int -> StartTestResponse)
-> Lens StartTestResponse StartTestResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartTestResponse' {Int
httpStatus :: Int
$sel:httpStatus:StartTestResponse' :: StartTestResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: StartTestResponse
s@StartTestResponse' {} Int
a -> StartTestResponse
s {$sel:httpStatus:StartTestResponse' :: Int
httpStatus = Int
a} :: StartTestResponse)

instance Prelude.NFData StartTestResponse