-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ZKUI-327: Init the domin for accounts, buckets and locations and pens…
…ieve metric adaptor
- Loading branch information
1 parent
6e5e8e7
commit 95ee523
Showing
11 changed files
with
271 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
src/react/next-architecture/adaptors/metrics/IMetricsAdaptor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Bucket } from 'aws-sdk/clients/s3'; | ||
import { LatestUsedCapacity } from '../../domain/entities/metrics'; | ||
|
||
export type BucketLatestUsedCapacity = { | ||
bucketName: string; | ||
} & LatestUsedCapacity; | ||
export type AccountLatestUsedCapacity = { | ||
accountId: string; | ||
} & LatestUsedCapacity; | ||
export type LocationLatestUsedCapacity = { | ||
locationId: string; | ||
} & LatestUsedCapacity; | ||
|
||
export interface IMetricsAdaptor { | ||
listBucketsLatestUsedCapacity( | ||
buckets: Bucket[], | ||
): Promise<BucketLatestUsedCapacity[]>; | ||
listLocationsLatestUsedCapacity( | ||
locationIds: string[], | ||
): Promise<LocationLatestUsedCapacity[]>; | ||
listAccountLocationsLatestUsedCapacity( | ||
accountId: string, | ||
): Promise<LocationLatestUsedCapacity[]>; | ||
listAccountsLatestUsedCapacity( | ||
accountIds: string[], | ||
): Promise<AccountLatestUsedCapacity[]>; | ||
} |
30 changes: 30 additions & 0 deletions
30
src/react/next-architecture/adaptors/metrics/PensieveMetricsAdaptor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Bucket } from 'aws-sdk/clients/s3'; | ||
import { | ||
AccountLatestUsedCapacity, | ||
BucketLatestUsedCapacity, | ||
LocationLatestUsedCapacity, | ||
IMetricsAdaptor, | ||
} from './IMetricsAdaptor'; | ||
|
||
export class PensieveMetricsAdaptor implements IMetricsAdaptor { | ||
listAccountLocationsLatestUsedCapacity( | ||
accountId: string, | ||
): Promise<LocationLatestUsedCapacity[]> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
async listAccountsLatestUsedCapacity( | ||
accountIds: string[], | ||
): Promise<AccountLatestUsedCapacity[]> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
async listBucketsLatestUsedCapacity( | ||
buckets: Bucket[], | ||
): Promise<BucketLatestUsedCapacity[]> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
async listLocationsLatestUsedCapacity( | ||
locationIds: string[], | ||
): Promise<LocationLatestUsedCapacity[]> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { IMetricsAdaptor } from '../../adaptors/metrics/IMetricsAdaptor'; | ||
import { AccountsPromiseResult } from '../entities/account'; | ||
|
||
/** | ||
* The hook returns all the accounts and the storage metric for the first 20 accounts. | ||
* @param metricsAdaptor | ||
*/ | ||
export const useListAccounts = ({ | ||
metricsAdaptor, | ||
}: { | ||
metricsAdaptor: IMetricsAdaptor; | ||
}): AccountsPromiseResult => { | ||
throw new Error('Method not implemented.'); | ||
}; | ||
|
||
/** | ||
* The hook returns the latest used capacity for a specific account. | ||
* @param metricsAdaptor | ||
* @param accountId | ||
*/ | ||
export const useAccountLatestUsedCapacity = ({ | ||
metricsAdaptor, | ||
accountId, | ||
}: { | ||
metricsAdaptor: IMetricsAdaptor; | ||
accountId: string; | ||
}): AccountsPromiseResult => { | ||
throw new Error('Method not implemented.'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { IMetricsAdaptor } from '../../adaptors/metrics/IMetricsAdaptor'; | ||
import { | ||
BucketLatestUsedCapacityPromiseResult, | ||
BucketLocationConstraintPromiseResult, | ||
BucketsPromiseResult, | ||
} from '../entities/bucket'; | ||
|
||
/** | ||
* The hook returns the full list of buckets plus the locations and metrcis of the first 20 buckets. | ||
*/ | ||
export const useListBucketsForCurrentAccount = ({ | ||
metricsAdaptor, | ||
}: { | ||
metricsAdaptor: IMetricsAdaptor; | ||
}): BucketsPromiseResult => { | ||
throw new Error('Method not implemented.'); | ||
}; | ||
|
||
/** | ||
* The hook returns the location constraint for a specific bucket. | ||
* It will be called within the Table Cell on demande. | ||
* @param bucketName name of the bucket | ||
*/ | ||
export const useBucketLocationConstraint = ({ | ||
bucketName, | ||
}: { | ||
bucketName: string; | ||
}): BucketLocationConstraintPromiseResult => { | ||
throw new Error('Method not implemented.'); | ||
}; | ||
|
||
/** | ||
* The hook returns the latest used capacity for a specific bucket. | ||
* @param bucketName name of the bucket | ||
*/ | ||
export const useBucketLatestUsedCapacity = ({ | ||
metricsAdaptor, | ||
bucketName, | ||
}: { | ||
metricsAdaptor: IMetricsAdaptor; | ||
bucketName: string; | ||
}): BucketLatestUsedCapacityPromiseResult => { | ||
throw new Error('Method not implemented.'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { IMetricsAdaptor } from '../../adaptors/metrics/IMetricsAdaptor'; | ||
import { LocationsPromiseResult } from '../entities/location'; | ||
|
||
/** | ||
* The hook returns all the locations and it's metrics | ||
* @param metricsAdaptor | ||
*/ | ||
export const useListLocations = ({ | ||
metricsAdaptor, | ||
}: { | ||
metricsAdaptor: IMetricsAdaptor; | ||
}): LocationsPromiseResult => { | ||
throw new Error('Method not implemented.'); | ||
}; | ||
|
||
export const useListLocationsForCurrentAccount = ({ | ||
metricsAdaptor, | ||
}: { | ||
metricsAdaptor: IMetricsAdaptor; | ||
}): LocationsPromiseResult => { | ||
throw new Error('Method not implemented.'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { LatestUsedCapacity } from './metrics'; | ||
import { PromiseResult } from './promise'; | ||
|
||
export type AccountLatestUsedCapacityPromiseResult = { | ||
usedCapacity: PromiseResult<LatestUsedCapacity>; | ||
}; | ||
|
||
type Account = { | ||
id: string; | ||
accountName: string; | ||
creationDate: Date; | ||
} & AccountLatestUsedCapacityPromiseResult; | ||
|
||
export type AccountsPromiseResult = { | ||
accounts: PromiseResult<Account[]>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { LatestUsedCapacity } from './metrics'; | ||
import { PromiseResult } from './promise'; | ||
|
||
export type BucketLocationConstraintPromiseResult = { | ||
locationConstraint: PromiseResult<string>; | ||
}; | ||
|
||
export type BucketLatestUsedCapacityPromiseResult = { | ||
usedCapacity: PromiseResult<LatestUsedCapacity>; | ||
}; | ||
|
||
type Bucket = BucketLocationConstraintPromiseResult & { | ||
bucketName: string; | ||
creationDate: Date; | ||
usedCapacity: PromiseResult<LatestUsedCapacity>; | ||
}; | ||
|
||
export type BucketsPromiseResult = { | ||
buckets: PromiseResult<Bucket[]>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { LatestUsedCapacity } from './metrics'; | ||
import { PromiseResult } from './promise'; | ||
|
||
type Location = { | ||
id: string; | ||
name: string; | ||
type: string; | ||
usedCapacity: PromiseResult<LatestUsedCapacity>; | ||
targetBucket?: string; | ||
}; | ||
|
||
export type LocationsPromiseResult = { | ||
locations: PromiseResult<Location[]>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export type LatestUsedCapacity = | ||
| { | ||
type: 'noMetrics'; | ||
} | ||
| { | ||
type: 'hasMetrics'; | ||
usedCapacity: { | ||
current: number; | ||
nonCurrent: number; | ||
}; | ||
measuredOn: Date; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
type Idle = 'idle'; | ||
type Loading = 'loading'; | ||
type NotResolved = Idle | Loading; | ||
type Success = 'success'; | ||
type Error = 'error'; | ||
|
||
export type PromiseStatus = NotResolved | Success | Error; | ||
|
||
interface PromiseSucceedResult<T> { | ||
status: Success; | ||
value: T; | ||
} | ||
|
||
interface PromiseRejectedResult { | ||
status: Error; | ||
title: string; | ||
reason: string; | ||
} | ||
|
||
interface PromiseNotResolved { | ||
status: NotResolved; | ||
} | ||
|
||
export type PromiseResult<T> = | ||
| PromiseNotResolved | ||
| PromiseSucceedResult<T> | ||
| PromiseRejectedResult; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { createContext, useContext } from 'react'; | ||
import { PensieveMetricsAdaptor } from '../adaptors/metrics/PensieveMetricsAdaptor'; | ||
import { IMetricsAdaptor } from '../adaptors/metrics/IMetricsAdaptor'; | ||
|
||
const _MetricsAdaptorContext = createContext<null | { | ||
metricsAdaptor: IMetricsAdaptor; | ||
}>(null); | ||
|
||
export const useMetricsAdaptor = (): IMetricsAdaptor => { | ||
const context = useContext(_MetricsAdaptorContext); | ||
|
||
if (!context) { | ||
throw new Error( | ||
'The useMetricsAdaptor hook can only be used within MetricsAdaptorProvider.', | ||
); | ||
} | ||
|
||
return context.metricsAdaptor; | ||
}; | ||
|
||
const MetricsAdaptorProvider = ({ children }: { children: JSX.Element }) => { | ||
// We only need to change to SCUBA Adaptor later on. | ||
const metricsAdaptor = new PensieveMetricsAdaptor(); | ||
return ( | ||
<_MetricsAdaptorContext.Provider value={{ metricsAdaptor }}> | ||
{children} | ||
</_MetricsAdaptorContext.Provider> | ||
); | ||
}; | ||
export default MetricsAdaptorProvider; |