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

CUMULUS-3243:Updated granule delete logic(#3366) #3367

Merged
merged 1 commit into from
May 2, 2023
Merged
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
13 changes: 11 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,15 @@ Users/clients that do not make use of these endpoints will not be impacted.
- **CUMULUS-3165**
- Update example/cumulus-tf/orca.tf to use orca v6.0.3

## [v15.0.2] 2023-04-28
## [v15.0.3] 2023-04-28

### Fixed

- **CUMULUS-3243**
- Updated granule delete logic to delete granule which is not in DynamoDB
- Updated granule unpublish logic to handle granule which is not in DynamoDB and/or CMR

## [v15.0.2] 2023-04-25

### Fixed

Expand Down Expand Up @@ -7121,7 +7129,8 @@ Note: There was an issue publishing 1.12.0. Upgrade to 1.12.1.

## [v1.0.0] - 2018-02-23

[unreleased]: https://github.com/nasa/cumulus/compare/v15.0.2...HEAD
[unreleased]: https://github.com/nasa/cumulus/compare/v15.0.3...HEAD
[v15.0.3]: https://github.com/nasa/cumulus/compare/v15.0.2...v15.0.3
[v15.0.2]: https://github.com/nasa/cumulus/compare/v15.0.1...v15.0.2
[v15.0.1]: https://github.com/nasa/cumulus/compare/v15.0.0...v15.0.1
[v15.0.0]: https://github.com/nasa/cumulus/compare/v14.1.0...v15.0.0
Expand Down
8 changes: 5 additions & 3 deletions packages/api/lib/granule-remove-from-cmr.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const { GranuleNotPublished } = require('@cumulus/errors');
const { CMR } = require('@cumulus/cmr-client');
const log = require('@cumulus/common/log');
const {
Expand Down Expand Up @@ -28,15 +27,18 @@ const { constructCollectionId } = require('@cumulus/message/Collections');
const _removeGranuleFromCmr = async (granule, collectionId) => {
log.info(`granules.removeGranuleFromCmrByGranule granule_id: ${granule.granule_id}, colletion_id: ${collectionId}`);
if (!granule.published || !granule.cmr_link) {
throw new GranuleNotPublished(`Granule ${granule.granule_id} in Collection ${collectionId} is not published to CMR, so cannot be removed from CMR`);
log.warn(`Granule ${granule.granule_id} in Collection ${collectionId} is not published to CMR, so cannot be removed from CMR`);
return;
}

const cmrSettings = await cmrjsCmrUtils.getCmrSettings();
const cmr = new CMR(cmrSettings);
const metadata = await cmr.getGranuleMetadata(granule.cmr_link);

// Use granule UR to delete from CMR
await cmr.deleteGranule(metadata.title);
if (metadata) {
await cmr.deleteGranule(metadata.title, collectionId);
}
};

/**
Expand Down
34 changes: 27 additions & 7 deletions packages/api/tests/lib/test-granule-remove-from-cmr.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,40 @@ test.after.always(async (t) => {
});
});

test('unpublishGranule() removing a granule from CMR fails if the granule is not in CMR', async (t) => {
test('unpublishGranule() removing a granule from CMR succeeds if the granule is not published to CMR', async (t) => {
const {
originalPgGranule,
pgGranuleCumulusId,
collectionId,
} = await createGranuleInPG(t, {
published: false,
cmrLink: undefined,
});
try {
await unpublishGranule({ knex: t.context.knex, pgGranuleRecord: originalPgGranule });
} catch (error) {
t.is(error.message, `Granule ${originalPgGranule.granule_id} in Collection ${collectionId} is not published to CMR, so cannot be removed from CMR`);
}
await unpublishGranule({ knex: t.context.knex, pgGranuleRecord: originalPgGranule });

t.like(
await t.context.granulePgModel.get(t.context.knex, { cumulus_id: pgGranuleCumulusId }),
{
published: false,
cmr_link: null,
}
);
});

test.serial('unpublishGranule() removing a granule from CMR succeeds if the granule is not in CMR', async (t) => {
const {
originalPgGranule,
pgGranuleCumulusId,
} = await createGranuleInPG(t, {
published: true,
cmrLink: 'example.com',
});

const cmrMetadataStub = sinon.stub(CMR.prototype, 'getGranuleMetadata').resolves(undefined);
t.teardown(() => {
cmrMetadataStub.restore();
});

await unpublishGranule({ knex: t.context.knex, pgGranuleRecord: originalPgGranule });

t.like(
await t.context.granulePgModel.get(t.context.knex, { cumulus_id: pgGranuleCumulusId }),
Expand Down