-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
14c7d67
commit 201fc97
Showing
13 changed files
with
256 additions
and
124 deletions.
There are no files selected for viewing
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,3 @@ | ||
import { Context } from '~/third_party/mlmd'; | ||
|
||
export type MlmdContext = Context; |
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
41 changes: 41 additions & 0 deletions
41
frontend/src/concepts/pipelines/apiHooks/mlmd/useMlmdContext.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,41 @@ | ||
import React from 'react'; | ||
import { MlmdContext } from '~/concepts/pipelines/apiHooks/mlmd/types'; | ||
import { usePipelinesAPI } from '~/concepts/pipelines/context'; | ||
import { GetContextByTypeAndNameRequest } from '~/third_party/mlmd'; | ||
import { FAST_POLL_INTERVAL } from '~/utilities/const'; | ||
import useFetchState, { | ||
FetchState, | ||
FetchStateCallbackPromise, | ||
NotReadyError, | ||
} from '~/utilities/useFetchState'; | ||
|
||
export const useMlmdContext = ( | ||
name?: string, | ||
type?: string, | ||
activelyRefresh?: boolean, | ||
): FetchState<MlmdContext | null> => { | ||
const { metadataStoreServiceClient } = usePipelinesAPI(); | ||
|
||
const call = React.useCallback<FetchStateCallbackPromise<MlmdContext | null>>(async () => { | ||
if (!type) { | ||
return Promise.reject(new NotReadyError('No context type')); | ||
} | ||
if (!name) { | ||
return Promise.reject(new NotReadyError('No context name')); | ||
} | ||
|
||
const request = new GetContextByTypeAndNameRequest(); | ||
request.setTypeName(type); | ||
request.setContextName(name); | ||
const res = await metadataStoreServiceClient.getContextByTypeAndName(request); | ||
const context = res.getContext(); | ||
if (!context) { | ||
return Promise.reject(new Error('Cannot find specified context')); | ||
} | ||
return context; | ||
}, [metadataStoreServiceClient, type, name]); | ||
|
||
return useFetchState(call, null, { | ||
refreshRate: activelyRefresh ? FAST_POLL_INTERVAL : undefined, | ||
}); | ||
}; |
49 changes: 6 additions & 43 deletions
49
frontend/src/concepts/pipelines/apiHooks/mlmd/usePipelineRunMlmdContext.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 |
---|---|---|
@@ -1,48 +1,11 @@ | ||
import React from 'react'; | ||
import { Context } from '~/third_party/mlmd'; | ||
import { usePipelinesAPI } from '~/concepts/pipelines/context'; | ||
import useFetchState, { | ||
FetchState, | ||
FetchStateCallbackPromise, | ||
NotReadyError, | ||
} from '~/utilities/useFetchState'; | ||
import { GetContextByTypeAndNameRequest } from '~/third_party/mlmd/generated/ml_metadata/proto/metadata_store_service_pb'; | ||
import { FAST_POLL_INTERVAL } from '~/utilities/const'; | ||
import { FetchState } from '~/utilities/useFetchState'; | ||
import { MlmdContext } from '~/concepts/pipelines/apiHooks/mlmd/types'; | ||
import { useMlmdContext } from '~/concepts/pipelines/apiHooks/mlmd/useMlmdContext'; | ||
|
||
const KFP_V2_RUN_CONTEXT_TYPE = 'system.PipelineRun'; | ||
|
||
const useMlmdContext = ( | ||
name?: string, | ||
type?: string, | ||
pipelineFinished?: boolean, | ||
): FetchState<Context | null> => { | ||
const { metadataStoreServiceClient } = usePipelinesAPI(); | ||
|
||
const call = React.useCallback<FetchStateCallbackPromise<Context | null>>(async () => { | ||
if (!type) { | ||
return Promise.reject(new NotReadyError('No context type')); | ||
} | ||
if (!name) { | ||
return Promise.reject(new NotReadyError('No context name')); | ||
} | ||
|
||
const request = new GetContextByTypeAndNameRequest(); | ||
request.setTypeName(type); | ||
request.setContextName(name); | ||
const res = await metadataStoreServiceClient.getContextByTypeAndName(request); | ||
const context = res.getContext(); | ||
if (!context) { | ||
return Promise.reject(new Error('Cannot find specified context')); | ||
} | ||
return context; | ||
}, [metadataStoreServiceClient, type, name]); | ||
|
||
return useFetchState(call, null, { | ||
refreshRate: !pipelineFinished ? FAST_POLL_INTERVAL : undefined, | ||
}); | ||
}; | ||
|
||
export const usePipelineRunMlmdContext = ( | ||
runID?: string, | ||
pipelineFinished?: boolean, | ||
): FetchState<Context | null> => useMlmdContext(runID, KFP_V2_RUN_CONTEXT_TYPE, pipelineFinished); | ||
activelyRefresh?: boolean, | ||
): FetchState<MlmdContext | null> => | ||
useMlmdContext(runID, KFP_V2_RUN_CONTEXT_TYPE, activelyRefresh); |
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
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
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
19 changes: 19 additions & 0 deletions
19
...rc/concepts/pipelines/content/pipelinesDetails/pipelineRun/useExecutionsForPipelineRun.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,19 @@ | ||
import { useExecutionsFromContext } from '~/concepts/pipelines/apiHooks/mlmd/useExecutionsFromContext'; | ||
import { usePipelineRunMlmdContext } from '~/concepts/pipelines/apiHooks/mlmd/usePipelineRunMlmdContext'; | ||
import { isPipelineRunFinished } from '~/concepts/pipelines/apiHooks/usePipelineRunById'; | ||
import { PipelineRunKFv2 } from '~/concepts/pipelines/kfTypes'; | ||
import { Execution } from '~/third_party/mlmd'; | ||
|
||
const useExecutionsForPipelineRun = ( | ||
run: PipelineRunKFv2 | null, | ||
): [executions: Execution[] | null, loaded: boolean, error?: Error] => { | ||
const isFinished = isPipelineRunFinished(run); | ||
// contextError means mlmd service is not available, no need to check executions | ||
const [context, , contextError] = usePipelineRunMlmdContext(run?.run_id, !isFinished); | ||
// executionsLoaded is the flag to show the spinner or not | ||
const [executions, executionsLoaded] = useExecutionsFromContext(context, !isFinished); | ||
|
||
return [executions, executionsLoaded, contextError]; | ||
}; | ||
|
||
export default useExecutionsForPipelineRun; |
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
Oops, something went wrong.