-
Notifications
You must be signed in to change notification settings - Fork 178
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
1aab9db
commit a22e785
Showing
21 changed files
with
839 additions
and
29 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 |
---|---|---|
@@ -1,7 +1,16 @@ | ||
import { Context } from '~/third_party/mlmd'; | ||
import { Artifact, Context, ContextType, Event } from '~/third_party/mlmd'; | ||
|
||
export type MlmdContext = Context; | ||
|
||
export type MlmdContextType = ContextType; | ||
|
||
export enum MlmdContextTypes { | ||
RUN = 'system.PipelineRun', | ||
} | ||
|
||
// An artifact which has associated event. | ||
// You can retrieve artifact name from event.path.steps[0].key | ||
export interface LinkedArtifact { | ||
event: Event; | ||
artifact: Artifact; | ||
} |
22 changes: 22 additions & 0 deletions
22
frontend/src/concepts/pipelines/apiHooks/mlmd/useGetArtifactTypes.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,22 @@ | ||
import React from 'react'; | ||
import { usePipelinesAPI } from '~/concepts/pipelines/context'; | ||
import { GetArtifactTypesRequest } from '~/third_party/mlmd'; | ||
import useFetchState, { FetchState, FetchStateCallbackPromise } from '~/utilities/useFetchState'; | ||
|
||
export const useGetArtifactTypeMap = (): FetchState<Record<number, string>> => { | ||
const { metadataStoreServiceClient } = usePipelinesAPI(); | ||
|
||
const call = React.useCallback<FetchStateCallbackPromise<Record<number, string>>>(async () => { | ||
const request = new GetArtifactTypesRequest(); | ||
|
||
const res = await metadataStoreServiceClient.getArtifactTypes(request); | ||
|
||
const artifactTypeMap: Record<number, string> = {}; | ||
res.getArtifactTypesList().forEach((artifactType) => { | ||
artifactTypeMap[artifactType.getId()] = artifactType.getName(); | ||
}); | ||
return artifactTypeMap; | ||
}, [metadataStoreServiceClient]); | ||
|
||
return useFetchState(call, {}); | ||
}; |
32 changes: 32 additions & 0 deletions
32
frontend/src/concepts/pipelines/apiHooks/mlmd/useGetEventsByExecutionId.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,32 @@ | ||
import React from 'react'; | ||
import { usePipelinesAPI } from '~/concepts/pipelines/context'; | ||
import { | ||
GetEventsByExecutionIDsRequest, | ||
GetEventsByExecutionIDsResponse, | ||
} from '~/third_party/mlmd'; | ||
import useFetchState, { FetchState, FetchStateCallbackPromise } from '~/utilities/useFetchState'; | ||
|
||
export const useGetEventsByExecutionId = ( | ||
executionId?: string, | ||
): FetchState<GetEventsByExecutionIDsResponse | null> => { | ||
const { metadataStoreServiceClient } = usePipelinesAPI(); | ||
|
||
const call = React.useCallback< | ||
FetchStateCallbackPromise<GetEventsByExecutionIDsResponse | null> | ||
>(async () => { | ||
const numberId = Number(executionId); | ||
const request = new GetEventsByExecutionIDsRequest(); | ||
|
||
if (!executionId || Number.isNaN(numberId)) { | ||
return null; | ||
} | ||
|
||
request.setExecutionIdsList([numberId]); | ||
|
||
const response = await metadataStoreServiceClient.getEventsByExecutionIDs(request); | ||
|
||
return response; | ||
}, [executionId, metadataStoreServiceClient]); | ||
|
||
return useFetchState(call, null); | ||
}; |
25 changes: 25 additions & 0 deletions
25
frontend/src/concepts/pipelines/apiHooks/mlmd/useGetExecutionById.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,25 @@ | ||
import React from 'react'; | ||
import { usePipelinesAPI } from '~/concepts/pipelines/context'; | ||
import { Execution, GetExecutionsByIDRequest } from '~/third_party/mlmd'; | ||
import useFetchState, { FetchState, FetchStateCallbackPromise } from '~/utilities/useFetchState'; | ||
|
||
export const useGetExecutionById = (executionId?: string): FetchState<Execution | null> => { | ||
const { metadataStoreServiceClient } = usePipelinesAPI(); | ||
|
||
const call = React.useCallback<FetchStateCallbackPromise<Execution | null>>(async () => { | ||
const numberId = Number(executionId); | ||
const request = new GetExecutionsByIDRequest(); | ||
|
||
if (!executionId || Number.isNaN(numberId)) { | ||
return null; | ||
} | ||
|
||
request.setExecutionIdsList([numberId]); | ||
|
||
const response = await metadataStoreServiceClient.getExecutionsByID(request); | ||
|
||
return response.getExecutionsList().length !== 0 ? response.getExecutionsList()[0] : null; | ||
}, [executionId, metadataStoreServiceClient]); | ||
|
||
return useFetchState(call, null); | ||
}; |
34 changes: 34 additions & 0 deletions
34
frontend/src/concepts/pipelines/apiHooks/mlmd/useGetLinkedArtifactsByEvents.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,34 @@ | ||
import React from 'react'; | ||
import { LinkedArtifact } from '~/concepts/pipelines/apiHooks/mlmd/types'; | ||
import { usePipelinesAPI } from '~/concepts/pipelines/context'; | ||
import { Artifact, Event, GetArtifactsByIDRequest } from '~/third_party/mlmd'; | ||
import useFetchState, { FetchState, FetchStateCallbackPromise } from '~/utilities/useFetchState'; | ||
|
||
export const useGetLinkedArtifactsByEvents = (events: Event[]): FetchState<LinkedArtifact[]> => { | ||
const { metadataStoreServiceClient } = usePipelinesAPI(); | ||
|
||
const call = React.useCallback<FetchStateCallbackPromise<LinkedArtifact[]>>(async () => { | ||
const artifactIds = events | ||
.filter((event) => event.getArtifactId()) | ||
.map((event) => event.getArtifactId()); | ||
const request = new GetArtifactsByIDRequest(); | ||
|
||
if (artifactIds.length === 0) { | ||
return []; | ||
} | ||
|
||
request.setArtifactIdsList(artifactIds); | ||
|
||
const response = await metadataStoreServiceClient.getArtifactsByID(request); | ||
|
||
const artifactMap: Record<number, Artifact> = {}; | ||
response.getArtifactsList().forEach((artifact) => (artifactMap[artifact.getId()] = artifact)); | ||
|
||
return events.map((event) => { | ||
const artifact = artifactMap[event.getArtifactId()]; | ||
return { event, artifact }; | ||
}); | ||
}, [events, metadataStoreServiceClient]); | ||
|
||
return useFetchState(call, []); | ||
}; |
36 changes: 36 additions & 0 deletions
36
frontend/src/concepts/pipelines/apiHooks/mlmd/useGetMlmdContextByExecution.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,36 @@ | ||
import React from 'react'; | ||
import { MlmdContext, MlmdContextTypes } from '~/concepts/pipelines/apiHooks/mlmd/types'; | ||
import { useGetMlmdContextType } from '~/concepts/pipelines/apiHooks/mlmd/useGetMlmdContextType'; | ||
import { usePipelinesAPI } from '~/concepts/pipelines/context'; | ||
import { Execution } from '~/third_party/mlmd'; | ||
import { GetContextsByExecutionRequest } from '~/third_party/mlmd/generated/ml_metadata/proto/metadata_store_service_pb'; | ||
import useFetchState, { FetchState, FetchStateCallbackPromise } from '~/utilities/useFetchState'; | ||
|
||
const useGetMlmdContextByExecution = ( | ||
execution: Execution, | ||
type?: MlmdContextTypes, | ||
): FetchState<MlmdContext | null> => { | ||
const { metadataStoreServiceClient } = usePipelinesAPI(); | ||
const executionId = execution.getId(); | ||
const [contextType] = useGetMlmdContextType(type); | ||
|
||
const contextTypeId = contextType?.getId(); | ||
|
||
const call = React.useCallback<FetchStateCallbackPromise<MlmdContext | null>>(async () => { | ||
const request = new GetContextsByExecutionRequest(); | ||
|
||
request.setExecutionId(executionId); | ||
|
||
const response = await metadataStoreServiceClient.getContextsByExecution(request); | ||
|
||
const result = response.getContextsList().filter((c) => c.getTypeId() === contextTypeId); | ||
|
||
return result.length === 1 ? result[0] : null; | ||
}, [executionId, metadataStoreServiceClient, contextTypeId]); | ||
|
||
return useFetchState(call, null); | ||
}; | ||
|
||
export const useGetPipelineRunContextByExecution = ( | ||
execution: Execution, | ||
): FetchState<MlmdContext | null> => useGetMlmdContextByExecution(execution, MlmdContextTypes.RUN); |
29 changes: 29 additions & 0 deletions
29
frontend/src/concepts/pipelines/apiHooks/mlmd/useGetMlmdContextType.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,29 @@ | ||
import React from 'react'; | ||
import { MlmdContextType, MlmdContextTypes } from '~/concepts/pipelines/apiHooks/mlmd/types'; | ||
import { usePipelinesAPI } from '~/concepts/pipelines/context'; | ||
import { GetContextTypeRequest } from '~/third_party/mlmd'; | ||
import useFetchState, { | ||
FetchState, | ||
FetchStateCallbackPromise, | ||
NotReadyError, | ||
} from '~/utilities/useFetchState'; | ||
|
||
export const useGetMlmdContextType = ( | ||
type?: MlmdContextTypes, | ||
): FetchState<MlmdContextType | null> => { | ||
const { metadataStoreServiceClient } = usePipelinesAPI(); | ||
|
||
const call = React.useCallback<FetchStateCallbackPromise<MlmdContextType | null>>(async () => { | ||
if (!type) { | ||
return Promise.reject(new NotReadyError('No context type')); | ||
} | ||
|
||
const request = new GetContextTypeRequest(); | ||
request.setTypeName(type); | ||
const res = await metadataStoreServiceClient.getContextType(request); | ||
const contextType = res.getContextType() || null; | ||
return contextType; | ||
}, [metadataStoreServiceClient, type]); | ||
|
||
return useFetchState(call, null); | ||
}; |
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
35 changes: 22 additions & 13 deletions
35
frontend/src/pages/pipelines/global/experiments/executions/ExecutionsTableRow.tsx
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,23 +1,32 @@ | ||
import * as React from 'react'; | ||
import { Td, Tr } from '@patternfly/react-table'; | ||
import { Link } from 'react-router-dom'; | ||
import { Execution } from '~/third_party/mlmd'; | ||
import ExecutionsTableRowStatusIcon from '~/pages/pipelines/global/experiments/executions/ExecutionsTableRowStatusIcon'; | ||
import { getExecutionDisplayName } from '~/pages/pipelines/global/experiments/executions/utils'; | ||
import { executionDetailsRoute } from '~/routes'; | ||
import { usePipelinesAPI } from '~/concepts/pipelines/context'; | ||
import ExecutionStatus from '~/pages/pipelines/global/experiments/executions/ExecutionStatus'; | ||
|
||
type ExecutionsTableRowProps = { | ||
obj: Execution; | ||
}; | ||
|
||
const ExecutionsTableRow: React.FC<ExecutionsTableRowProps> = ({ obj }) => ( | ||
<Tr> | ||
<Td dataLabel="Executions"> | ||
{obj.getCustomPropertiesMap().get('task_name')?.getStringValue() || '(No name)'} | ||
</Td> | ||
<Td dataLabel="Status"> | ||
<ExecutionsTableRowStatusIcon status={obj.getLastKnownState()} /> | ||
</Td> | ||
<Td dataLabel="ID">{obj.getId()}</Td> | ||
<Td dataLabel="Type">{obj.getType()}</Td> | ||
</Tr> | ||
); | ||
const ExecutionsTableRow: React.FC<ExecutionsTableRowProps> = ({ obj }) => { | ||
const { namespace } = usePipelinesAPI(); | ||
return ( | ||
<Tr> | ||
<Td dataLabel="Executions"> | ||
<Link to={executionDetailsRoute(namespace, obj.getId().toString())}> | ||
{getExecutionDisplayName(obj)} | ||
</Link> | ||
</Td> | ||
<Td dataLabel="Status"> | ||
<ExecutionStatus isIcon status={obj.getLastKnownState()} /> | ||
</Td> | ||
<Td dataLabel="ID">{obj.getId()}</Td> | ||
<Td dataLabel="Type">{obj.getType()}</Td> | ||
</Tr> | ||
); | ||
}; | ||
|
||
export default ExecutionsTableRow; |
Oops, something went wrong.