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

Commit f236d42

Browse files
committed
Cleaning up. Removing ES. Fixing the GET return
1 parent 06ab184 commit f236d42

File tree

5 files changed

+2
-111
lines changed

5 files changed

+2
-111
lines changed

config/default.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,6 @@ module.exports = {
4444
idleTimeout: parseInt(process.env.IDLETIMEOUT, 10) || 3600,
4545
timeout: parseInt(process.env.TIMEOUT, 10) || 30000
4646
},
47-
48-
V4_ES: {
49-
// above AWS_REGION is used if we use AWS ES
50-
AWS_REGION: process.env.AWS_REGION || 'ap-northeast-1',
51-
HOST: process.env.V4_ES_HOST,
52-
API_VERSION: process.env.V4_ES_API_VERSION || '6.8',
53-
CHALLENGE_ES_INDEX: process.env.CHALLENGE_ES_INDEX || 'challengeslisting', // challenge es index
54-
CHALLENGE_ES_TYPE: process.env.CHALLENGE_ES_TYPE || 'challenges', // challenge es type
55-
ES_REFRESH: process.env.ES_REFRESH || 'true'
56-
},
57-
5847
// Topcoder APIs
5948
V5_CHALLENGE_API_URL: process.env.V5_CHALLENGE_API_URL || 'http://localhost:4000/v5/challenges',
6049
V5_CHALLENGE_TYPE_API_URL: process.env.V5_CHALLENGE_TYPE_API_URL || 'http://localhost:4000/v5/challenge-types',

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,10 @@
2525
"@topcoder-platform/topcoder-bus-api-wrapper": "^1.2.0",
2626
"@topcoder-platform/topcoder-healthcheck-dropin": "^1.1.0",
2727
"async-mutex": "^0.2.4",
28-
"aws-sdk": "^2.729.0",
2928
"bluebird": "^3.7.2",
3029
"config": "^3.3.1",
31-
"elasticsearch": "^16.7.1",
3230
"get-parameter-names": "^0.3.0",
3331
"gulp": "^4.0.2",
34-
"http-aws-es": "^6.0.0",
3532
"http-json-response": "^1.0.1",
3633
"ifxnjs": "^10.0.5",
3734
"lodash": "^4.17.19",

src/common/helper.js

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22
* Contains generic helper methods
33
*/
44

5-
const elasticsearch = require('elasticsearch')
6-
const AWS = require('aws-sdk')
75
const _ = require('lodash')
86
const config = require('config')
97
const ifxnjs = require('ifxnjs')
10-
const logger = require('./logger')
118
const request = require('superagent')
129
const m2mAuth = require('tc-core-library-js').auth.m2m
1310
const busApi = require('@topcoder-platform/topcoder-bus-api-wrapper')
@@ -18,53 +15,9 @@ const Pool = ifxnjs.Pool
1815
const pool = Promise.promisifyAll(new Pool())
1916
pool.setMaxPoolSize(config.get('INFORMIX.POOL_MAX_SIZE'))
2017

21-
AWS.config.region = config.get('V4_ES.AWS_REGION')
22-
// ES Client
23-
let esClient
24-
2518
// Bus API Client
2619
let busApiClient
2720

28-
/**
29-
* Get ES Client
30-
* @return {Object} Elastic Host Client Instance
31-
*/
32-
function getESClient () {
33-
logger.debug('getES Client Called')
34-
const esHost = config.get('V4_ES.HOST')
35-
if (esClient) {
36-
// logger.debug(`Cached ES Client: ${JSON.stringify(esClient)}`)
37-
return esClient
38-
} else {
39-
// logger.debug(`No ES Client, building.... ${esClient}`)
40-
}
41-
42-
try {
43-
// AWS ES configuration is different from other providers
44-
logger.debug('getES Client in try')
45-
if (/.*amazonaws.*/.test(esHost)) {
46-
esClient = elasticsearch.Client({
47-
apiVersion: config.get('V4_ES.API_VERSION'),
48-
hosts: esHost,
49-
connectionClass: require('http-aws-es'), // eslint-disable-line global-require
50-
amazonES: {
51-
region: config.get('V4_ES.AWS_REGION'),
52-
credentials: new AWS.EnvironmentCredentials('AWS')
53-
}
54-
})
55-
} else {
56-
esClient = new elasticsearch.Client({
57-
apiVersion: config.get('V4_ES.API_VERSION'),
58-
hosts: esHost
59-
})
60-
}
61-
// logger.debug(`ES Client: ${JSON.stringify(esClient)}`)
62-
} catch (e) {
63-
logger.error(`Get ES Client Error ${e}`)
64-
}
65-
return esClient
66-
}
67-
6821
/**
6922
* Get Informix connection using the configured parameters
7023
* @return {Object} Informix connection
@@ -205,6 +158,5 @@ module.exports = {
205158
getRequest,
206159
putRequest,
207160
postRequest,
208-
postBusEvent,
209-
getESClient
161+
postBusEvent
210162
}

src/services/ProcessorService.js

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -389,50 +389,8 @@ async function processUpdate (message) {
389389
return
390390
}
391391

392-
// let challengeV4FromEs
393-
// let esClient
394-
// const esQuery = {
395-
// index: config.get('V4_ES.CHALLENGE_ES_INDEX'),
396-
// type: config.get('V4_ES.CHALLENGE_ES_TYPE'),
397-
// size: 1,
398-
// from: 0,
399-
// body: {
400-
// _source: ['groupIds'],
401-
// query: {
402-
// match_phrase: {
403-
// _id: message.payload.legacyId
404-
// }
405-
// }
406-
// }
407-
// }
408-
409392
const v4GroupIds = await groupService.getGroupsForChallenge(message.payload.legacyId)
410393
logger.info(`GroupIDs Found in Informix: ${JSON.stringify(v4GroupIds)}`)
411-
// try {
412-
// // Search with constructed query
413-
// // logger.debug(`Looking Up Challenge in V4 - index: ${config.get('V4_ES.CHALLENGE_ES_INDEX')} type: ${config.get('V4_ES.CHALLENGE_ES_TYPE')} - Query: ${JSON.stringify(esQuery)}`)
414-
// esClient = helper.getESClient()
415-
// const docs = await esClient.search(esQuery)
416-
// logger.debug(`Docs: ${JSON.stringify(docs)}`)
417-
// // Extract data from hits
418-
// if (docs.hits.total === 0) {
419-
// throw new Error('Challenge does not exist yet on ES')
420-
// }
421-
// challengeV4FromEs = _.map(docs.hits.hits, item => item._source)[0]
422-
// if (!challengeV4FromEs) {
423-
// throw new Error(`Could not find challenge ${message.payload.legacyId} on ES`)
424-
// }
425-
// } catch (e) {
426-
// // postpone kafka event
427-
// logger.info(`Challenge does not exist yet on ES. Will post the same message back to the bus API, ${e}`)
428-
// await new Promise((resolve) => {
429-
// setTimeout(async () => {
430-
// await helper.postBusEvent(config.UPDATE_CHALLENGE_TOPIC, message.payload)
431-
// resolve()
432-
// }, config.RETRY_TIMEOUT)
433-
// })
434-
// return
435-
// }
436394

437395
const saveDraftContestDTO = await parsePayload(message.payload, m2mToken, false, v4GroupIds)
438396
logger.debug('Parsed Payload', saveDraftContestDTO)

src/services/groupsService.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,7 @@ async function getChallengeEligibilityId (connection, challengeLegacyId) {
120120
logger.info(`getChallengeEligibilityId Query: ${util.format(QUERY_GET_ELIGIBILITY_ID, challengeLegacyId)}`)
121121
const result = await connection.queryAsync(util.format(QUERY_GET_ELIGIBILITY_ID, challengeLegacyId))
122122
logger.info(`getChallengeEligibilityId Result: ${JSON.stringify(result)}`)
123-
// if (result.length === 0) {
124-
// logger.debug(`getChallengeEligibility not found, creating ${challengeLegacyId}`)
125-
// await createChallengeEligibilityRecord(connection, challengeLegacyId)
126-
// result = await connection.queryAsync(util.format(QUERY_GET_ELIGIBILITY_ID, challengeLegacyId))
127-
// }
128-
return result[0].contest_eligibility_id || false
123+
return (result && result[0]) ? result[0].contest_eligibility_id : false
129124
}
130125

131126
/**

0 commit comments

Comments
 (0)