{-# 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.Proton.CancelServiceInstanceDeployment
-- 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)
--
-- Attempts to cancel a service instance deployment on an
-- UpdateServiceInstance action, if the deployment is @IN_PROGRESS@. For
-- more information, see /Update a service instance/ in the
-- <https://docs.aws.amazon.com/proton/latest/adminguide/ag-svc-instance-update.html AWS Proton Administrator guide>
-- or the
-- <https://docs.aws.amazon.com/proton/latest/userguide/ug-svc-instance-update.html AWS Proton User guide>.
--
-- The following list includes potential cancellation scenarios.
--
-- -   If the cancellation attempt succeeds, the resulting deployment state
--     is @CANCELLED@.
--
-- -   If the cancellation attempt fails, the resulting deployment state is
--     @FAILED@.
--
-- -   If the current UpdateServiceInstance action succeeds before the
--     cancellation attempt starts, the resulting deployment state is
--     @SUCCEEDED@ and the cancellation attempt has no effect.
module Amazonka.Proton.CancelServiceInstanceDeployment
  ( -- * Creating a Request
    CancelServiceInstanceDeployment (..),
    newCancelServiceInstanceDeployment,

    -- * Request Lenses
    cancelServiceInstanceDeployment_serviceInstanceName,
    cancelServiceInstanceDeployment_serviceName,

    -- * Destructuring the Response
    CancelServiceInstanceDeploymentResponse (..),
    newCancelServiceInstanceDeploymentResponse,

    -- * Response Lenses
    cancelServiceInstanceDeploymentResponse_httpStatus,
    cancelServiceInstanceDeploymentResponse_serviceInstance,
  )
where

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

-- | /See:/ 'newCancelServiceInstanceDeployment' smart constructor.
data CancelServiceInstanceDeployment = CancelServiceInstanceDeployment'
  { -- | The name of the service instance with the deployment to cancel.
    CancelServiceInstanceDeployment -> Text
serviceInstanceName :: Prelude.Text,
    -- | The name of the service with the service instance deployment to cancel.
    CancelServiceInstanceDeployment -> Text
serviceName :: Prelude.Text
  }
  deriving (CancelServiceInstanceDeployment
-> CancelServiceInstanceDeployment -> Bool
(CancelServiceInstanceDeployment
 -> CancelServiceInstanceDeployment -> Bool)
-> (CancelServiceInstanceDeployment
    -> CancelServiceInstanceDeployment -> Bool)
-> Eq CancelServiceInstanceDeployment
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CancelServiceInstanceDeployment
-> CancelServiceInstanceDeployment -> Bool
$c/= :: CancelServiceInstanceDeployment
-> CancelServiceInstanceDeployment -> Bool
== :: CancelServiceInstanceDeployment
-> CancelServiceInstanceDeployment -> Bool
$c== :: CancelServiceInstanceDeployment
-> CancelServiceInstanceDeployment -> Bool
Prelude.Eq, ReadPrec [CancelServiceInstanceDeployment]
ReadPrec CancelServiceInstanceDeployment
Int -> ReadS CancelServiceInstanceDeployment
ReadS [CancelServiceInstanceDeployment]
(Int -> ReadS CancelServiceInstanceDeployment)
-> ReadS [CancelServiceInstanceDeployment]
-> ReadPrec CancelServiceInstanceDeployment
-> ReadPrec [CancelServiceInstanceDeployment]
-> Read CancelServiceInstanceDeployment
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CancelServiceInstanceDeployment]
$creadListPrec :: ReadPrec [CancelServiceInstanceDeployment]
readPrec :: ReadPrec CancelServiceInstanceDeployment
$creadPrec :: ReadPrec CancelServiceInstanceDeployment
readList :: ReadS [CancelServiceInstanceDeployment]
$creadList :: ReadS [CancelServiceInstanceDeployment]
readsPrec :: Int -> ReadS CancelServiceInstanceDeployment
$creadsPrec :: Int -> ReadS CancelServiceInstanceDeployment
Prelude.Read, Int -> CancelServiceInstanceDeployment -> ShowS
[CancelServiceInstanceDeployment] -> ShowS
CancelServiceInstanceDeployment -> String
(Int -> CancelServiceInstanceDeployment -> ShowS)
-> (CancelServiceInstanceDeployment -> String)
-> ([CancelServiceInstanceDeployment] -> ShowS)
-> Show CancelServiceInstanceDeployment
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CancelServiceInstanceDeployment] -> ShowS
$cshowList :: [CancelServiceInstanceDeployment] -> ShowS
show :: CancelServiceInstanceDeployment -> String
$cshow :: CancelServiceInstanceDeployment -> String
showsPrec :: Int -> CancelServiceInstanceDeployment -> ShowS
$cshowsPrec :: Int -> CancelServiceInstanceDeployment -> ShowS
Prelude.Show, (forall x.
 CancelServiceInstanceDeployment
 -> Rep CancelServiceInstanceDeployment x)
-> (forall x.
    Rep CancelServiceInstanceDeployment x
    -> CancelServiceInstanceDeployment)
-> Generic CancelServiceInstanceDeployment
forall x.
Rep CancelServiceInstanceDeployment x
-> CancelServiceInstanceDeployment
forall x.
CancelServiceInstanceDeployment
-> Rep CancelServiceInstanceDeployment x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CancelServiceInstanceDeployment x
-> CancelServiceInstanceDeployment
$cfrom :: forall x.
CancelServiceInstanceDeployment
-> Rep CancelServiceInstanceDeployment x
Prelude.Generic)

-- |
-- Create a value of 'CancelServiceInstanceDeployment' 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:
--
-- 'serviceInstanceName', 'cancelServiceInstanceDeployment_serviceInstanceName' - The name of the service instance with the deployment to cancel.
--
-- 'serviceName', 'cancelServiceInstanceDeployment_serviceName' - The name of the service with the service instance deployment to cancel.
newCancelServiceInstanceDeployment ::
  -- | 'serviceInstanceName'
  Prelude.Text ->
  -- | 'serviceName'
  Prelude.Text ->
  CancelServiceInstanceDeployment
newCancelServiceInstanceDeployment :: Text -> Text -> CancelServiceInstanceDeployment
newCancelServiceInstanceDeployment
  Text
pServiceInstanceName_
  Text
pServiceName_ =
    CancelServiceInstanceDeployment' :: Text -> Text -> CancelServiceInstanceDeployment
CancelServiceInstanceDeployment'
      { $sel:serviceInstanceName:CancelServiceInstanceDeployment' :: Text
serviceInstanceName =
          Text
pServiceInstanceName_,
        $sel:serviceName:CancelServiceInstanceDeployment' :: Text
serviceName = Text
pServiceName_
      }

-- | The name of the service instance with the deployment to cancel.
cancelServiceInstanceDeployment_serviceInstanceName :: Lens.Lens' CancelServiceInstanceDeployment Prelude.Text
cancelServiceInstanceDeployment_serviceInstanceName :: (Text -> f Text)
-> CancelServiceInstanceDeployment
-> f CancelServiceInstanceDeployment
cancelServiceInstanceDeployment_serviceInstanceName = (CancelServiceInstanceDeployment -> Text)
-> (CancelServiceInstanceDeployment
    -> Text -> CancelServiceInstanceDeployment)
-> Lens
     CancelServiceInstanceDeployment
     CancelServiceInstanceDeployment
     Text
     Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CancelServiceInstanceDeployment' {Text
serviceInstanceName :: Text
$sel:serviceInstanceName:CancelServiceInstanceDeployment' :: CancelServiceInstanceDeployment -> Text
serviceInstanceName} -> Text
serviceInstanceName) (\s :: CancelServiceInstanceDeployment
s@CancelServiceInstanceDeployment' {} Text
a -> CancelServiceInstanceDeployment
s {$sel:serviceInstanceName:CancelServiceInstanceDeployment' :: Text
serviceInstanceName = Text
a} :: CancelServiceInstanceDeployment)

-- | The name of the service with the service instance deployment to cancel.
cancelServiceInstanceDeployment_serviceName :: Lens.Lens' CancelServiceInstanceDeployment Prelude.Text
cancelServiceInstanceDeployment_serviceName :: (Text -> f Text)
-> CancelServiceInstanceDeployment
-> f CancelServiceInstanceDeployment
cancelServiceInstanceDeployment_serviceName = (CancelServiceInstanceDeployment -> Text)
-> (CancelServiceInstanceDeployment
    -> Text -> CancelServiceInstanceDeployment)
-> Lens
     CancelServiceInstanceDeployment
     CancelServiceInstanceDeployment
     Text
     Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CancelServiceInstanceDeployment' {Text
serviceName :: Text
$sel:serviceName:CancelServiceInstanceDeployment' :: CancelServiceInstanceDeployment -> Text
serviceName} -> Text
serviceName) (\s :: CancelServiceInstanceDeployment
s@CancelServiceInstanceDeployment' {} Text
a -> CancelServiceInstanceDeployment
s {$sel:serviceName:CancelServiceInstanceDeployment' :: Text
serviceName = Text
a} :: CancelServiceInstanceDeployment)

instance
  Core.AWSRequest
    CancelServiceInstanceDeployment
  where
  type
    AWSResponse CancelServiceInstanceDeployment =
      CancelServiceInstanceDeploymentResponse
  request :: CancelServiceInstanceDeployment
-> Request CancelServiceInstanceDeployment
request = Service
-> CancelServiceInstanceDeployment
-> Request CancelServiceInstanceDeployment
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CancelServiceInstanceDeployment
-> ClientResponse ClientBody
-> m (Either
        Error
        (ClientResponse (AWSResponse CancelServiceInstanceDeployment)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse CancelServiceInstanceDeployment))
-> Logger
-> Service
-> Proxy CancelServiceInstanceDeployment
-> ClientResponse ClientBody
-> m (Either
        Error
        (ClientResponse (AWSResponse CancelServiceInstanceDeployment)))
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 ->
          Int -> ServiceInstance -> CancelServiceInstanceDeploymentResponse
CancelServiceInstanceDeploymentResponse'
            (Int -> ServiceInstance -> CancelServiceInstanceDeploymentResponse)
-> Either String Int
-> Either
     String (ServiceInstance -> CancelServiceInstanceDeploymentResponse)
forall (f :: * -> *) a b. Functor 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))
            Either
  String (ServiceInstance -> CancelServiceInstanceDeploymentResponse)
-> Either String ServiceInstance
-> Either String CancelServiceInstanceDeploymentResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String ServiceInstance
forall a. FromJSON a => Object -> Text -> Either String a
Core..:> Text
"serviceInstance")
      )

instance
  Prelude.Hashable
    CancelServiceInstanceDeployment

instance
  Prelude.NFData
    CancelServiceInstanceDeployment

instance
  Core.ToHeaders
    CancelServiceInstanceDeployment
  where
  toHeaders :: CancelServiceInstanceDeployment -> ResponseHeaders
toHeaders =
    ResponseHeaders
-> CancelServiceInstanceDeployment -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"AwsProton20200720.CancelServiceInstanceDeployment" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.0" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON CancelServiceInstanceDeployment where
  toJSON :: CancelServiceInstanceDeployment -> Value
toJSON CancelServiceInstanceDeployment' {Text
serviceName :: Text
serviceInstanceName :: Text
$sel:serviceName:CancelServiceInstanceDeployment' :: CancelServiceInstanceDeployment -> Text
$sel:serviceInstanceName:CancelServiceInstanceDeployment' :: CancelServiceInstanceDeployment -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"serviceInstanceName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
serviceInstanceName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"serviceName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
serviceName)
          ]
      )

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

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

-- | /See:/ 'newCancelServiceInstanceDeploymentResponse' smart constructor.
data CancelServiceInstanceDeploymentResponse = CancelServiceInstanceDeploymentResponse'
  { -- | The response's http status code.
    CancelServiceInstanceDeploymentResponse -> Int
httpStatus :: Prelude.Int,
    -- | The service instance summary data that\'s returned by AWS Proton.
    CancelServiceInstanceDeploymentResponse -> ServiceInstance
serviceInstance :: ServiceInstance
  }
  deriving (CancelServiceInstanceDeploymentResponse
-> CancelServiceInstanceDeploymentResponse -> Bool
(CancelServiceInstanceDeploymentResponse
 -> CancelServiceInstanceDeploymentResponse -> Bool)
-> (CancelServiceInstanceDeploymentResponse
    -> CancelServiceInstanceDeploymentResponse -> Bool)
-> Eq CancelServiceInstanceDeploymentResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CancelServiceInstanceDeploymentResponse
-> CancelServiceInstanceDeploymentResponse -> Bool
$c/= :: CancelServiceInstanceDeploymentResponse
-> CancelServiceInstanceDeploymentResponse -> Bool
== :: CancelServiceInstanceDeploymentResponse
-> CancelServiceInstanceDeploymentResponse -> Bool
$c== :: CancelServiceInstanceDeploymentResponse
-> CancelServiceInstanceDeploymentResponse -> Bool
Prelude.Eq, Int -> CancelServiceInstanceDeploymentResponse -> ShowS
[CancelServiceInstanceDeploymentResponse] -> ShowS
CancelServiceInstanceDeploymentResponse -> String
(Int -> CancelServiceInstanceDeploymentResponse -> ShowS)
-> (CancelServiceInstanceDeploymentResponse -> String)
-> ([CancelServiceInstanceDeploymentResponse] -> ShowS)
-> Show CancelServiceInstanceDeploymentResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CancelServiceInstanceDeploymentResponse] -> ShowS
$cshowList :: [CancelServiceInstanceDeploymentResponse] -> ShowS
show :: CancelServiceInstanceDeploymentResponse -> String
$cshow :: CancelServiceInstanceDeploymentResponse -> String
showsPrec :: Int -> CancelServiceInstanceDeploymentResponse -> ShowS
$cshowsPrec :: Int -> CancelServiceInstanceDeploymentResponse -> ShowS
Prelude.Show, (forall x.
 CancelServiceInstanceDeploymentResponse
 -> Rep CancelServiceInstanceDeploymentResponse x)
-> (forall x.
    Rep CancelServiceInstanceDeploymentResponse x
    -> CancelServiceInstanceDeploymentResponse)
-> Generic CancelServiceInstanceDeploymentResponse
forall x.
Rep CancelServiceInstanceDeploymentResponse x
-> CancelServiceInstanceDeploymentResponse
forall x.
CancelServiceInstanceDeploymentResponse
-> Rep CancelServiceInstanceDeploymentResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CancelServiceInstanceDeploymentResponse x
-> CancelServiceInstanceDeploymentResponse
$cfrom :: forall x.
CancelServiceInstanceDeploymentResponse
-> Rep CancelServiceInstanceDeploymentResponse x
Prelude.Generic)

-- |
-- Create a value of 'CancelServiceInstanceDeploymentResponse' 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:
--
-- 'httpStatus', 'cancelServiceInstanceDeploymentResponse_httpStatus' - The response's http status code.
--
-- 'serviceInstance', 'cancelServiceInstanceDeploymentResponse_serviceInstance' - The service instance summary data that\'s returned by AWS Proton.
newCancelServiceInstanceDeploymentResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'serviceInstance'
  ServiceInstance ->
  CancelServiceInstanceDeploymentResponse
newCancelServiceInstanceDeploymentResponse :: Int -> ServiceInstance -> CancelServiceInstanceDeploymentResponse
newCancelServiceInstanceDeploymentResponse
  Int
pHttpStatus_
  ServiceInstance
pServiceInstance_ =
    CancelServiceInstanceDeploymentResponse' :: Int -> ServiceInstance -> CancelServiceInstanceDeploymentResponse
CancelServiceInstanceDeploymentResponse'
      { $sel:httpStatus:CancelServiceInstanceDeploymentResponse' :: Int
httpStatus =
          Int
pHttpStatus_,
        $sel:serviceInstance:CancelServiceInstanceDeploymentResponse' :: ServiceInstance
serviceInstance =
          ServiceInstance
pServiceInstance_
      }

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

-- | The service instance summary data that\'s returned by AWS Proton.
cancelServiceInstanceDeploymentResponse_serviceInstance :: Lens.Lens' CancelServiceInstanceDeploymentResponse ServiceInstance
cancelServiceInstanceDeploymentResponse_serviceInstance :: (ServiceInstance -> f ServiceInstance)
-> CancelServiceInstanceDeploymentResponse
-> f CancelServiceInstanceDeploymentResponse
cancelServiceInstanceDeploymentResponse_serviceInstance = (CancelServiceInstanceDeploymentResponse -> ServiceInstance)
-> (CancelServiceInstanceDeploymentResponse
    -> ServiceInstance -> CancelServiceInstanceDeploymentResponse)
-> Lens
     CancelServiceInstanceDeploymentResponse
     CancelServiceInstanceDeploymentResponse
     ServiceInstance
     ServiceInstance
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CancelServiceInstanceDeploymentResponse' {ServiceInstance
serviceInstance :: ServiceInstance
$sel:serviceInstance:CancelServiceInstanceDeploymentResponse' :: CancelServiceInstanceDeploymentResponse -> ServiceInstance
serviceInstance} -> ServiceInstance
serviceInstance) (\s :: CancelServiceInstanceDeploymentResponse
s@CancelServiceInstanceDeploymentResponse' {} ServiceInstance
a -> CancelServiceInstanceDeploymentResponse
s {$sel:serviceInstance:CancelServiceInstanceDeploymentResponse' :: ServiceInstance
serviceInstance = ServiceInstance
a} :: CancelServiceInstanceDeploymentResponse)

instance
  Prelude.NFData
    CancelServiceInstanceDeploymentResponse