defaultIcon: ProjectIcon,
onSetColumns: jest.fn(),
defaultMessages: ['testing'],
++ contextMenuColumn: true
});
import { addRouteChangeHandlers } from './routes/routes';
import { loadWorkbench } from './store/workbench/workbench-actions';
import { Routes } from '~/routes/routes';
+ import { trashActionSet } from "~/views-components/context-menu/action-sets/trash-action-set";
+import { ServiceRepository } from '~/services/services';
+import { initWebSocket } from '~/websocket/websocket';
+import { Config } from '~/common/config';
const getBuildNumber = () => "BN-" + (process.env.REACT_APP_BUILD_NUMBER || "dev");
const getGitCommit = () => "GIT-" + (process.env.REACT_APP_GIT_COMMIT || "latest").substr(0, 7);
import { RootStore } from '~/store/store';
import { matchPath } from 'react-router';
import { ResourceKind, RESOURCE_UUID_PATTERN, extractUuidKind } from '~/models/resource';
- import { getProjectUrl } from '../models/project';
+ import { getProjectUrl } from '~/models/project';
import { getCollectionUrl } from '~/models/collection';
- import { loadProject, loadFavorites, loadCollection, loadProcessLog } from '~/store/workbench/workbench-actions';
-import { loadProject, loadFavorites, loadCollection, loadTrash } from '~/store/workbench/workbench-actions';
++import { loadProject, loadFavorites, loadCollection, loadTrash, loadProcessLog } from '~/store/workbench/workbench-actions';
import { loadProcess } from '~/store/processes/processes-actions';
export const Routes = {
COLLECTIONS: `/collections/:id(${RESOURCE_UUID_PATTERN})`,
PROCESSES: `/processes/:id(${RESOURCE_UUID_PATTERN})`,
FAVORITES: '/favorites',
- TRASH: '/trash'
++ TRASH: '/trash',
+ PROCESS_LOGS: `/process-logs/:id(${RESOURCE_UUID_PATTERN})`
};
export const getResourceUrl = (uuid: string) => {
const projectMatch = matchProjectRoute(pathname);
const collectionMatch = matchCollectionRoute(pathname);
const favoriteMatch = matchFavoritesRoute(pathname);
+ const trashMatch = matchTrashRoute(pathname);
const processMatch = matchProcessRoute(pathname);
+ const processLogMatch = matchProcessLogRoute(pathname);
+
if (projectMatch) {
store.dispatch(loadProject(projectMatch.params.id));
} else if (collectionMatch) {
store.dispatch(loadCollection(collectionMatch.params.id));
} else if (favoriteMatch) {
store.dispatch(loadFavorites());
+ } else if (trashMatch) {
+ store.dispatch(loadTrash());
} else if (processMatch) {
store.dispatch(loadProcess(processMatch.params.id));
+ } else if (processLogMatch) {
+ store.dispatch(loadProcessLog(processLogMatch.params.id));
}
};
it("#contents", async () => {
axiosMock
-- .onGet("/groups/1/contents/")
++ .onGet("/groups/1/contents")
.reply(200, {
kind: "kind",
offset: 2,
--- /dev/null
- import { CommonResourceService } from "~/common/api/common-resource-service";
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { AxiosInstance } from "axios";
+import { LogResource } from '~/models/log';
++import { CommonResourceService } from "~/services/common-service/common-resource-service";
+
+export class LogService extends CommonResourceService<LogResource> {
+ constructor(serverApi: AxiosInstance) {
+ super(serverApi, "logs");
+ }
+}
export const openProcessContextMenu = (event: React.MouseEvent<HTMLElement>) =>
(dispatch: Dispatch, getState: () => RootState) => {
+ const { location } = getState().router;
+ const pathname = location ? location.pathname : '';
+ // ToDo: We get error from matchProcessRoute
+ // const match = matchProcessRoute(pathname);
+ // console.log('match: ', match);
+ // const uuid = match ? match.params.id : '';
+ const uuid = pathname.split('/').slice(-1)[0];
const resource = {
- uuid,
+ uuid: '',
+ ownerUuid: '',
+ kind: ResourceKind.PROCESS,
name: '',
description: '',
- kind: ContextMenuKind.PROCESS
+ menuKind: ContextMenuKind.PROCESS
};
dispatch<any>(openContextMenu(event, resource));
};
--- /dev/null
- import { FilterBuilder } from '~/common/api/filter-builder';
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { unionize, ofType, UnionOf } from "~/common/unionize";
+import { ProcessLogs, getProcessLogsPanelCurrentUuid } from './process-logs-panel';
+import { LogEventType } from '~/models/log';
+import { RootState } from '~/store/store';
+import { ServiceRepository } from '~/services/services';
+import { Dispatch } from 'redux';
- import { OrderBuilder } from '~/common/api/order-builder';
+import { groupBy } from 'lodash';
+import { loadProcess } from '~/store/processes/processes-actions';
- import { ResourceEventMessage } from '../../websocket/resource-event-message';
+import { LogResource } from '~/models/log';
+import { LogService } from '~/services/log-service/log-service';
++import { ResourceEventMessage } from '~/websocket/resource-event-message';
+import { getProcess } from '~/store/processes/process';
++import { FilterBuilder } from "~/services/api/filter-builder";
++import { OrderBuilder } from "~/services/api/order-builder";
+
+export const processLogsPanelActions = unionize({
+ RESET_PROCESS_LOGS_PANEL: ofType<{}>(),
+ INIT_PROCESS_LOGS_PANEL: ofType<{ filters: string[], logs: ProcessLogs }>(),
+ SET_PROCESS_LOGS_PANEL_FILTER: ofType<string>(),
+ ADD_PROCESS_LOGS_PANEL_ITEM: ofType<{ logType: string, log: string }>(),
+});
+
+export type ProcessLogsPanelAction = UnionOf<typeof processLogsPanelActions>;
+
+export const setProcessLogsPanelFilter = (filter: string) =>
+ processLogsPanelActions.SET_PROCESS_LOGS_PANEL_FILTER(filter);
+
+export const initProcessLogsPanel = (processUuid: string) =>
+ async (dispatch: Dispatch, getState: () => RootState, { logService }: ServiceRepository) => {
+ dispatch(processLogsPanelActions.RESET_PROCESS_LOGS_PANEL());
+ const process = await dispatch<any>(loadProcess(processUuid));
+ if (process.container) {
+ const logResources = await loadContainerLogs(process.container.uuid, logService);
+ const initialState = createInitialLogPanelState(logResources);
+ dispatch(processLogsPanelActions.INIT_PROCESS_LOGS_PANEL(initialState));
+ }
+ };
+
+export const addProcessLogsPanelItem = (message: ResourceEventMessage<{ text: string }>) =>
+ async (dispatch: Dispatch, getState: () => RootState, { logService }: ServiceRepository) => {
+ if (PROCESS_PANEL_LOG_EVENT_TYPES.indexOf(message.eventType) > -1) {
+ const uuid = getProcessLogsPanelCurrentUuid(getState());
+ if (uuid) {
+ const process = getProcess(uuid)(getState().resources);
+ if (process) {
+ const { containerRequest, container } = process;
+ if (message.objectUuid === containerRequest.uuid
+ || container && message.objectUuid === container.uuid) {
+ dispatch(processLogsPanelActions.ADD_PROCESS_LOGS_PANEL_ITEM({
+ logType: SUMMARIZED_FILTER_TYPE,
+ log: message.properties.text
+ }));
+ dispatch(processLogsPanelActions.ADD_PROCESS_LOGS_PANEL_ITEM({
+ logType: message.eventType,
+ log: message.properties.text
+ }));
+ }
+ }
+ }
+ }
+ };
+
+const loadContainerLogs = async (containerUuid: string, logService: LogService) => {
+ const requestFilters = new FilterBuilder()
+ .addEqual('objectUuid', containerUuid)
+ .addIn('eventType', PROCESS_PANEL_LOG_EVENT_TYPES)
+ .getFilters();
+ const requestOrder = new OrderBuilder<LogResource>()
+ .addAsc('eventAt')
+ .getOrder();
+ const requestParams = {
+ limit: MAX_AMOUNT_OF_LOGS,
+ filters: requestFilters,
+ order: requestOrder,
+ };
+ const { items } = await logService.list(requestParams);
+ return items;
+};
+
+const createInitialLogPanelState = (logResources: LogResource[]) => {
+ const allLogs = logsToLines(logResources);
+ const groupedLogResources = groupBy(logResources, log => log.eventType);
+ const groupedLogs = Object
+ .keys(groupedLogResources)
+ .reduce((grouped, key) => ({
+ ...grouped,
+ [key]: logsToLines(groupedLogResources[key])
+ }), {});
+ const filters = [SUMMARIZED_FILTER_TYPE, ...Object.keys(groupedLogs)];
+ const logs = { [SUMMARIZED_FILTER_TYPE]: allLogs, ...groupedLogs };
+ return { filters, logs };
+};
+
+const logsToLines = (logs: LogResource[]) =>
+ logs.map(({ properties }) => properties.text);
+
+const MAX_AMOUNT_OF_LOGS = 10000;
+
+const SUMMARIZED_FILTER_TYPE = 'Summarized';
+
+const PROCESS_PANEL_LOG_EVENT_TYPES = [
+ LogEventType.ARV_MOUNT,
+ LogEventType.CRUNCH_RUN,
+ LogEventType.CRUNCHSTAT,
+ LogEventType.DISPATCH,
+ LogEventType.HOSTSTAT,
+ LogEventType.NODE_INFO,
+ LogEventType.STDERR,
+ LogEventType.STDOUT,
+];
import { RootState } from '~/store/store';
import { ServiceRepository } from '~/services/services';
import { updateResources } from '~/store/resources/resources-actions';
- import { FilterBuilder } from '~/common/api/filter-builder';
+ import { FilterBuilder } from '~/services/api/filter-builder';
import { ContainerRequestResource } from '../../models/container-request';
+import { Process } from './process';
-export const loadProcess = (uuid: string) =>
- async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
- const containerRequest = await services.containerRequestService.get(uuid);
+export const loadProcess = (containerRequestUuid: string) =>
+ async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository): Promise<Process> => {
+ const containerRequest = await services.containerRequestService.get(containerRequestUuid);
dispatch<any>(updateResources([containerRequest]));
if (containerRequest.containerUuid) {
const container = await services.containerService.get(containerRequest.containerUuid);
import { propertiesReducer } from './properties/properties-reducer';
import { RootState } from './store';
import { fileUploaderReducer } from './file-uploader/file-uploader-reducer';
+ import { TrashPanelMiddlewareService } from "~/store/trash-panel/trash-panel-middleware-service";
+ import { TRASH_PANEL_ID } from "~/store/trash-panel/trash-panel-action";
+import { processLogsPanelReducer } from './process-logs-panel/process-logs-panel-reducer';
const composeEnhancers =
(process.env.NODE_ENV === 'development' &&
import * as collectionMoveActions from '~/store/collections/collection-move-actions';
import * as processesActions from '../processes/processes-actions';
import { getProcess } from '../processes/process';
+ import { trashPanelColumns } from "~/views/trash-panel/trash-panel";
+ import { loadTrashPanel, trashPanelActions } from "~/store/trash-panel/trash-panel-action";
+import { initProcessLogsPanel } from '../process-logs-panel/process-logs-panel-actions';
export const loadWorkbench = () =>
<Route path={Routes.COLLECTIONS} component={CollectionPanel} />
<Route path={Routes.FAVORITES} component={FavoritePanel} />
<Route path={Routes.PROCESSES} component={ProcessPanel} />
+ <Route path={Routes.TRASH} component={TrashPanel} />
+ <Route path={Routes.PROCESS_LOGS} component={ProcessLogPanel} />
</Switch>
</div>
{user && <DetailsPanel />}
--- /dev/null
- import { CommonResourceService } from '~/common/api/common-resource-service';
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { AuthService } from '~/services/auth-service/auth-service';
+import { ResourceEventMessage } from './resource-event-message';
+import { camelCase } from 'lodash';
++import { CommonResourceService } from "~/services/common-service/common-resource-service";
+
+type MessageListener = (message: ResourceEventMessage) => void;
+
+export class WebSocketService {
+ private ws: WebSocket;
+ private messageListener: MessageListener;
+
+ constructor(private url: string, private authService: AuthService) { }
+
+ connect() {
+ if (this.ws) {
+ this.ws.close();
+ }
+ this.ws = new WebSocket(this.getUrl());
+ this.ws.addEventListener('message', this.handleMessage);
+ this.ws.addEventListener('open', this.handleOpen);
+ }
+
+ setMessageListener = (listener: MessageListener) => {
+ this.messageListener = listener;
+ }
+
+ private getUrl() {
+ return `${this.url}?api_token=${this.authService.getApiToken()}`;
+ }
+
+ private handleMessage = (event: MessageEvent) => {
+ if (this.messageListener) {
+ const data = JSON.parse(event.data);
+ const message = CommonResourceService.mapKeys(camelCase)(data);
+ this.messageListener(message);
+ }
+ }
+
+ private handleOpen = () => {
+ this.ws.send('{"method":"subscribe"}');
+ }
+
+}
--- /dev/null
- import { loadContainers } from '../store/processes/processes-actions';
- import { FilterBuilder } from '~/common/api/filter-builder';
- import { LogEventType } from '../models/log';
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { RootStore } from '~/store/store';
+import { AuthService } from '~/services/auth-service/auth-service';
+import { Config } from '~/common/config';
+import { WebSocketService } from './websocket-service';
+import { ResourceEventMessage } from './resource-event-message';
+import { ResourceKind } from '~/models/resource';
+import { loadProcess } from '~/store/processes/processes-actions';
++import { loadContainers } from '~/store/processes/processes-actions';
++import { LogEventType } from '~/models/log';
+import { addProcessLogsPanelItem } from '../store/process-logs-panel/process-logs-panel-actions';
++import { FilterBuilder } from "~/services/api/filter-builder";
+
+export const initWebSocket = (config: Config, authService: AuthService, store: RootStore) => {
+ const webSocketService = new WebSocketService(config.websocketUrl, authService);
+ webSocketService.setMessageListener(messageListener(store));
+ webSocketService.connect();
+};
+
+const messageListener = (store: RootStore) => (message: ResourceEventMessage) => {
+ if (message.eventType === LogEventType.CREATE || message.eventType === LogEventType.UPDATE) {
+ switch (message.objectKind) {
+ case ResourceKind.CONTAINER_REQUEST:
+ return store.dispatch(loadProcess(message.objectUuid));
+ case ResourceKind.CONTAINER:
+ return store.dispatch(loadContainers(
+ new FilterBuilder().addIn('uuid', [message.objectUuid]).getFilters()
+ ));
+ default:
+ return;
+ }
+ } else {
+ return store.dispatch(addProcessLogsPanelItem(message as ResourceEventMessage<{text: string}>));
+ }
+};