diff --git a/src/plugins/point_in_time_management/public/components/pit_table/pit_table.tsx b/src/plugins/point_in_time_management/public/components/pit_table/pit_table.tsx
index 56e56302ae7f..7c8425b224f0 100644
--- a/src/plugins/point_in_time_management/public/components/pit_table/pit_table.tsx
+++ b/src/plugins/point_in_time_management/public/components/pit_table/pit_table.tsx
@@ -38,6 +38,8 @@ import {
PointInTime,
createSavedObject,
getSavedPits,
+ deletePointInTimeById,
+ updatePointInTimeSavedObject,
} from '../utils';
import { EmptyState, NoDataSourceState } from './empty_state';
// import { PageHeader } from './page_header';
@@ -58,6 +60,7 @@ export interface DashboardPitItem {
name: string;
creation_time: number;
keep_alive: number;
+ delete_on_expiry: boolean;
}
export interface PitItem {
@@ -129,6 +132,11 @@ const PITTable = ({ history }: RouteComponentProps) => {
});
};
+ const navigateEdit = (pit) => {
+ console.log(pit);
+ history.push(`${pit.id}`);
+ };
+
const getPits = (dataSourceId?: string) => {
// setMessage(<>Loading PITs...>);
setLoading(true);
@@ -168,46 +176,85 @@ const PITTable = ({ history }: RouteComponentProps) => {
// if (fetchedDataSources?.length) {
// setDashboardPits(fetchedDataSources);
// }
-
+ console.log('dashboard pits', fetchedDashboardPits);
setLoading(false);
if (fetchedPits?.resp?.pits) {
- let expiredPits: DashboardPitItem[] = [];
+ const expiredPits: DashboardPitItem[] = [];
+ // if (dataSourceId === undefined) {
+ // expiredPits = fetchedDashboardPits.filter(
+ // (x) => !fetchedPits?.resp?.pits.some((x2) => x.attributes.id === x2.pit_id)
+ // );
+ // }
+ // console.log('expired', expiredPits);
+ // expiredPits.filter(x=>x.attributes.delete_on_expiry).forEach(x=> {
+ // console.log('deleting ', x)
+ // deletePointInTimeById(savedObjects.client, x.id);
+ // })
+
if (dataSourceId === undefined) {
- expiredPits = fetchedDashboardPits.filter(
- (x) => !fetchedPits?.resp?.pits.some((x2) => x.attributes.id === x2.pit_id)
- );
+ fetchedDashboardPits.forEach((x) => {
+ if (!fetchedPits?.resp?.pits.some((x2) => x.attributes.pit_id === x2.pit_id)) {
+ if (x.attributes.delete_on_expiry) {
+ console.log('deleting ', x);
+ deletePointInTimeById(savedObjects.client, x.id);
+ } else {
+ expiredPits.push(x);
+ }
+ }
+ });
}
console.log('expired', expiredPits);
+
setPits(
fetchedPits?.resp?.pits
.map((val) => {
const date = moment(val.creation_time);
- let formattedDate = date.format('MMM D @ HH:mm:ss');
+ const formattedDate = date.format('MMM D @ HH:mm:ss');
const expiry = val.creation_time + val.keep_alive;
const dashboardPit = fetchedDashboardPits.filter(
- (x) => x.attributes.id === val.pit_id
+ (x) => x.attributes.pit_id === val.pit_id
);
- console.log(dashboardPit);
if (dashboardPit.length > 0) {
- formattedDate = dashboardPit[0].attributes.name;
+ console.log(dashboardPit);
+ dashboardPit[0].attributes.keepAlive = val.keep_alive;
+ console.log('updating', dashboardPit);
+ updatePointInTimeSavedObject(
+ savedObjects.client,
+ dashboardPit[0].id,
+ dashboardPit[0].attributes,
+ dashboardPit[0].references
+ );
+ return {
+ pit_id: val.pit_id,
+ id: dashboardPit[0].id,
+ name: dashboardPit[0].attributes.name,
+ creation_time: val.creation_time,
+ keep_alive: val.keep_alive,
+ dataSource: dataSourceName,
+ isSavedObject: true,
+ expiry,
+ };
}
-
return {
pit_id: val.pit_id,
+ id: val.id,
name: formattedDate,
creation_time: val.creation_time,
keep_alive: val.keep_alive,
dataSource: dataSourceName,
+ isSavedObject: false,
expiry,
};
})
.concat(
expiredPits.map((x) => ({
- pit_id: x.attributes.id,
+ pit_id: x.attributes.pit_id,
name: x.attributes.name,
+ id: x.id,
creation_time: x.attributes.creation_time,
keep_alive: x.attributes.keepAlive,
dataSource: dataSourceName,
+ isSavedObject: true,
expiry: x.attributes.creation_time + x.attributes.keepAlive,
}))
)
@@ -238,17 +285,18 @@ const PITTable = ({ history }: RouteComponentProps) => {
const createPointInTime = () => {
// setIsFlyoutVisible(false);
const pit: PointInTime = {
- id:
- 'o463QQEKbXktaW5kZXgtMRZtN2RWMHdaRlNILThIMUVWWDJJMVBRABZxMlNNZVdPZVRGbVR6MUxPc1RZYkx3AAAAAAAAAAAjFmhZdDNoTk9hUlBlVng2RVNIMUNhelEBFm03ZFYwd1pGU0gtOEgxRVZYMkkxUFEAAA==',
- keepAlive: 600000,
- creation_time: 1681386155468,
- name: 'PIT-my-index-2', // Todo create pit and fill the pit id
+ pit_id:
+ 'o463QQEKbXktaW5kZXgtMRZqUlZFU2lSaFE1eUx0cHdiSjNLWjRRABZtWjNCdk1ZdFRZbS1JbnltaVlBTWdBAAAAAAAAAACGFlJXLVVNYXVQVFctQVIxVmh1OUJuSlEBFmpSVkVTaVJoUTV5THRwd2JKM0taNFEAAA==',
+ keepAlive: 30000000,
+ creation_time: 1684418768188,
+ name: 'PIT-my-index-1223', // Todo create pit and fill the pit id
+ delete_on_expiry: false,
};
const reference: SavedObjectReference = {
- id: 'ff959d40-b880-11e8-a6d9-e546fe2bba5f',
+ id: '5586e600-f57b-11ed-90e3-a75eeb2a18a5',
type: 'index-pattern',
- name: 'opensearch_dashboards_sample_data_ecommerce',
+ name: 'my*',
};
createSavedObject(pit, savedObjects.client, reference);
};
@@ -366,7 +414,7 @@ const PITTable = ({ history }: RouteComponentProps) => {
description: 'Configure PIT',
icon: 'pencil',
type: 'icon',
- onClick: fetchDataSources,
+ onClick: navigateEdit, // route it to edit page --> create a route page
},
{
name: 'Delete',
@@ -664,4 +712,4 @@ const PITTable = ({ history }: RouteComponentProps) => {
);
};
-export const PITTableWithRouter = withRouter(PITTable);
+export const PITTableWithRouter = withRouter(PITTable);
\ No newline at end of file
diff --git a/src/plugins/point_in_time_management/public/components/utils.ts b/src/plugins/point_in_time_management/public/components/utils.ts
index 412458710c3e..fc1522624901 100644
--- a/src/plugins/point_in_time_management/public/components/utils.ts
+++ b/src/plugins/point_in_time_management/public/components/utils.ts
@@ -3,11 +3,11 @@
* SPDX-License-Identifier: Apache-2.0
*/
-import { HttpStart, SavedObjectsClientContract } from 'src/core/public';
-//import { DuplicateIndexPatternError, IndexPattern } from 'src/plugins/data/common';
+
+
+import { HttpStart, SavedObjectReference, SavedObjectsClientContract } from 'src/core/public';
import { DataSourceAttributes } from 'src/plugins/data_source/common/data_sources';
-import { IndexPatternCreationConfig } from 'src/plugins/index_pattern_management/public';
-import { responseToItemArray } from 'src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/lib/get_indices';
+import { PointInTimeAttributes } from '../types';
import { ResolveIndexResponse } from 'src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/types';
export async function getDataSources(savedObjectsClient: SavedObjectsClientContract) {
@@ -64,16 +64,17 @@ export async function getDataSources(savedObjectsClient: SavedObjectsClientContr
export interface PointInTime {
name: string;
keepAlive: number;
- id: string;
+ pit_id: string;
creation_time: number;
+ id?: string;
+ delete_on_expiry: boolean;
}
-
-export interface SavedObjectReference {
- name?: string;
- id: string;
- type: string;
-}
-
+// export interface SavedObjectReference {
+// name?: string;
+// id: string;
+// type: string;
+// }
+
export async function getIndexPatterns(savedObjectsClient: SavedObjectsClientContract) {
return (
savedObjectsClient
@@ -114,7 +115,7 @@ export async function getSavedPits(client: SavedObjectsClientContract) {
const savedObjects = await client.find({
type: 'point-in-time',
perPage: 1000,
- fields: ['id', 'creation_time', 'keepAlive', 'name'],
+ fields: ['id', 'creation_time', 'keepAlive', 'name', 'pit_id', 'delete_on_expiry'],
});
return savedObjects.savedObjects;
@@ -126,26 +127,52 @@ export async function findById(client: SavedObjectsClientContract, id: string) {
const savedObjects = await client.find({
type: 'point-in-time',
perPage: 1000,
- // search: `${id}`,
- // searchFields: ['id'],
- fields: ['id'],
+ fields: [],
});
- console.log(savedObjects.savedObjects);
- return savedObjects.savedObjects.find(
- (obj) => obj.attributes.id.toLowerCase() === id.toLowerCase()
- );
+ return savedObjects.savedObjects.find((obj) => obj.id === id);
}
}
+export async function updatePointInTimeById(
+ savedObjectsClient: SavedObjectsClientContract,
+ id: string,
+ attributes: PointInTimeAttributes
+) {
+ return savedObjectsClient.update('point-in-time', id, attributes);
+}
+
+export async function updatePointInTimeSavedObject(
+ savedObjectsClient: SavedObjectsClientContract,
+ id: string,
+ attributes: PointInTimeAttributes,
+ reference: SavedObjectReference[]
+) {
+ return savedObjectsClient.update('point-in-time', id, attributes, { references: reference });
+}
+
+export async function deletePointInTimeById(
+ savedObjectsClient: SavedObjectsClientContract,
+ id: string
+) {
+ return savedObjectsClient.delete('point-in-time', id);
+}
+
+export async function updatePointInTimeKeepAlive(
+ savedObjectsClient: SavedObjectsClientContract,
+ id: string,
+ addTime: number
+) {}
+
export async function createSavedObject(
pointintime: PointInTime,
client: SavedObjectsClientContract,
reference: SavedObjectReference
) {
- const dupe = await findById(client, pointintime.id);
+ const dupe = await findById(client, pointintime.pit_id);
+ console.log('This is dupe output');
console.log(dupe);
if (dupe) {
- throw new Error(`Duplicate Point in time: ${pointintime.id}`);
+ throw new Error(`Duplicate Point in time: ${pointintime.pit_id}`);
}
// if (dupe) {
// if (override) {
@@ -159,11 +186,12 @@ export async function createSavedObject(
const references = [{ ...reference }];
const savedObjectType = 'point-in-time';
const response = await client.create(savedObjectType, body, {
- id: pointintime.id,
references,
});
+ console.log('This is the response');
console.log(response);
pointintime.id = response.id;
+ console.log(pointintime);
return pointintime;
}
export async function getIndicesViaResolve (
diff --git a/src/plugins/point_in_time_management/public/management_app/mount_management_section.tsx b/src/plugins/point_in_time_management/public/management_app/mount_management_section.tsx
index a25af5d4cfcc..30548d86aee4 100644
--- a/src/plugins/point_in_time_management/public/management_app/mount_management_section.tsx
+++ b/src/plugins/point_in_time_management/public/management_app/mount_management_section.tsx
@@ -13,7 +13,7 @@ import { StartServicesAccessor } from '../../../../core/public';
import { PointInTimeManagementContext } from '../types';
import { OpenSearchDashboardsContextProvider } from '../../../opensearch_dashboards_react/public';
import { PITTableWithRouter } from '../components';
-import { PointInTimeCreateForm } from '../components/create_pit';
+import { PITEditWithRouter } from '../components/pit_edit';
import { CreatePitWithRouter } from '../components/create_pit/create_pit';
export async function mountManagementSection(
@@ -38,6 +38,10 @@ export async function mountManagementSection(
+
+
+
+
{/*
*/}
diff --git a/src/plugins/point_in_time_management/public/services.ts b/src/plugins/point_in_time_management/public/services.ts
index 70eb064e35ed..bb7842b06f99 100644
--- a/src/plugins/point_in_time_management/public/services.ts
+++ b/src/plugins/point_in_time_management/public/services.ts
@@ -9,6 +9,7 @@ export interface Services {
getAllPits: (dataSourceId?: string) => Promise;
deletePits: (pits: string[], dataSourceId?: string) => any;
createPit: (index: string, keepAlive: string, allowPartialCreation: boolean, dataSourceId?: string) => any;
+ addPitTime: (pit_id: string, keepAlive: string, dataSourceId?: string) => any;
}
export function getServices(http: CoreStart['http']): Services {
@@ -20,11 +21,29 @@ export function getServices(http: CoreStart['http']): Services {
dataSourceId: dataSourceId ? dataSourceId : '',
}),
});
+ console.log('These are backend PITs');
+ console.log(response);
return response;
} catch (e) {
return e;
}
},
+ addPitTime: async (pit_id: string, keepAlive: string, dataSourceId?: string) => {
+ try {
+ console.log(pit_id, keepAlive, dataSourceId);
+ const response = await http.post('/api/pit/addTime', {
+ body: JSON.stringify({
+ dataSourceId: dataSourceId ? dataSourceId : 'default',
+ pit_id,
+ keepAlive,
+ }),
+ });
+ console.log('Updated the PIT KeepAlive');
+ console.log(response);
+ } catch (e) {
+ return e;
+ }
+ },
deletePits: async (pits: string[], dataSourceId?: string) => {
try {
diff --git a/src/plugins/point_in_time_management/server/routes/opensearch.ts b/src/plugins/point_in_time_management/server/routes/opensearch.ts
index ea701bea519b..be9b37de4cc0 100644
--- a/src/plugins/point_in_time_management/server/routes/opensearch.ts
+++ b/src/plugins/point_in_time_management/server/routes/opensearch.ts
@@ -42,6 +42,46 @@ export function registerPitRoutes(router: IRouter) {
}
);
+ router.post(
+ {
+ path: '/api/pit/addTime',
+ validate: {
+ body: schema.object({
+ dataSourceId: schema.string(),
+ pit_id: schema.string(),
+ keepAlive: schema.string(),
+ }),
+ },
+ },
+ async (context, req, res) => {
+ const client: OpenSearchClient = await getClient(req, context);
+ console.log(req.body);
+ try {
+ const response = await client.search({
+ body: {
+ size: 0,
+ pit: {
+ id: req.body.pit_id,
+ keep_alive: req.body.keepAlive,
+ },
+ },
+ });
+ return res.ok({
+ body: {
+ ok: true,
+ resp: response.body,
+ },
+ });
+ } catch (err: any) {
+ return res.ok({
+ body: {
+ ok: false,
+ resp: err.message,
+ },
+ });
+ }
+ }
+ );
router.post(
{
path: '/api/pit/delete',
diff --git a/src/plugins/point_in_time_management/server/saved_objects/pit_saved_object.ts b/src/plugins/point_in_time_management/server/saved_objects/pit_saved_object.ts
index c92f672f4235..40776a530c04 100644
--- a/src/plugins/point_in_time_management/server/saved_objects/pit_saved_object.ts
+++ b/src/plugins/point_in_time_management/server/saved_objects/pit_saved_object.ts
@@ -33,6 +33,8 @@ export const pointInTimeSavedObject: SavedObjectsType = {
creation_time: { type: 'double' },
keepAlive: { type: 'integer' },
name: { type: 'text' },
+ pit_id: { type: 'text' },
+ delete_on_expiry: { type: 'boolean' },
},
},
};