Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Frontend - Metadata - Switching to contexts #2852

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions frontend/src/lib/Apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ export enum ArtifactProperties {
export enum ArtifactCustomProperties {
WORKSPACE = '__kf_workspace__',
RUN = '__kf_run__',
NAME = 'name',
PIPELINE_NAME = 'pipeline_name', // TODO: Remove when switching to contexts
RUN_ID = 'run_id', // TODO: Remove when switching to contexts
}

/** Known Execution properties */
Expand All @@ -57,6 +60,19 @@ export enum ExecutionProperties {
/** Known Execution custom properties */
export enum ExecutionCustomProperties {
WORKSPACE = '__kf_workspace__',
RUN_ID = 'run_id', // TODO: Remove when switching to contexts
TASK_ID = 'task_id',
}

/** Known Context properties */
export enum ContextProperties {
PIPELINE_NAME = 'pipeline_name',
}

/** Known Context custom properties */
export enum ContextCustomProperties {
PIPELINE_NAME = 'pipeline_name',
RUN_ID = 'run_id',
}

export interface ListRequest {
Expand Down Expand Up @@ -120,6 +136,16 @@ const metadataServicePromiseClient = {
getExecutionsByID: makePromiseApi(
metadataServiceClient.getExecutionsByID.bind(metadataServiceClient),
),
//getContextTypes: makePromiseApi( # Missing for some reason
// metadataServiceClient.getContextTypes.bind(metadataServiceClient),
//),
getContextType: makePromiseApi(metadataServiceClient.getContextType.bind(metadataServiceClient)),
getContexts: makePromiseApi(metadataServiceClient.getContexts.bind(metadataServiceClient)),
getContextsByID: makePromiseApi(
metadataServiceClient.getContextsByID.bind(metadataServiceClient),
),
getAttributions: makePromiseApi(metadataServiceClient.Attributions.bind(metadataServiceClient)),
getAssociations: makePromiseApi(metadataServiceClient.Associations.bind(metadataServiceClient)),
};

// For cross browser support, fetch should use 'same-origin' as default. This fixes firefox auth issues.
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/lib/Utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { ListRequest } from './Apis';
import { Row, Column, ExpandState } from '../components/CustomTable';
import { padding } from '../Css';
import { classes } from 'typestyle';
import { Value, Artifact, Execution } from '../generated/src/apis/metadata/metadata_store_pb';
import { Value, Artifact, Execution, Context } from '../generated/src/apis/metadata/metadata_store_pb';
import { CustomTableRow, css } from '../components/CustomTableRow';
import { ServiceError } from '../generated/src/apis/metadata/metadata_store_service_pb_service';

Expand Down Expand Up @@ -123,7 +123,7 @@ export function titleCase(str: string): string {
* @param fromCustomProperties
*/
export function getResourceProperty(
resource: Artifact | Execution,
resource: Artifact | Execution | Context,
propertyName: string,
fromCustomProperties = false,
): string | number | null {
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/pages/ArtifactDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { CircularProgress } from '@material-ui/core';
import { titleCase, getResourceProperty, serviceErrorToString } from '../lib/Utils';
import { ResourceInfo, ResourceType } from '../components/ResourceInfo';
import { Artifact } from '../generated/src/apis/metadata/metadata_store_pb';
import { Apis, ArtifactProperties } from '../lib/Apis';
import { Apis, ArtifactProperties, ArtifactCustomProperties } from '../lib/Apis';
import { GetArtifactsByIDRequest } from '../generated/src/apis/metadata/metadata_store_service_pb';

interface ArtifactDetailsState {
Expand Down Expand Up @@ -108,7 +108,9 @@ export default class ArtifactDetails extends Page<{}, ArtifactDetailsState> {

const artifact = res.getArtifactsList()[0];

const artifactName = getResourceProperty(artifact, ArtifactProperties.NAME);
const artifactName =
getResourceProperty(artifact, ArtifactProperties.NAME) ||
getResourceProperty(artifact, ArtifactCustomProperties.NAME, true);
let title = artifactName ? artifactName.toString() : '';
const version = getResourceProperty(artifact, ArtifactProperties.VERSION);
if (version) {
Expand Down
48 changes: 44 additions & 4 deletions frontend/src/pages/ArtifactList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ import {
} from '../lib/Utils';
import { RoutePageFactory } from '../components/Router';
import { Link } from 'react-router-dom';
import { Artifact, ArtifactType } from '../generated/src/apis/metadata/metadata_store_pb';
import { ArtifactProperties, ArtifactCustomProperties, ListRequest, Apis } from '../lib/Apis';
import { Artifact, ArtifactType, Context, Attribution } from '../generated/src/apis/metadata/metadata_store_pb';
import { ArtifactProperties, ArtifactCustomProperties, ContextCustomProperties, ListRequest, Apis } from '../lib/Apis';
import {
GetArtifactTypesRequest,
GetArtifactsRequest,
Expand Down Expand Up @@ -181,6 +181,40 @@ class ArtifactList extends Page<{}, ArtifactListState> {
artifactTypesMap.set(artifactType.getId()!, artifactType);
});

const contextsMap = new Map<number, Context>();
const {
error: contexts_err,
response: contexts_res,
} = await Apis.getMetadataServicePromiseClient().getContexts(
new GetContextsRequest(),
);

if (contexts_err) {
this.showPageError(serviceErrorToString(contexts_err));
return;
}

((contexts_res && contexts_res.getContextsList()) || []).forEach(context => {
contextsMap.set(context.getId()!, context);
});

const artifactIdToContextIdMap = new Map<number, number>();
const {
error: attributions_err,
response: attributions_res,
} = await Apis.getMetadataServicePromiseClient().getAttributions(
new GetAttributionsRequest(),
);

if (attributions_err) {
this.showPageError(serviceErrorToString(attributions_err));
return;
}

((attributions_res && attributions_res.getAttributionsList()) || []).forEach(attribution => {
artifactIdToContextIdMap.set(attribution.getArtifactId()!, attribution.getContextId()!);
});

try {
// TODO: When backend supports sending creation time back when we list
// artifacts, let's use it directly.
Expand All @@ -206,12 +240,18 @@ class ArtifactList extends Page<{}, ArtifactListState> {
typeId && artifactTypesMap && artifactTypesMap.get(typeId)
? artifactTypesMap.get(typeId)!.getName()
: typeId;
const artifactId = artifact.getId()!;
const contextId = artifactIdToContextIdMap.get(artifactId);
const context = contextId ? contextsMap.get(contextId) : undefined;
return {
id: `${type}:${artifact.getId()}`, // Join with colon so we can build the link
otherFields: [
getResourceProperty(artifact, ArtifactProperties.PIPELINE_NAME) ||
getResourceProperty(artifact, ArtifactCustomProperties.WORKSPACE, true),
getResourceProperty(artifact, ArtifactProperties.NAME),
getResourceProperty(artifact, ArtifactCustomProperties.WORKSPACE, true) ||
getResourceProperty(artifact, ArtifactCustomProperties.RUN_ID, true) ||
(context ? getResourceProperty(context, ContextCustomProperties.RUN_ID, true) : undefined),
getResourceProperty(artifact, ArtifactProperties.NAME) ||
getResourceProperty(artifact, ArtifactCustomProperties.NAME, true),
artifact.getId(),
type,
artifact.getUri(),
Expand Down
16 changes: 13 additions & 3 deletions frontend/src/pages/ExecutionDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ import { CircularProgress } from '@material-ui/core';
import { titleCase, getResourceProperty, serviceErrorToString, logger } from '../lib/Utils';
import { ResourceInfo, ResourceType } from '../components/ResourceInfo';
import { Execution, ArtifactType } from '../generated/src/apis/metadata/metadata_store_pb';
import { Apis, ExecutionProperties, ArtifactProperties } from '../lib/Apis';
import {
Apis,
ExecutionProperties,
ArtifactProperties,
ExecutionCustomProperties,
ArtifactCustomProperties,
} from '../lib/Apis';
import {
GetExecutionsByIDRequest,
GetEventsByExecutionIDsRequest,
Expand Down Expand Up @@ -168,7 +174,9 @@ export default class ExecutionDetails extends Page<{}, ExecutionDetailsState> {
}

const execution = executionResponse.response.getExecutionsList()[0];
const executionName = getResourceProperty(execution, ExecutionProperties.COMPONENT_ID);
const executionName =
getResourceProperty(execution, ExecutionProperties.COMPONENT_ID) ||
getResourceProperty(execution, ExecutionCustomProperties.TASK_ID, true);
this.props.updateToolbar({
pageTitle: executionName ? executionName.toString() : '',
});
Expand Down Expand Up @@ -252,7 +260,9 @@ class SectionIO extends Component<
}
const data: ArtifactInfo = {
id,
name: (getResourceProperty(artifact, ArtifactProperties.NAME) || '') as string, // TODO: assert name is string
name: (getResourceProperty(artifact, ArtifactProperties.NAME) ||
getResourceProperty(artifact, ArtifactCustomProperties.NAME, true) ||
'') as string, // TODO: assert name is string
typeId: artifact.getTypeId(),
uri: artifact.getUri() || '',
};
Expand Down
50 changes: 46 additions & 4 deletions frontend/src/pages/ExecutionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ import {
} from '../lib/Utils';
import { Link } from 'react-router-dom';
import { RoutePage, RouteParams } from '../components/Router';
import { Execution, ExecutionType } from '../generated/src/apis/metadata/metadata_store_pb';
import { ListRequest, ExecutionProperties, ExecutionCustomProperties, Apis } from '../lib/Apis';
import { Execution, ExecutionType, Context, Association } from '../generated/src/apis/metadata/metadata_store_pb';
import { ListRequest, ExecutionProperties, ExecutionCustomProperties, ContextCustomProperties, Apis } from '../lib/Apis';
import {
GetExecutionsRequest,
GetExecutionTypesRequest,
GetContextsRequest,
} from '../generated/src/apis/metadata/metadata_store_service_pb';

interface ExecutionListState {
Expand Down Expand Up @@ -179,6 +180,41 @@ class ExecutionList extends Page<{}, ExecutionListState> {
executionTypesMap.set(executionType.getId()!, executionType);
});

const contextsMap = new Map<number, Context>();
const {
error: contexts_err,
response: contexts_res,
} = await Apis.getMetadataServicePromiseClient().getContexts(
new GetContextsRequest(),
);

if (contexts_err) {
this.showPageError(serviceErrorToString(contexts_err));
return;
}

((contexts_res && contexts_res.getContextsList()) || []).forEach(context => {
contextsMap.set(context.getId()!, context);
});

const executionIdToContextIdMap = new Map<number, number>();
const {
error: associations_err,
response: associations_res,
} = await Apis.getMetadataServicePromiseClient().getAssociations(
new GetAssociationsRequest(),
);

if (associations_err) {
this.showPageError(serviceErrorToString(associations_err));
return;
}

((associations_res && associations_res.getAssociationsList()) || []).forEach(association => {
executionIdToContextIdMap.set(association.getExecutionId()!, association.getContextId()!);
});


const collapsedAndExpandedRows = groupRows(
executions
.map(execution => {
Expand All @@ -188,12 +224,18 @@ class ExecutionList extends Page<{}, ExecutionListState> {
typeId && executionTypesMap && executionTypesMap.get(typeId)
? executionTypesMap.get(typeId)!.getName()
: typeId;
const executiontId = execution.getId()!;
const contextId = executionIdToContextIdMap.get(executionId);
const context = contextId ? contextsMap.get(contextId) : undefined;
return {
id: `${type}:${execution.getId()}`, // Join with colon so we can build the link
otherFields: [
getResourceProperty(execution, ExecutionProperties.PIPELINE_NAME) ||
getResourceProperty(execution, ExecutionCustomProperties.WORKSPACE, true),
getResourceProperty(execution, ExecutionProperties.COMPONENT_ID),
getResourceProperty(execution, ExecutionCustomProperties.WORKSPACE, true) ||
getResourceProperty(execution, ExecutionCustomProperties.RUN_ID, true) ||
(context ? getResourceProperty(context, ContextCustomProperties.RUN_ID, true) : undefined),
getResourceProperty(execution, ExecutionProperties.COMPONENT_ID) ||
getResourceProperty(execution, ExecutionCustomProperties.TASK_ID, true),
getResourceProperty(execution, ExecutionProperties.STATE),
execution.getId(),
type,
Expand Down