Skip to content

Commit

Permalink
use addon id instead of name (#122)
Browse files Browse the repository at this point in the history
* use addon id instead of name

if we use the name, `heroku addons:rename` breaks the addon lookup until the
control plane has updated it's cached information.

This requires work on the Heroku Kafka backend as well, but this is a
start.

* Wait using id
  • Loading branch information
tcrayford committed Jan 3, 2017
1 parent fdb942c commit ffee030
Show file tree
Hide file tree
Showing 30 changed files with 73 additions and 73 deletions.
2 changes: 1 addition & 1 deletion commands/credentials_rotate.js
Expand Up @@ -11,7 +11,7 @@ function * credentialsRotate (context, heroku) {
yield withCluster(heroku, context.app, context.args.CLUSTER, function * (addon) {
let response = yield request(heroku, {
method: 'POST',
path: `/client/kafka/${VERSION}/clusters/${addon.name}/rotate-credentials`
path: `/client/kafka/${VERSION}/clusters/${addon.id}/rotate-credentials`
})

cli.log(response.message)
Expand Down
2 changes: 1 addition & 1 deletion commands/fail.js
Expand Up @@ -19,7 +19,7 @@ function * fail (context, heroku) {
catastrophic: context.flags.catastrophic,
zookeeper: context.flags.zookeeper
},
path: `/client/kafka/${VERSION}/clusters/${addon.name}/induce-failure`
path: `/client/kafka/${VERSION}/clusters/${addon.id}/induce-failure`
})
}))

Expand Down
2 changes: 1 addition & 1 deletion commands/info.js
Expand Up @@ -102,7 +102,7 @@ function * run (context, heroku) {
cluster: heroku.request({
host: host(addon),
method: 'get',
path: `/data/kafka/v0/clusters/${addon.name}`
path: `/data/kafka/v0/clusters/${addon.id}`
}).catch(err => {
if (err.statusCode !== 404) throw err
cli.warn(`${cli.color.addon(addon.name)} is not yet provisioned.\nRun ${cli.color.cmd('heroku kafka:wait')} to wait until the cluster is provisioned.`)
Expand Down
2 changes: 1 addition & 1 deletion commands/jmx.js
Expand Up @@ -26,7 +26,7 @@ function * jmx (context, heroku) {
body: {
enabled: enabled
},
path: `/client/kafka/${VERSION}/clusters/${addon.name}/jmx`
path: `/client/kafka/${VERSION}/clusters/${addon.id}/jmx`
})
}))
})
Expand Down
2 changes: 1 addition & 1 deletion commands/topics.js
Expand Up @@ -12,7 +12,7 @@ const VERSION = 'v0'
function * listTopics (context, heroku) {
yield withCluster(heroku, context.app, context.args.CLUSTER, function * (addon) {
let topics = yield request(heroku, {
path: `/data/kafka/${VERSION}/clusters/${addon.name}/topics`
path: `/data/kafka/${VERSION}/clusters/${addon.id}/topics`
})
cli.styledHeader('Kafka Topics on ' + (topics.attachment_name || 'HEROKU_KAFKA'))
let filtered = topics.topics.filter((t) => t.name !== '__consumer_offsets')
Expand Down
2 changes: 1 addition & 1 deletion commands/topics_compaction.js
Expand Up @@ -29,7 +29,7 @@ function * compaction (context, heroku) {
compaction: enabled
}
},
path: `/data/kafka/${VERSION}/clusters/${addon.name}/topics/${topicName}`
path: `/data/kafka/${VERSION}/clusters/${addon.id}/topics/${topicName}`
})
}))
cli.log(`Use \`heroku kafka:topics:info ${context.args.TOPIC}\` to monitor your topic.`)
Expand Down
2 changes: 1 addition & 1 deletion commands/topics_create.js
Expand Up @@ -48,7 +48,7 @@ function * createTopic (context, heroku) {
compaction: flags['compaction'] || false
}
},
path: `/data/kafka/${VERSION}/clusters/${addon.name}/topics`
path: `/data/kafka/${VERSION}/clusters/${addon.id}/topics`
})
}))

Expand Down
2 changes: 1 addition & 1 deletion commands/topics_destroy.js
Expand Up @@ -20,7 +20,7 @@ function * destroyTopic (context, heroku) {
body: {
topic_name: topicName
},
path: `/data/kafka/${VERSION}/clusters/${addon.name}/topics/${topicName}`
path: `/data/kafka/${VERSION}/clusters/${addon.id}/topics/${topicName}`
})
}))

Expand Down
2 changes: 1 addition & 1 deletion commands/topics_info.js
Expand Up @@ -66,7 +66,7 @@ function * kafkaTopic (context, heroku) {
const topic = context.args.TOPIC

let info = yield request(heroku, {
path: `/data/kafka/${VERSION}/clusters/${addon.name}/topics`
path: `/data/kafka/${VERSION}/clusters/${addon.id}/topics`
})

let forTopic = info.topics.filter((t) => t.name === topic)
Expand Down
2 changes: 1 addition & 1 deletion commands/topics_replication_factor.js
Expand Up @@ -23,7 +23,7 @@ function * replicationFactor (context, heroku) {
replication_factor: context.args.VALUE
}
},
path: `/data/kafka/${VERSION}/clusters/${addon.name}/topics/${topicName}`
path: `/data/kafka/${VERSION}/clusters/${addon.id}/topics/${topicName}`
})
}))
cli.log(`Use \`heroku kafka:topics:info ${context.args.TOPIC}\` to monitor your topic.`)
Expand Down
2 changes: 1 addition & 1 deletion commands/topics_retention_time.js
Expand Up @@ -29,7 +29,7 @@ function * retentionTime (context, heroku) {
retention_time_ms: parsed
}
},
path: `/data/kafka/${VERSION}/clusters/${addon.name}/topics/${topicName}`
path: `/data/kafka/${VERSION}/clusters/${addon.id}/topics/${topicName}`
})
}))

Expand Down
2 changes: 1 addition & 1 deletion commands/upgrade.js
Expand Up @@ -25,7 +25,7 @@ function * upgradeCluster (context, heroku) {
body: {
version: context.flags.version
},
path: `/client/kafka/${VERSION}/clusters/${addon.name}/upgrade`
path: `/client/kafka/${VERSION}/clusters/${addon.id}/upgrade`
})

cli.action.done('started.\n\n')
Expand Down
2 changes: 1 addition & 1 deletion commands/zookeeper.js
Expand Up @@ -31,7 +31,7 @@ function * zookeeper (context, heroku) {
body: {
enabled: enabled
},
path: `/client/kafka/${VERSION}/clusters/${addon.name}/zookeeper`
path: `/client/kafka/${VERSION}/clusters/${addon.id}/zookeeper`
})
}))
})
Expand Down
2 changes: 1 addition & 1 deletion lib/clusters.js
Expand Up @@ -24,7 +24,7 @@ HerokuKafkaClusters.prototype.waitStatus = function * (addon) {
return null
}
var response = yield this.request({
path: `/client/kafka/${VERSION}/clusters/${addon.name}/wait_status`
path: `/client/kafka/${VERSION}/clusters/${addon.id}/wait_status`
}).catch(function (err) {
if (err.statusCode === 410) {
return Object.assign({ 'deprovisioned?': true }, errorResponse)
Expand Down
4 changes: 2 additions & 2 deletions test/commands/credentials_rotate_test.js
Expand Up @@ -13,7 +13,7 @@ const nock = require('nock')

let planName
const withCluster = function * (heroku, app, cluster, callback) {
yield callback({ name: 'kafka-1', plan: { name: planName } })
yield callback({ name: 'kafka-1', id: '00000000-0000-0000-0000-000000000000', plan: { name: planName } })
}

const cmd = proxyquire('../../commands/credentials_rotate', {
Expand Down Expand Up @@ -42,7 +42,7 @@ describe('kafka:credentials', () => {
})

it(`rotates credentials`, () => {
kafka.post(credentialsUrl('kafka-1')).reply(200, {message: 'Rotated'})
kafka.post(credentialsUrl('00000000-0000-0000-0000-000000000000')).reply(200, {message: 'Rotated'})

return cmd.run({app: 'myapp', args: {CLUSTER: undefined}, flags: { reset: true }})
.then(() => expect(cli.stderr).to.be.empty)
Expand Down
10 changes: 5 additions & 5 deletions test/commands/fail_test.js
Expand Up @@ -12,7 +12,7 @@ const nock = require('nock')
const cli = require('heroku-cli-util')

const withCluster = function * (heroku, app, cluster, callback) {
yield callback({ name: 'kafka-1' })
yield callback({ name: 'kafka-1', id: '00000000-0000-0000-0000-000000000000' })
}

let lastApp
Expand Down Expand Up @@ -56,7 +56,7 @@ describe('kafka:fail', () => {
const cluster = 'kafka-1'
const message = `This command will affect the cluster: ${cluster}, which is on ${app}\n\nThis command will forcibly terminate nodes in your cluster at random.\nYou should only run this command in controlled testing scenarios.`

kafka.post(failUrl('kafka-1')).reply(200, { message: 'Triggered failure on node 1.2.3.4' })
kafka.post(failUrl('00000000-0000-0000-0000-000000000000')).reply(200, { message: 'Triggered failure on node 1.2.3.4' })

return cmd.run({app: 'myapp', args: {}, flags: {confirm: 'myapp'}})
.then(() => {
Expand All @@ -67,7 +67,7 @@ describe('kafka:fail', () => {
})

it('triggers failure', () => {
kafka.post(failUrl('kafka-1', {confirm: 'myapp',
kafka.post(failUrl('00000000-0000-0000-0000-000000000000', {confirm: 'myapp',
catastrophic: false,
zookeeper: false}))
.reply(200, { message: 'Triggered failure on node 1.2.3.4' })
Expand All @@ -82,7 +82,7 @@ describe('kafka:fail', () => {
})

it('passes the --catastrophic flag', () => {
kafka.post(failUrl('kafka-1', {confirm: 'myapp',
kafka.post(failUrl('00000000-0000-0000-0000-000000000000', {confirm: 'myapp',
catastrophic: true,
zookeeper: false}))
.reply(200, { message: 'Triggered failure on node 1.2.3.4' })
Expand All @@ -97,7 +97,7 @@ describe('kafka:fail', () => {
})

it('passes the --zookeeper flag', () => {
kafka.post(failUrl('kafka-1', {confirm: 'myapp',
kafka.post(failUrl('00000000-0000-0000-0000-000000000000', {confirm: 'myapp',
catastrophic: false,
zookeeper: true}))
.reply(200, { message: 'Triggered failure on node 1.2.3.4' })
Expand Down
24 changes: 12 additions & 12 deletions test/commands/info_test.js
Expand Up @@ -13,8 +13,8 @@ const nock = require('nock')

let addon
let all = [
{name: 'kafka-1', plan: {name: 'heroku-kafka:beta-3'}},
{name: 'kafka-2', plan: {name: 'heroku-kafka:beta-3'}}
{name: 'kafka-1', id: '00000000-0000-0000-0000-000000000000', plan: {name: 'heroku-kafka:beta-3'}},
{name: 'kafka-2', id: '00000000-0000-0000-0000-000000000001', plan: {name: 'heroku-kafka:beta-3'}}
]

const fetcher = () => {
Expand Down Expand Up @@ -60,14 +60,14 @@ describe('kafka:info', () => {
describe('with 2 dbs', () => {
let plan = {name: 'heroku-kafka:beta-3'}
let attachments = [
{ addon: { name: 'kafka-1' }, name: 'KAFKA' },
{ addon: { name: 'kafka-1' }, name: 'HEROKU_KAFKA_COBALT' },
{ addon: { name: 'kafka-2' }, name: 'HEROKU_KAFKA_PURPLE' }
{ addon: { name: 'kafka-1', id: '00000000-0000-0000-0000-000000000000' }, name: 'KAFKA' },
{ addon: { name: 'kafka-1', id: '00000000-0000-0000-0000-000000000000' }, name: 'HEROKU_KAFKA_COBALT' },
{ addon: { name: 'kafka-2', id: '00000000-0000-0000-0000-000000000001' }, name: 'HEROKU_KAFKA_PURPLE' }
]
let addonService = {name: 'heroku-kafka'}
let addons = [
{id: 1, name: 'kafka-1', addon_service: addonService, plan},
{id: 2, name: 'kafka-2', addon_service: addonService, plan}
{name: 'kafka-1', id: '00000000-0000-0000-0000-000000000000', addon_service: addonService, plan},
{name: 'kafka-2', id: '00000000-0000-0000-0000-000000000001', addon_service: addonService, plan}
]
let clusterA = {
addon: { name: 'kafka-1' },
Expand Down Expand Up @@ -97,8 +97,8 @@ describe('kafka:info', () => {

api.get('/apps/myapp/addon-attachments').reply(200, attachments)
kafka
.get(infoUrl('kafka-1')).reply(200, clusterA)
.get(infoUrl('kafka-2')).reply(200, clusterB)
.get(infoUrl('00000000-0000-0000-0000-000000000000')).reply(200, clusterA)
.get(infoUrl('00000000-0000-0000-0000-000000000001')).reply(200, clusterB)

return cmd.run({app: 'myapp', args: {}})
.then(() => expect(cli.stderr).to.be.empty)
Expand Down Expand Up @@ -130,7 +130,7 @@ Add-on: kafka-2
api.get('/apps/myapp/addon-attachments').reply(200, attachments)

kafka
.get(infoUrl('kafka-2'))
.get(infoUrl('00000000-0000-0000-0000-000000000001'))
.reply(200, clusterB)

return cmd.run({app: 'myapp', args: {CLUSTER: 'kafka-2'}})
Expand All @@ -153,8 +153,8 @@ Add-on: kafka-2

api.get('/apps/myapp/addon-attachments').reply(200, attachments)
kafka
.get(infoUrl('kafka-1')).reply(404)
.get(infoUrl('kafka-2')).reply(200, clusterB)
.get(infoUrl('00000000-0000-0000-0000-000000000000')).reply(404)
.get(infoUrl('00000000-0000-0000-0000-000000000001')).reply(200, clusterB)

return cmd.run({app: 'myapp', args: {}})
.then(() => expect(cli.stdout).to.equal(`=== HEROKU_KAFKA_PURPLE_URL
Expand Down
6 changes: 3 additions & 3 deletions test/commands/jmx_test.js
Expand Up @@ -13,7 +13,7 @@ const cli = require('heroku-cli-util')
const nock = require('nock')

const withCluster = function * (heroku, app, cluster, callback) {
yield callback({ name: 'kafka-1' })
yield callback({ name: 'kafka-1', id: '00000000-0000-0000-0000-000000000000' })
}

const cmd = proxyquire('../../commands/jmx', {
Expand Down Expand Up @@ -53,7 +53,7 @@ describe('kafka:jmx', () => {
const validEnable = [ 'enable', 'on' ]
validEnable.forEach((value) => {
it(`turns JMX on with argument ${value}`, () => {
kafka.post(configUrl('kafka-1'), { enabled: true }).reply(200)
kafka.post(configUrl('00000000-0000-0000-0000-000000000000'), { enabled: true }).reply(200)

return cmd.run({app: 'myapp', args: { VALUE: value }})
.then(() => expect(cli.stderr).to.equal('Enabling JMX access... done\n'))
Expand All @@ -64,7 +64,7 @@ describe('kafka:jmx', () => {
const validDisable = [ 'disable', 'off' ]
validDisable.forEach((value) => {
it(`turns JMX off with argument ${value}`, () => {
kafka.post(configUrl('kafka-1'), { enabled: false }).reply(200)
kafka.post(configUrl('00000000-0000-0000-0000-000000000000'), { enabled: false }).reply(200)

return cmd.run({app: 'myapp', args: { VALUE: value }})
.then(() => expect(cli.stderr).to.equal('Disabling JMX access... done\n'))
Expand Down
6 changes: 3 additions & 3 deletions test/commands/topics_compaction_test.js
Expand Up @@ -13,7 +13,7 @@ const cli = require('heroku-cli-util')
const nock = require('nock')

const withCluster = function * (heroku, app, cluster, callback) {
yield callback({ name: 'kafka-1' })
yield callback({ name: 'kafka-1', id: '00000000-0000-0000-0000-000000000000' })
}

const cmd = proxyquire('../../commands/topics_compaction', {
Expand Down Expand Up @@ -54,7 +54,7 @@ describe('kafka:topics:compaction', () => {
const validEnable = [ 'enable', 'on' ]
validEnable.forEach((value) => {
it(`turns compaction on with argument ${value}`, () => {
kafka.put(topicConfigUrl('kafka-1', 'topic-1'),
kafka.put(topicConfigUrl('00000000-0000-0000-0000-000000000000', 'topic-1'),
{ topic: { name: 'topic-1', compaction: true } }).reply(200)

return cmd.run({app: 'myapp', args: { TOPIC: 'topic-1', VALUE: value }})
Expand All @@ -66,7 +66,7 @@ describe('kafka:topics:compaction', () => {
const validDisable = [ 'disable', 'off' ]
validDisable.forEach((value) => {
it(`turns compaction off with argument ${value}`, () => {
kafka.put(topicConfigUrl('kafka-1', 'topic-1'),
kafka.put(topicConfigUrl('00000000-0000-0000-0000-000000000000', 'topic-1'),
{ topic: { name: 'topic-1', compaction: false } }).reply(200)

return cmd.run({app: 'myapp', args: { TOPIC: 'topic-1', VALUE: value }})
Expand Down
10 changes: 5 additions & 5 deletions test/commands/topics_create_test.js
Expand Up @@ -13,7 +13,7 @@ const cli = require('heroku-cli-util')
const nock = require('nock')

const withCluster = function * (heroku, app, cluster, callback) {
yield callback({ name: 'kafka-1' })
yield callback({ name: 'kafka-1', id: '00000000-0000-0000-0000-000000000000' })
}

let lastApp
Expand Down Expand Up @@ -66,7 +66,7 @@ describe('kafka:topics:create', () => {
it('requires app confirmation and warns if replication factor of 1 specified', () => {
const message = `This command will create a topic with no replication on the cluster: kafka-1, which is on myapp.\nData written to this topic will be lost if any single broker suffers catastrophic failure.`

kafka.post(createUrl('kafka-1')).reply(200, { message: 'success' })
kafka.post(createUrl('00000000-0000-0000-0000-000000000000')).reply(200, { message: 'success' })

lastApp = null
lastConfirm = null
Expand All @@ -86,7 +86,7 @@ describe('kafka:topics:create', () => {
})

it('does not require app confirmation with higher replication factor', () => {
kafka.post(createUrl('kafka-1')).reply(200)
kafka.post(createUrl('00000000-0000-0000-0000-000000000000')).reply(200)

lastApp = null
lastConfirm = null
Expand All @@ -103,7 +103,7 @@ describe('kafka:topics:create', () => {
})

it('passes the topic name and specified flags', () => {
kafka.post(createUrl('kafka-1'),
kafka.post(createUrl('00000000-0000-0000-0000-000000000000'),
{
topic: {
name: 'topic-1',
Expand All @@ -126,7 +126,7 @@ describe('kafka:topics:create', () => {
})

it('defaults to 32 partitions', () => {
kafka.post(createUrl('kafka-1'),
kafka.post(createUrl('00000000-0000-0000-0000-000000000000'),
{
topic: {
name: 'topic-1',
Expand Down
6 changes: 3 additions & 3 deletions test/commands/topics_destroy_test.js
Expand Up @@ -12,7 +12,7 @@ const cli = require('heroku-cli-util')
const nock = require('nock')

const withCluster = function * (heroku, app, cluster, callback) {
yield callback({ name: 'kafka-1' })
yield callback({ name: 'kafka-1', id: '00000000-0000-0000-0000-000000000000' })
}

let lastApp
Expand Down Expand Up @@ -57,7 +57,7 @@ describe('kafka:topics:destroy', () => {
it('requires app confirmation', () => {
const message = 'This command will affect the cluster: kafka-1, which is on myapp'

kafka.delete(deleteUrl('kafka-1', 'topic-1')).reply(200)
kafka.delete(deleteUrl('00000000-0000-0000-0000-000000000000', 'topic-1')).reply(200)

lastApp = null
lastConfirm = null
Expand All @@ -74,7 +74,7 @@ describe('kafka:topics:destroy', () => {
})

it('deletes the topic', () => {
kafka.delete(deleteUrl('kafka-1', 'topic-1'), { topic_name: 'topic-1' })
kafka.delete(deleteUrl('00000000-0000-0000-0000-000000000000', 'topic-1'), { topic_name: 'topic-1' })
.reply(200)

return cmd.run({app: 'myapp',
Expand Down
4 changes: 2 additions & 2 deletions test/commands/topics_info_test.js
Expand Up @@ -12,7 +12,7 @@ const cli = require('heroku-cli-util')
const nock = require('nock')

const withCluster = function * (heroku, app, cluster, callback) {
yield callback({ name: 'kafka-1' })
yield callback({ name: 'kafka-1', id: '00000000-0000-0000-0000-000000000000' })
}

const cmd = proxyquire('../../commands/topics_info', {
Expand Down Expand Up @@ -40,7 +40,7 @@ describe('kafka:topics:info', () => {
})

it('displays the topic info', () => {
kafka.get(topicsUrl('kafka-1')).reply(200, {
kafka.get(topicsUrl('00000000-0000-0000-0000-000000000000')).reply(200, {
attachment_name: 'HEROKU_KAFKA_BLUE_URL',
topics: [
{
Expand Down

0 comments on commit ffee030

Please sign in to comment.