Skip to content

Commit

Permalink
generalised image, ensured no warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Oswyn Brent committed Feb 10, 2015
1 parent 4ff2d1a commit 6bfd7db
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion lib/Ceilometer/Fold.hs
Expand Up @@ -93,7 +93,7 @@ foldSSD window = PFold step bEvent (eEvent window)
foldImage :: Window -> PFold (Timed PDImage) (FoldResult PDImage)
foldImage window = PFold step bEvent (eEvent window)
where -- Stop folding as soon as the image is deleted
step (More (prev,acc)) (Timed end (PDImage _ ImageDelete _))
step (More (prev,acc)) (Timed end (PDImage _ ImageDelete _ _))
= Term (Nothing, go end acc prev)
step a x = sEvent window a x

Expand Down
2 changes: 1 addition & 1 deletion lib/Ceilometer/Types.hs
Expand Up @@ -128,7 +128,7 @@ instance Valued PDInstanceDisk where

instance Valued PDImage where
type PFValue PDImage = PFValue32
value f (PDImage s v x) = PDImage s v <$> f x
value f (PDImage s v e x) = PDImage s v e <$> f x

instance Valued PDImagePollster where
type PFValue PDImagePollster = PFValue64
Expand Down
27 changes: 14 additions & 13 deletions lib/Ceilometer/Types/Image.hs
Expand Up @@ -53,9 +53,10 @@ $(declarePF "Image"
[ ''Show, ''Read, ''Eq, ''Bounded, ''Enum ])

data PDImage = PDImage
{ _imageStatus :: PFImageStatus
, _imageVerb :: PFImageVerb
, _imageVal :: PFValue32 }
{ _imageStatus :: PFImageStatus
, _imageVerb :: PFImageVerb
, _imageEndpoint :: PFEndpoint
, _imageVal :: PFValue32 }
deriving (Eq, Show, Read, Typeable)

$(makeLenses ''PDImage)
Expand All @@ -68,15 +69,15 @@ pdImagePollster = iso (PDImagePollster . _prSimpleVal) (PRSimple . _pdImagePolls

pdImage :: Prism' PRCompoundEvent PDImage
pdImage = prism' pretty parse
where parse raw = do
s <- raw ^? eventStatus . pfImageStatus
v <- raw ^? eventVerb . pfImageVerb
_ <- raw ^? eventEndpoint . pfEndpoint . only Instant
x <- raw ^? eventVal
Just $ PDImage s v x
pretty (PDImage status verb val)
where parse raw
= PDImage
<$> (raw ^? eventStatus . pfImageStatus)
<*> (raw ^? eventVerb . pfImageVerb)
<*> (raw ^? eventEndpoint . pfEndpoint)
<*> (raw ^? eventVal )
pretty (PDImage status verb ep val)
= PRCompoundEvent
val
(Instant ^. re pfEndpoint)
(verb ^. re pfImageVerb)
(status ^. re pfImageStatus)
(ep ^. re pfEndpoint)
(verb ^. re pfImageVerb)
(status ^. re pfImageStatus)
7 changes: 4 additions & 3 deletions tests/SampleData.hs
Expand Up @@ -104,6 +104,7 @@ instance Arbitrary PDImage where arbitrary = PDImage
<$> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
instance Arbitrary PDImagePollster where arbitrary = PDImagePollster <$> arbitrary
instance Arbitrary PDSnapshot where arbitrary = PDSnapshot
<$> arbitrary
Expand Down Expand Up @@ -279,9 +280,9 @@ imagePR2 = 3 + (5 `shift` 8) + (0 `shift` 16) + (100000 `shift` 32)
imagePDs = [imagePD0, imagePD1, imagePD2 ]

imagePD0, imagePD1, imagePD2 :: PDImage
imagePD0 = PDImage ImageActive ImageUpload 200000
imagePD1 = PDImage ImageActive ImageServe 400000
imagePD2 = PDImage ImageDeleted ImageDelete 100000
imagePD0 = PDImage ImageActive ImageUpload Instant 200000
imagePD1 = PDImage ImageActive ImageServe Instant 400000
imagePD2 = PDImage ImageDeleted ImageDelete Instant 100000

imageTimedPDs :: [Timed PDImage]
imageTimedPDs = [ Timed testS imagePD0
Expand Down

0 comments on commit 6bfd7db

Please sign in to comment.