Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Sync master with develop #57

Merged
merged 20 commits into from
Oct 29, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
c8a5248
Issue 50 - Fix issues with api (documentation)
xxcxy Oct 6, 2020
055ee11
Merge pull request #51 from topcoder-platform/Issue_50
callmekatootie Oct 7, 2020
7c965ca
Support enrichment for users endpoints
callmekatootie Oct 13, 2020
92af080
Merge branch 'develop' of github.com:topcoder-platform/u-bahn-api int…
callmekatootie Oct 13, 2020
365423a
Support filtering by external id on users
callmekatootie Oct 13, 2020
95eb66b
Support filtering by org id on users
callmekatootie Oct 13, 2020
211f395
Merge winning submission from enrich contest
callmekatootie Oct 20, 2020
25ea241
Working data insertion script
callmekatootie Oct 21, 2020
7f7a6cb
Working db dump script and misc
callmekatootie Oct 21, 2020
8ac769b
Restore deleted code
callmekatootie Oct 21, 2020
2bf09e4
Merge pull request #54 from topcoder-platform/enrich-2
callmekatootie Oct 21, 2020
310adc9
1. Set the enrich policy name as a config
callmekatootie Oct 22, 2020
07ea1ad
Merge pull request #56 from topcoder-platform/enrich
callmekatootie Oct 22, 2020
2f5269e
Update elasticsearch host to support elastic cloud since we are using…
callmekatootie Oct 22, 2020
3006252
touch
cwdcwd Oct 22, 2020
e76171c
Debug why db to es migration script failed
callmekatootie Oct 23, 2020
f58967f
Merge branch 'develop' of github.com:topcoder-platform/u-bahn-api int…
callmekatootie Oct 23, 2020
49aa2fb
more debugging
callmekatootie Oct 23, 2020
354fedf
Fix issue where data migration from db to es fails
callmekatootie Oct 23, 2020
6235c7f
Fix issue where data migration from db to es fails
callmekatootie Oct 23, 2020
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ Configuration for the application is at config/default.js and config/production.
- UBAHN_AGGREGATE_TOPIC: Kafka topic that is used to combine all create, update and delete message(s)
- ES.HOST: Elasticsearch host
- ES.DOCUMENTS: Elasticsearch index, type and id mapping for resources.
- ATTRIBUTE_GROUP_PIPELINE_ID: The pipeline id for enrichment with attribute group. Default is `attributegroup-pipeline`
- SKILL_PROVIDER_PIPELINE_ID: The pipeline id for enrichment with skill provider. Default is `skillprovider-pipeline`
- USER_PIPELINE_ID: The pipeline id for enrichment of user details. Default is `user-pipeline`

For `ES.DOCUMENTS` configuration, you will find multiple other configurations below it. Each has default values that you can override using the environment variables

Expand Down
10 changes: 6 additions & 4 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ module.exports = {
// ElasticSearch
ES: {
HOST: process.env.ES_HOST || 'http://localhost:9200',
ENRICH_USER_PIPELINE_NAME: process.env.ENRICH_USER_PIPELINE_NAME || 'enrich_user',
// es mapping: _index, _type, _id
DOCUMENTS: {
achievementprovider: {
Expand All @@ -64,7 +63,8 @@ module.exports = {
},
attributegroup: {
index: process.env.ATTRIBUTE_GROUP_INDEX || 'attribute_group',
type: '_doc'
type: '_doc',
pipelineId: process.env.ATTRIBUTE_GROUP_PIPELINE_ID || 'attributegroup-pipeline'
},
organization: {
index: process.env.ORGANIZATION_INDEX || 'organization',
Expand All @@ -80,11 +80,13 @@ module.exports = {
},
skillprovider: {
index: process.env.SKILL_PROVIDER_INDEX || 'skill_provider',
type: '_doc'
type: '_doc',
pipelineId: process.env.SKILL_PROVIDER_PIPELINE_ID || 'skillprovider-pipeline'
},
user: {
index: process.env.USER_INDEX || 'user',
type: '_doc'
type: '_doc',
pipelineId: process.env.USER_PIPELINE_ID || 'user-pipeline'
},
// sub resources under user
achievement: {
Expand Down
149 changes: 124 additions & 25 deletions scripts/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,136 @@
const config = require('config')

const topResources = {
skillprovider: {
index: config.get('ES.DOCUMENTS.skillprovider.index'),
type: config.get('ES.DOCUMENTS.skillprovider.type'),
enrich: {
policyName: 'skillprovider-policy',
matchField: 'id',
enrichFields: ['id', 'name', 'created', 'updated', 'createdBy', 'updatedBy']
},
pipeline: {
id: config.get('ES.DOCUMENTS.skillprovider.pipelineId'),
field: 'skillProviderId',
targetField: 'skillprovider',
maxMatches: '1'
}
},

role: {
index: config.get('ES.DOCUMENTS.role.index'),
type: config.get('ES.DOCUMENTS.role.type'),
enrich: {
policyName: 'role-policy',
matchField: 'id',
enrichFields: ['id', 'name', 'created', 'updated', 'createdBy', 'updatedBy']
}
},

achievementprovider: {
index: config.get('ES.DOCUMENTS.achievementprovider.index'),
enrichPolicy: 'achievementprovider-policy',
type: config.get('ES.DOCUMENTS.achievementprovider.type')
},
attribute: {
index: config.get('ES.DOCUMENTS.attribute.index'),
enrichPolicy: 'attribute-policy',
type: config.get('ES.DOCUMENTS.attribute.type')
type: config.get('ES.DOCUMENTS.achievementprovider.type'),
enrich: {
policyName: 'achievementprovider-policy',
matchField: 'id',
enrichFields: ['id', 'name', 'created', 'updated', 'createdBy', 'updatedBy']
}
},

attributegroup: {
index: config.get('ES.DOCUMENTS.attributegroup.index'),
type: config.get('ES.DOCUMENTS.attributegroup.type')
},
organization: {
index: config.get('ES.DOCUMENTS.organization.index'),
enrichPolicy: 'organization-policy',
type: config.get('ES.DOCUMENTS.organization.type')
},
role: {
index: config.get('ES.DOCUMENTS.role.index'),
enrichPolicy: 'role-policy',
type: config.get('ES.DOCUMENTS.role.type')
type: config.get('ES.DOCUMENTS.attributegroup.type'),
enrich: {
policyName: 'attributegroup-policy',
matchField: 'id',
enrichFields: ['id', 'name', 'organizationId', 'created', 'updated', 'createdBy', 'updatedBy']
},
pipeline: {
id: config.get('ES.DOCUMENTS.attributegroup.pipelineId'),
field: 'attributeGroupId',
targetField: 'attributegroup',
maxMatches: '1'
}
},

skill: {
index: config.get('ES.DOCUMENTS.skill.index'),
enrichPolicy: 'skill-policy',
type: config.get('ES.DOCUMENTS.skill.type')
type: config.get('ES.DOCUMENTS.skill.type'),
enrich: {
policyName: 'skill-policy',
matchField: 'id',
enrichFields: ['id', 'skillProviderId', 'name', 'externalId', 'uri', 'created', 'updated', 'createdBy', 'updatedBy', 'skillprovider']
},
ingest: {
pipeline: {
id: config.get('ES.DOCUMENTS.skillprovider.pipelineId')
}
}
},
skillprovider: {
index: config.get('ES.DOCUMENTS.skillprovider.index'),
type: config.get('ES.DOCUMENTS.skillprovider.type')

attribute: {
index: config.get('ES.DOCUMENTS.attribute.index'),
type: config.get('ES.DOCUMENTS.attribute.type'),
enrich: {
policyName: 'attribute-policy',
matchField: 'id',
enrichFields: ['id', 'name', 'attributeGroupId', 'created', 'updated', 'createdBy', 'updatedBy', 'attributegroup']
},
ingest: {
pipeline: {
id: config.get('ES.DOCUMENTS.attributegroup.pipelineId')
}
}
},

organization: {
index: config.get('ES.DOCUMENTS.organization.index'),
type: config.get('ES.DOCUMENTS.organization.type')
},

user: {
index: config.get('ES.DOCUMENTS.user.index'),
type: config.get('ES.DOCUMENTS.user.type')
type: config.get('ES.DOCUMENTS.user.type'),
pipeline: {
id: config.get('ES.DOCUMENTS.user.pipelineId'),
processors: [
{
referenceField: config.get('ES.DOCUMENTS.achievement.userField'),
enrichPolicyName: 'achievementprovider-policy',
field: '_ingest._value.achievementsProviderId',
targetField: '_ingest._value.achievementprovider',
maxMatches: '1'
},
{
referenceField: config.get('ES.DOCUMENTS.externalprofile.userField'),
enrichPolicyName: 'organization-policy',
field: '_ingest._value.organizationId',
targetField: '_ingest._value.organization',
maxMatches: '1'
},
{
referenceField: config.get('ES.DOCUMENTS.userattribute.userField'),
enrichPolicyName: 'attribute-policy',
field: '_ingest._value.attributeId',
targetField: '_ingest._value.attribute',
maxMatches: '1'
},
{
referenceField: config.get('ES.DOCUMENTS.userrole.userField'),
enrichPolicyName: 'role-policy',
field: '_ingest._value.roleId',
targetField: '_ingest._value.role',
maxMatches: '1'
},
{
referenceField: config.get('ES.DOCUMENTS.userskill.userField'),
enrichPolicyName: 'skill-policy',
field: '_ingest._value.skillId',
targetField: '_ingest._value.skill',
maxMatches: '1'
}
]
}
}
}

Expand Down Expand Up @@ -72,7 +166,12 @@ const userResources = {
const organizationResources = {
organizationskillprovider: {
propertyName: config.get('ES.DOCUMENTS.organizationskillprovider.orgField'),
relateKey: 'skillProviderId'
relateKey: 'skillProviderId',
enrich: {
policyName: 'organization-policy',
matchField: 'id',
enrichFields: ['id', 'name', 'created', 'updated', 'createdBy', 'updatedBy', 'skillProviders']
}
}
}

Expand Down
41 changes: 40 additions & 1 deletion scripts/db/dropAll.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,63 @@
const _ = require('lodash')
const models = require('../../src/models')
const logger = require('../../src/common/logger')
const { topResources, modelToESIndexMapping } = require('../constants')
const {
topResources,
organizationResources,
modelToESIndexMapping
} = require('../constants')
const { getESClient } = require('../../src/common/es-client')

async function main () {
const client = getESClient()

try {
logger.info('Deleting all pipelines...')
await client.ingest.deletePipeline({
id: topResources.user.pipeline.id
})
await client.ingest.deletePipeline({
id: topResources.skillprovider.pipeline.id
})
await client.ingest.deletePipeline({
id: topResources.attributegroup.pipeline.id
})
logger.info('Successfully deleted')
} catch (e) {
console.error(e)
logger.warn('Delete all ingest pipelines failed')
}

const keys = Object.keys(models)
for (let i = 0; i < keys.length; i++) {
const key = keys[i]
if (models[key].tableName) {
const esResourceName = modelToESIndexMapping[key]
try {
if (_.includes(_.keys(topResources), esResourceName)) {
if (topResources[esResourceName].enrich) {
logger.info(`Deleting enrich policy for ${esResourceName}`)
await client.enrich.deletePolicy({
name: topResources[esResourceName].enrich.policyName
})
logger.info(`Successfully deleted enrich policy for ${esResourceName}`)
}
logger.info(`Deleting index for ${esResourceName}`)
await client.indices.delete({
index: topResources[esResourceName].index
})
logger.info(`Successfully deleted enrich policy for ${esResourceName}`)
} else if (_.includes(_.keys(organizationResources), esResourceName)) {
logger.info('Deleting enrich policy for organization')
await client.enrich.deletePolicy({
name: organizationResources[esResourceName].enrich.policyName
})
logger.info('Successfully deleted enrich policy for organization')
}

logger.info(`Deleting data in QLDB for ${esResourceName}`)
await models.DBHelper.clear(models[key])
logger.info(`Successfully deleted data in QLDB for ${esResourceName}`)
} catch (e) {
console.error(e)
logger.warn(`drop table ${key} failed`)
Expand Down
Loading