Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
Signed-off-by: yujin-emma <[email protected]>
  • Loading branch information
yujin-emma committed Feb 14, 2024
1 parent 6f427da commit 248fc80
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 237 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ export async function checkConflictsForDataSource({
} else {
const omitOriginId = ignoreRegularConflicts;
importIdMap.set(`${type}:${id}`, { id: `${dataSourceId}_${rawId}`, omitOriginId });
// console.log("in check data source conflict", `${type}:${id}`)
// pendingOverwrites.add(`${type}:${id}`);
filteredObjects.push({ ...object, id: `${dataSourceId}_${rawId}` });
}
}
Expand Down
1 change: 0 additions & 1 deletion src/core/server/saved_objects/import/check_conflicts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ export async function checkConflicts({
(acc, { type, id, error }) => acc.set(`${type}:${id}`, error),
new Map<string, SavedObjectError>()
);
console.log("in checkk conclict", checkConflictsResult);

objects.forEach((object) => {
const {
Expand Down
236 changes: 2 additions & 234 deletions src/core/server/saved_objects/import/import_saved_objects.ts
Original file line number Diff line number Diff line change
@@ -1,235 +1,3 @@
// /*
// * SPDX-License-Identifier: Apache-2.0
// *
// * The OpenSearch Contributors require contributions made to
// * this file be licensed under the Apache-2.0 license or a
// * compatible open source license.
// *
// * Any modifications Copyright OpenSearch Contributors. See
// * GitHub history for details.
// */

// /*
// * Licensed to Elasticsearch B.V. under one or more contributor
// * license agreements. See the NOTICE file distributed with
// * this work for additional information regarding copyright
// * ownership. Elasticsearch B.V. licenses this file to you under
// * the Apache License, Version 2.0 (the "License"); you may
// * not use this file except in compliance with the License.
// * You may obtain a copy of the License at
// *
// * http://www.apache.org/licenses/LICENSE-2.0
// *
// * Unless required by applicable law or agreed to in writing,
// * software distributed under the License is distributed on an
// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// * KIND, either express or implied. See the License for the
// * specific language governing permissions and limitations
// * under the License.
// */

// import { collectSavedObjects } from './collect_saved_objects';
// import {
// SavedObjectsImportError,
// SavedObjectsImportResponse,
// SavedObjectsImportOptions,
// } from './types';
// import { validateReferences } from './validate_references';
// import { checkOriginConflicts } from './check_origin_conflicts';
// import { createSavedObjects } from './create_saved_objects';
// import { checkConflicts } from './check_conflicts';
// import { regenerateIds } from './regenerate_ids';
// import { checkConflictsForDataSource } from './check_conflict_for_data_source';

// /**
// * Import saved objects from given stream. See the {@link SavedObjectsImportOptions | options} for more
// * detailed information.
// *
// * @public
// */
// export async function importSavedObjectsFromStream({
// readStream,
// objectLimit,
// overwrite,
// createNewCopies,
// savedObjectsClient,
// typeRegistry,
// namespace,
// dataSourceId,
// dataSourceTitle,
// }: SavedObjectsImportOptions): Promise<SavedObjectsImportResponse> {
// let errorAccumulator: SavedObjectsImportError[] = [];
// const supportedTypes = typeRegistry.getImportableAndExportableTypes().map((type) => type.name);

// // Get the objects to import
// const collectSavedObjectsResult = await collectSavedObjects({
// readStream,
// objectLimit,
// supportedTypes,
// dataSourceId,
// });
// errorAccumulator = [...errorAccumulator, ...collectSavedObjectsResult.errors];
// /** Map of all IDs for objects that we are attempting to import; each value is empty by default */
// let importIdMap = collectSavedObjectsResult.importIdMap;
// let pendingOverwrites = new Set<string>();

// // Validate references
// const validateReferencesResult = await validateReferences(
// collectSavedObjectsResult.collectedObjects,
// savedObjectsClient,
// namespace
// );
// errorAccumulator = [...errorAccumulator, ...validateReferencesResult];

// if (createNewCopies) {
// // randomly generated id
// importIdMap = regenerateIds(collectSavedObjectsResult.collectedObjects, dataSourceId);
// } else {
// // in check conclict and override mode
// // Check single-namespace objects for conflicts in this namespace, and check multi-namespace objects for conflicts across all namespaces
// const checkConflictsParams = {
// objects: collectSavedObjectsResult.collectedObjects,
// savedObjectsClient,
// namespace,
// ignoreRegularConflicts: overwrite,
// };

// // resolve when data source exist, pass the filtered objects to next check conflict
// if (dataSourceId) {
// const checkConflictsForDataSourceResult = await checkConflictsForDataSource({
// objects: collectSavedObjectsResult.collectedObjects,
// ignoreRegularConflicts: overwrite,
// dataSourceId,
// });

// // checkConflictsParams.objects = checkConflictsForDataSourceResult.filteredObjects;

// pendingOverwrites = new Set([
// ...pendingOverwrites,
// ...checkConflictsForDataSourceResult.pendingOverwrites,
// ]);
// importIdMap = new Map([...importIdMap, ...checkConflictsForDataSourceResult.importIdMap]);

// }
// console.log("in import saved objects, data source", pendingOverwrites)


// const checkConflictsResult = await checkConflicts(checkConflictsParams);
// errorAccumulator = [...errorAccumulator, ...checkConflictsResult.errors];
// importIdMap = new Map([...importIdMap, ...checkConflictsResult.importIdMap]);
// pendingOverwrites = new Set([...pendingOverwrites, ...checkConflictsResult.pendingOverwrites]);
// console.log("in import saved objects, checkConflictsResult", checkConflictsResult.pendingOverwrites)

// // Check multi-namespace object types for origin conflicts in this namespace
// const checkOriginConflictsParams = {
// objects: checkConflictsResult.filteredObjects,
// savedObjectsClient,
// typeRegistry,
// namespace,
// ignoreRegularConflicts: overwrite,
// importIdMap,
// };

// if (dataSourceId) {
// const checkConflictsForDataSourceResult = await checkConflictsForDataSource({
// objects: checkConflictsResult.filteredObjects, //collectSavedObjectsResult.collectedObjects,
// ignoreRegularConflicts: overwrite,
// dataSourceId,
// });

// // checkConflictsParams.objects = checkConflictsForDataSourceResult.filteredObjects;

// // pendingOverwrites = new Set([
// // ...pendingOverwrites,
// // ...checkConflictsForDataSourceResult.pendingOverwrites,
// // ]);
// // importIdMap = new Map([...importIdMap, ...checkConflictsForDataSourceResult.importIdMap]);
// checkOriginConflictsParams.objects = checkConflictsForDataSourceResult.filteredObjects;

// }

// const checkOriginConflictsResult = await checkOriginConflicts(checkOriginConflictsParams);
// errorAccumulator = [...errorAccumulator, ...checkOriginConflictsResult.errors];
// importIdMap = new Map([...importIdMap, ...checkOriginConflictsResult.importIdMap]);
// pendingOverwrites = new Set([
// ...pendingOverwrites,
// ...checkOriginConflictsResult.pendingOverwrites,
// ]);

// console.log("in import saved objects, pendingOverwrites checkOriginConflictsResult", pendingOverwrites)

// // if (dataSourceId) {
// // const checkConflictsForDataSourceResult = await checkConflictsForDataSource({
// // objects: checkConflictsResult.filteredObjects, //collectSavedObjectsResult.collectedObjects,
// // ignoreRegularConflicts: overwrite,
// // dataSourceId,
// // });

// // // checkConflictsParams.objects = checkConflictsForDataSourceResult.filteredObjects;

// // pendingOverwrites = new Set([
// // ...pendingOverwrites,
// // ...checkConflictsForDataSourceResult.pendingOverwrites,
// // ]);
// // importIdMap = new Map([...importIdMap, ...checkConflictsForDataSourceResult.importIdMap]);

// // }
// }

// // console.log("in import saved objects, pendingOverwrites after adding checkOriginConflictsResult", pendingOverwrites)

// // Create objects in bulk
// const createSavedObjectsParams = {
// objects: dataSourceId
// ? collectSavedObjectsResult.collectedObjects.filter((object) => object.type !== 'data-source')
// : collectSavedObjectsResult.collectedObjects,
// accumulatedErrors: errorAccumulator,
// savedObjectsClient,
// importIdMap,
// overwrite,
// namespace,
// dataSourceId,
// dataSourceTitle,
// };
// const createSavedObjectsResult = await createSavedObjects(createSavedObjectsParams);
// errorAccumulator = [...errorAccumulator, ...createSavedObjectsResult.errors];

// const successResults = createSavedObjectsResult.createdObjects.map(
// ({ type, id, attributes: { title }, destinationId, originId }) => {
// const meta = { title, icon: typeRegistry.getType(type)?.management?.icon };
// // console.log("`${type}:${id}`", `${type}:${id}`)
// const attemptedOverwrite = pendingOverwrites.has(`${type}:${id}`);
// console.log("attemptedOverwrite", attemptedOverwrite)
// return {
// type,
// id,
// meta,
// ...(attemptedOverwrite && { overwrite: true }),
// ...(destinationId && { destinationId }),
// ...(destinationId && !originId && !createNewCopies && { createNewCopy: true }),
// };
// }
// );

// const errorResults = errorAccumulator.map((error) => {
// const icon = typeRegistry.getType(error.type)?.management?.icon;
// const attemptedOverwrite = pendingOverwrites.has(`${error.type}:${error.id}`);
// return {
// ...error,
// meta: { ...error.meta, icon },
// ...(attemptedOverwrite && { overwrite: true }),
// };
// });

// return {
// successCount: createSavedObjectsResult.createdObjects.length,
// success: errorAccumulator.length === 0,
// ...(successResults.length && { successResults }),
// ...(errorResults.length && { errors: errorResults }),
// };
// }


/*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down Expand Up @@ -342,7 +110,7 @@ export async function importSavedObjectsFromStream({
};

/**
* If dataSourceId exist,
* If dataSourceId exist
*/
if (dataSourceId) {
const checkConflictsForDataSourceResult = await checkConflictsForDataSource({
Expand Down Expand Up @@ -409,4 +177,4 @@ export async function importSavedObjectsFromStream({
...(successResults.length && { successResults }),
...(errorResults.length && { errors: errorResults }),
};
}
}

0 comments on commit 248fc80

Please sign in to comment.