{-# 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.KinesisAnalytics.StartApplication
-- 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)
--
-- This documentation is for version 1 of the Amazon Kinesis Data Analytics
-- API, which only supports SQL applications. Version 2 of the API supports
-- SQL and Java applications. For more information about version 2, see
-- </kinesisanalytics/latest/apiv2/Welcome.html Amazon Kinesis Data Analytics API V2 Documentation>.
--
-- Starts the specified Amazon Kinesis Analytics application. After
-- creating an application, you must exclusively call this operation to
-- start your application.
--
-- After the application starts, it begins consuming the input data,
-- processes it, and writes the output to the configured destination.
--
-- The application status must be @READY@ for you to start an application.
-- You can get the application status in the console or using the
-- <https://docs.aws.amazon.com/kinesisanalytics/latest/dev/API_DescribeApplication.html DescribeApplication>
-- operation.
--
-- After you start the application, you can stop the application from
-- processing the input by calling the
-- <https://docs.aws.amazon.com/kinesisanalytics/latest/dev/API_StopApplication.html StopApplication>
-- operation.
--
-- This operation requires permissions to perform the
-- @kinesisanalytics:StartApplication@ action.
module Amazonka.KinesisAnalytics.StartApplication
  ( -- * Creating a Request
    StartApplication (..),
    newStartApplication,

    -- * Request Lenses
    startApplication_applicationName,
    startApplication_inputConfigurations,

    -- * Destructuring the Response
    StartApplicationResponse (..),
    newStartApplicationResponse,

    -- * Response Lenses
    startApplicationResponse_httpStatus,
  )
where

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

-- |
--
-- /See:/ 'newStartApplication' smart constructor.
data StartApplication = StartApplication'
  { -- | Name of the application.
    StartApplication -> Text
applicationName :: Prelude.Text,
    -- | Identifies the specific input, by ID, that the application starts
    -- consuming. Amazon Kinesis Analytics starts reading the streaming source
    -- associated with the input. You can also specify where in the streaming
    -- source you want Amazon Kinesis Analytics to start reading.
    StartApplication -> [InputConfiguration]
inputConfigurations :: [InputConfiguration]
  }
  deriving (StartApplication -> StartApplication -> Bool
(StartApplication -> StartApplication -> Bool)
-> (StartApplication -> StartApplication -> Bool)
-> Eq StartApplication
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StartApplication -> StartApplication -> Bool
$c/= :: StartApplication -> StartApplication -> Bool
== :: StartApplication -> StartApplication -> Bool
$c== :: StartApplication -> StartApplication -> Bool
Prelude.Eq, ReadPrec [StartApplication]
ReadPrec StartApplication
Int -> ReadS StartApplication
ReadS [StartApplication]
(Int -> ReadS StartApplication)
-> ReadS [StartApplication]
-> ReadPrec StartApplication
-> ReadPrec [StartApplication]
-> Read StartApplication
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StartApplication]
$creadListPrec :: ReadPrec [StartApplication]
readPrec :: ReadPrec StartApplication
$creadPrec :: ReadPrec StartApplication
readList :: ReadS [StartApplication]
$creadList :: ReadS [StartApplication]
readsPrec :: Int -> ReadS StartApplication
$creadsPrec :: Int -> ReadS StartApplication
Prelude.Read, Int -> StartApplication -> ShowS
[StartApplication] -> ShowS
StartApplication -> String
(Int -> StartApplication -> ShowS)
-> (StartApplication -> String)
-> ([StartApplication] -> ShowS)
-> Show StartApplication
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StartApplication] -> ShowS
$cshowList :: [StartApplication] -> ShowS
show :: StartApplication -> String
$cshow :: StartApplication -> String
showsPrec :: Int -> StartApplication -> ShowS
$cshowsPrec :: Int -> StartApplication -> ShowS
Prelude.Show, (forall x. StartApplication -> Rep StartApplication x)
-> (forall x. Rep StartApplication x -> StartApplication)
-> Generic StartApplication
forall x. Rep StartApplication x -> StartApplication
forall x. StartApplication -> Rep StartApplication x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StartApplication x -> StartApplication
$cfrom :: forall x. StartApplication -> Rep StartApplication x
Prelude.Generic)

-- |
-- Create a value of 'StartApplication' 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:
--
-- 'applicationName', 'startApplication_applicationName' - Name of the application.
--
-- 'inputConfigurations', 'startApplication_inputConfigurations' - Identifies the specific input, by ID, that the application starts
-- consuming. Amazon Kinesis Analytics starts reading the streaming source
-- associated with the input. You can also specify where in the streaming
-- source you want Amazon Kinesis Analytics to start reading.
newStartApplication ::
  -- | 'applicationName'
  Prelude.Text ->
  StartApplication
newStartApplication :: Text -> StartApplication
newStartApplication Text
pApplicationName_ =
  StartApplication' :: Text -> [InputConfiguration] -> StartApplication
StartApplication'
    { $sel:applicationName:StartApplication' :: Text
applicationName =
        Text
pApplicationName_,
      $sel:inputConfigurations:StartApplication' :: [InputConfiguration]
inputConfigurations = [InputConfiguration]
forall a. Monoid a => a
Prelude.mempty
    }

-- | Name of the application.
startApplication_applicationName :: Lens.Lens' StartApplication Prelude.Text
startApplication_applicationName :: (Text -> f Text) -> StartApplication -> f StartApplication
startApplication_applicationName = (StartApplication -> Text)
-> (StartApplication -> Text -> StartApplication)
-> Lens StartApplication StartApplication Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartApplication' {Text
applicationName :: Text
$sel:applicationName:StartApplication' :: StartApplication -> Text
applicationName} -> Text
applicationName) (\s :: StartApplication
s@StartApplication' {} Text
a -> StartApplication
s {$sel:applicationName:StartApplication' :: Text
applicationName = Text
a} :: StartApplication)

-- | Identifies the specific input, by ID, that the application starts
-- consuming. Amazon Kinesis Analytics starts reading the streaming source
-- associated with the input. You can also specify where in the streaming
-- source you want Amazon Kinesis Analytics to start reading.
startApplication_inputConfigurations :: Lens.Lens' StartApplication [InputConfiguration]
startApplication_inputConfigurations :: ([InputConfiguration] -> f [InputConfiguration])
-> StartApplication -> f StartApplication
startApplication_inputConfigurations = (StartApplication -> [InputConfiguration])
-> (StartApplication -> [InputConfiguration] -> StartApplication)
-> Lens
     StartApplication
     StartApplication
     [InputConfiguration]
     [InputConfiguration]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartApplication' {[InputConfiguration]
inputConfigurations :: [InputConfiguration]
$sel:inputConfigurations:StartApplication' :: StartApplication -> [InputConfiguration]
inputConfigurations} -> [InputConfiguration]
inputConfigurations) (\s :: StartApplication
s@StartApplication' {} [InputConfiguration]
a -> StartApplication
s {$sel:inputConfigurations:StartApplication' :: [InputConfiguration]
inputConfigurations = [InputConfiguration]
a} :: StartApplication) (([InputConfiguration] -> f [InputConfiguration])
 -> StartApplication -> f StartApplication)
-> (([InputConfiguration] -> f [InputConfiguration])
    -> [InputConfiguration] -> f [InputConfiguration])
-> ([InputConfiguration] -> f [InputConfiguration])
-> StartApplication
-> f StartApplication
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([InputConfiguration] -> f [InputConfiguration])
-> [InputConfiguration] -> f [InputConfiguration]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest StartApplication where
  type
    AWSResponse StartApplication =
      StartApplicationResponse
  request :: StartApplication -> Request StartApplication
request = Service -> StartApplication -> Request StartApplication
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy StartApplication
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse StartApplication)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse StartApplication))
-> Logger
-> Service
-> Proxy StartApplication
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse StartApplication)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> StartApplicationResponse
StartApplicationResponse'
            (Int -> StartApplicationResponse)
-> Either String Int -> Either String StartApplicationResponse
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))
      )

instance Prelude.Hashable StartApplication

instance Prelude.NFData StartApplication

instance Core.ToHeaders StartApplication where
  toHeaders :: StartApplication -> ResponseHeaders
toHeaders =
    ResponseHeaders -> StartApplication -> 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
"KinesisAnalytics_20150814.StartApplication" ::
                          Prelude.ByteString
                      ),
            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 StartApplication where
  toJSON :: StartApplication -> Value
toJSON StartApplication' {[InputConfiguration]
Text
inputConfigurations :: [InputConfiguration]
applicationName :: Text
$sel:inputConfigurations:StartApplication' :: StartApplication -> [InputConfiguration]
$sel:applicationName:StartApplication' :: StartApplication -> 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
"ApplicationName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
applicationName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"InputConfigurations" Text -> [InputConfiguration] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [InputConfiguration]
inputConfigurations)
          ]
      )

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

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

-- |
--
-- /See:/ 'newStartApplicationResponse' smart constructor.
data StartApplicationResponse = StartApplicationResponse'
  { -- | The response's http status code.
    StartApplicationResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (StartApplicationResponse -> StartApplicationResponse -> Bool
(StartApplicationResponse -> StartApplicationResponse -> Bool)
-> (StartApplicationResponse -> StartApplicationResponse -> Bool)
-> Eq StartApplicationResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StartApplicationResponse -> StartApplicationResponse -> Bool
$c/= :: StartApplicationResponse -> StartApplicationResponse -> Bool
== :: StartApplicationResponse -> StartApplicationResponse -> Bool
$c== :: StartApplicationResponse -> StartApplicationResponse -> Bool
Prelude.Eq, ReadPrec [StartApplicationResponse]
ReadPrec StartApplicationResponse
Int -> ReadS StartApplicationResponse
ReadS [StartApplicationResponse]
(Int -> ReadS StartApplicationResponse)
-> ReadS [StartApplicationResponse]
-> ReadPrec StartApplicationResponse
-> ReadPrec [StartApplicationResponse]
-> Read StartApplicationResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StartApplicationResponse]
$creadListPrec :: ReadPrec [StartApplicationResponse]
readPrec :: ReadPrec StartApplicationResponse
$creadPrec :: ReadPrec StartApplicationResponse
readList :: ReadS [StartApplicationResponse]
$creadList :: ReadS [StartApplicationResponse]
readsPrec :: Int -> ReadS StartApplicationResponse
$creadsPrec :: Int -> ReadS StartApplicationResponse
Prelude.Read, Int -> StartApplicationResponse -> ShowS
[StartApplicationResponse] -> ShowS
StartApplicationResponse -> String
(Int -> StartApplicationResponse -> ShowS)
-> (StartApplicationResponse -> String)
-> ([StartApplicationResponse] -> ShowS)
-> Show StartApplicationResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StartApplicationResponse] -> ShowS
$cshowList :: [StartApplicationResponse] -> ShowS
show :: StartApplicationResponse -> String
$cshow :: StartApplicationResponse -> String
showsPrec :: Int -> StartApplicationResponse -> ShowS
$cshowsPrec :: Int -> StartApplicationResponse -> ShowS
Prelude.Show, (forall x.
 StartApplicationResponse -> Rep StartApplicationResponse x)
-> (forall x.
    Rep StartApplicationResponse x -> StartApplicationResponse)
-> Generic StartApplicationResponse
forall x.
Rep StartApplicationResponse x -> StartApplicationResponse
forall x.
StartApplicationResponse -> Rep StartApplicationResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep StartApplicationResponse x -> StartApplicationResponse
$cfrom :: forall x.
StartApplicationResponse -> Rep StartApplicationResponse x
Prelude.Generic)

-- |
-- Create a value of 'StartApplicationResponse' 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', 'startApplicationResponse_httpStatus' - The response's http status code.
newStartApplicationResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  StartApplicationResponse
newStartApplicationResponse :: Int -> StartApplicationResponse
newStartApplicationResponse Int
pHttpStatus_ =
  StartApplicationResponse' :: Int -> StartApplicationResponse
StartApplicationResponse'
    { $sel:httpStatus:StartApplicationResponse' :: Int
httpStatus =
        Int
pHttpStatus_
    }

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

instance Prelude.NFData StartApplicationResponse