Skip to content

Commit

Permalink
adding AML Compute
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Zocca committed Jun 24, 2023
1 parent 000cafa commit f483ab2
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 4 deletions.
3 changes: 2 additions & 1 deletion ms-azure-api/ms-azure-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ tested-with: GHC == 9.2.8
library
default-language: Haskell2010
hs-source-dirs: src
exposed-modules: MSAzureAPI.MachineLearning.Jobs
exposed-modules: MSAzureAPI.MachineLearning.Compute
MSAzureAPI.MachineLearning.Jobs
MSAzureAPI.StorageServices
MSAzureAPI.StorageServices.FileService
other-modules: MSAzureAPI.Internal.Common
Expand Down
77 changes: 77 additions & 0 deletions ms-azure-api/src/MSAzureAPI/MachineLearning/Compute.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
module MSAzureAPI.MachineLearning.Compute where

import Control.Applicative (Alternative(..))
import Control.Monad.IO.Class (MonadIO(..))
import Data.Foldable (asum)
import Data.Functor (void)
-- import Data.Maybe (listToMaybe)
import GHC.Generics (Generic(..))

-- aeson
import qualified Data.Aeson as A (ToJSON(..), genericToEncoding, FromJSON(..), genericParseJSON, defaultOptions, Options(..), withObject, withText, (.:), (.:?), object, (.=), Key, Value, camelTo2)
-- bytestring
import qualified Data.ByteString as BS (ByteString)
import qualified Data.ByteString.Char8 as BS8 (pack, unpack)
import qualified Data.ByteString.Lazy as LBS (ByteString)
-- hoauth2
import Network.OAuth.OAuth2.Internal (AccessToken(..))
-- req
import Network.HTTP.Req (Req, Url, Option, Scheme(..))
-- text
import Data.Text (Text, pack, unpack)
import qualified Data.Text.Lazy as TL (Text, pack, unpack, toStrict)
-- time
import Data.Time (UTCTime, getCurrentTime)
import Data.Time.Format (FormatTime, formatTime, defaultTimeLocale)
import Data.Time.LocalTime (ZonedTime, getZonedTime)

import qualified MSAzureAPI.Internal.Common as MSA (Collection, APIPlane(..), (==:), put, get, getBs, post, getLbs, aesonOptions)

-- | list computes in a workspace
--
-- docs : https://learn.microsoft.com/en-us/rest/api/azureml/2023-04-01/compute/list?tabs=HTTP
--
-- @GET https:\/\/management.azure.com\/subscriptions\/{subscriptionId}\/resourceGroups\/{resourceGroupName}\/providers\/Microsoft.MachineLearningServices\/workspaces\/{workspaceName}\/computes?api-version=2023-04-01@
listComputes :: Text -- ^ subscription id
-> Text -- ^ res group id
-> Text -- ^ ML workspace id
-> AccessToken -> Req (MSA.Collection Compute)
listComputes sid rgid wsid = MSA.get MSA.APManagement [
"subscriptions", sid,
"resourceGroups", rgid,
"providers", "Microsoft.MachineLearningServices",
"workspaces", wsid,
"computes"
] ("api-version" MSA.==: "2023-04-01")

data Compute = Compute {
cmpId :: Text
, cmpType :: Text
, cmpName :: Text
, cmpLocation :: Text
, cmpProperties :: ComputeProperties
} deriving (Show, Generic)
instance A.FromJSON Compute where
parseJSON = A.genericParseJSON (MSA.aesonOptions "cmp")
instance A.ToJSON Compute where
toEncoding = A.genericToEncoding (MSA.aesonOptions "cmp")

data ComputeProperties = ComputeProperties {
cmppCreatedOn :: ZonedTime
, cmppModifiedOn :: ZonedTime
, cmppResourceId :: Text
, cmppComputeType :: ComputeType
, cmppProvisioningState :: ProvisioningState
} deriving (Show, Generic)
instance A.ToJSON ComputeProperties where
toEncoding = A.genericToEncoding (MSA.aesonOptions "cmpp")
instance A.FromJSON ComputeProperties where
parseJSON = A.genericParseJSON (MSA.aesonOptions "cmpp")

data ComputeType = AKS deriving (Eq, Show, Generic)
instance A.ToJSON ComputeType
instance A.FromJSON ComputeType

data ProvisioningState = Succeeded deriving (Eq, Show, Generic)
instance A.ToJSON ProvisioningState
instance A.FromJSON ProvisioningState
11 changes: 8 additions & 3 deletions ms-azure-api/src/MSAzureAPI/MachineLearning/Jobs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,13 @@ createJob sid rgid wsid jid =
"workspaces", wsid,
"jobs", jid] ("api-version" MSA.==: "2023-04-01")

data JobBase = JB {
jbTODO :: Text
} deriving (Eq, Show, Generic)
-- | JobBase type
--
-- https://learn.microsoft.com/en-us/rest/api/azureml/2023-04-01/jobs/create-or-update?tabs=HTTP
data JobBase = JBAutoMLJob -- ^ https://learn.microsoft.com/en-us/rest/api/azureml/2023-04-01/jobs/list?tabs=HTTP#automljob
| JBCommandJob
| JBPipelineJob
| JBSweepJob
deriving (Eq, Show, Generic)
instance A.ToJSON JobBase where
toEncoding = A.genericToEncoding (MSA.aesonOptions "jb")

0 comments on commit f483ab2

Please sign in to comment.