本文整理汇总了Python中otter.util.cqlbatch.Batch.execute方法的典型用法代码示例。如果您正苦于以下问题:Python Batch.execute方法的具体用法?Python Batch.execute怎么用?Python Batch.execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类otter.util.cqlbatch.Batch
的用法示例。
在下文中一共展示了Batch.execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_scaling_group
# 需要导入模块: from otter.util.cqlbatch import Batch [as 别名]
# 或者: from otter.util.cqlbatch.Batch import execute [as 别名]
def create_scaling_group(self, log, tenant_id, config, launch, policies=None):
"""
see :meth:`otter.models.interface.IScalingGroupCollection.create_scaling_group`
"""
scaling_group_id = generate_key_str('scalinggroup')
log.bind(tenant_id=tenant_id, scaling_group_id=scaling_group_id).msg("Creating scaling group")
queries = [
_cql_insert.format(cf=self.config_table, name=":scaling"),
_cql_insert.format(cf=self.launch_table, name=":launch"),
_cql_create_group_state.format(cf=self.state_table)]
data = {"tenantId": tenant_id,
"groupId": scaling_group_id,
"scaling": serialize_json_data(config, 1),
"launch": serialize_json_data(launch, 1),
}
outpolicies = {}
_build_policies(policies, self.policies_table, self.event_table, queries, data,
outpolicies)
b = Batch(queries, data,
consistency=get_consistency_level('create', 'group'))
d = b.execute(self.connection)
d.addCallback(lambda _: {
'groupConfiguration': config,
'launchConfiguration': launch,
'scalingPolicies': outpolicies,
'id': scaling_group_id
})
return d
示例2: create_scaling_group
# 需要导入模块: from otter.util.cqlbatch import Batch [as 别名]
# 或者: from otter.util.cqlbatch.Batch import execute [as 别名]
def create_scaling_group(self, log, tenant_id, config, launch, policies=None):
"""
see :meth:`otter.models.interface.IScalingGroupCollection.create_scaling_group`
"""
scaling_group_id = generate_key_str('scalinggroup')
log.bind(tenant_id=tenant_id, scaling_group_id=scaling_group_id).msg("Creating scaling group")
queries = [_cql_create_group.format(cf=self.group_table)]
data = {"tenantId": tenant_id,
"groupId": scaling_group_id,
"group_config": serialize_json_data(config, 1),
"launch_config": serialize_json_data(launch, 1),
"active": '{}',
"pending": '{}',
"policyTouched": '{}',
"paused": False,
"created_at": datetime.utcnow()
}
outpolicies = {}
_build_policies(policies, self.policies_table, self.event_table, queries, data,
outpolicies)
b = Batch(queries, data,
consistency=get_consistency_level('create', 'group'))
d = b.execute(self.connection)
d.addCallback(lambda _: {
'groupConfiguration': config,
'launchConfiguration': launch,
'scalingPolicies': outpolicies,
'id': scaling_group_id
})
return d
示例3: _do_update
# 需要导入模块: from otter.util.cqlbatch import Batch [as 别名]
# 或者: from otter.util.cqlbatch.Batch import execute [as 别名]
def _do_update(_):
queries, data = list(), dict()
for i, event in enumerate(update_events):
polname = 'policy{}'.format(i)
queries.append(_cql_insert_event_batch.format(cf=self.event_table, name=':' + polname))
data.update({polname + key: event[key] for key in event})
b = Batch(queries, data, get_consistency_level('insert', 'event'))
return b.execute(self.connection)
示例4: _do_update_config
# 需要导入模块: from otter.util.cqlbatch import Batch [as 别名]
# 或者: from otter.util.cqlbatch.Batch import execute [as 别名]
def _do_update_config(lastRev):
queries = [_cql_update.format(cf=self.config_table, name=":scaling")]
b = Batch(queries, {"tenantId": self.tenant_id,
"groupId": self.uuid,
"scaling": serialize_json_data(data, 1)},
consistency=get_consistency_level('update', 'partial'))
return b.execute(self.connection)
示例5: _do_update_policy
# 需要导入模块: from otter.util.cqlbatch import Batch [as 别名]
# 或者: from otter.util.cqlbatch.Batch import execute [as 别名]
def _do_update_policy(_):
queries = [_cql_update_policy.format(cf=self.policies_table, name=":policy")]
b = Batch(queries, {"tenantId": self.tenant_id,
"groupId": self.uuid,
"policyId": policy_id,
"policy": serialize_json_data(data, 1)},
consistency=get_consistency_level('update', 'policy'))
return b.execute(self.connection)
示例6: _do_update_launch
# 需要导入模块: from otter.util.cqlbatch import Batch [as 别名]
# 或者: from otter.util.cqlbatch.Batch import execute [as 别名]
def _do_update_launch(lastRev):
queries = [_cql_update.format(cf=self.group_table, column='launch_config',
name=":launch")]
b = Batch(queries, {"tenantId": self.tenant_id,
"groupId": self.uuid,
"launch": serialize_json_data(data, 1)},
consistency=get_consistency_level('update', 'partial'))
d = b.execute(self.connection)
return d
示例7: _do_delete
# 需要导入模块: from otter.util.cqlbatch import Batch [as 别名]
# 或者: from otter.util.cqlbatch.Batch import execute [as 别名]
def _do_delete(_):
queries = [
_cql_delete_all_in_policy.format(cf=self.policies_table),
_cql_delete_all_in_policy.format(cf=self.webhooks_table),
_cql_delete_policy_events.format(cf=self.event_table)]
b = Batch(queries, {"tenantId": self.tenant_id,
"groupId": self.uuid,
"policyId": policy_id},
consistency=get_consistency_level('delete', 'policy'))
return b.execute(self.connection)
示例8: test_batch
# 需要导入模块: from otter.util.cqlbatch import Batch [as 别名]
# 或者: from otter.util.cqlbatch.Batch import execute [as 别名]
def test_batch(self):
"""
Test a simple batch
"""
batch = Batch(['INSERT * INTO BLAH', 'INSERT * INTO BLOO'], {})
d = batch.execute(self.connection)
self.successResultOf(d)
expected = 'BEGIN BATCH INSERT * INTO BLAH'
expected += ' INSERT * INTO BLOO APPLY BATCH;'
self.connection.execute.assert_called_once_with(expected, {},
ConsistencyLevel.ONE)
示例9: test_batch_ts
# 需要导入模块: from otter.util.cqlbatch import Batch [as 别名]
# 或者: from otter.util.cqlbatch.Batch import execute [as 别名]
def test_batch_ts(self):
"""
Test a simple batch with timestamp set
"""
batch = Batch(['INSERT * INTO BLAH'], {}, timestamp=123)
d = batch.execute(self.connection)
self.successResultOf(d)
expected = 'BEGIN BATCH USING TIMESTAMP 123'
expected += ' INSERT * INTO BLAH APPLY BATCH;'
self.connection.execute.assert_called_once_with(expected, {},
ConsistencyLevel.ONE)
示例10: _do_create_pol
# 需要导入模块: from otter.util.cqlbatch import Batch [as 别名]
# 或者: from otter.util.cqlbatch.Batch import execute [as 别名]
def _do_create_pol(lastRev):
queries = []
cqldata = {"tenantId": self.tenant_id,
"groupId": self.uuid}
outpolicies = _build_policies(data, self.policies_table,
self.event_table, queries, cqldata)
b = Batch(queries, cqldata,
consistency=get_consistency_level('create', 'policy'))
d = b.execute(self.connection)
return d.addCallback(lambda _: outpolicies)
示例11: test_batch_consistency
# 需要导入模块: from otter.util.cqlbatch import Batch [as 别名]
# 或者: from otter.util.cqlbatch.Batch import execute [as 别名]
def test_batch_consistency(self):
"""
Test a simple batch with consistency set
"""
batch = Batch(['INSERT * INTO BLAH'], {},
consistency=ConsistencyLevel.QUORUM)
d = batch.execute(self.connection)
self.successResultOf(d)
expected = 'BEGIN BATCH'
expected += ' INSERT * INTO BLAH APPLY BATCH;'
self.connection.execute.assert_called_once_with(
expected, {}, ConsistencyLevel.QUORUM)
示例12: test_batch_param
# 需要导入模块: from otter.util.cqlbatch import Batch [as 别名]
# 或者: from otter.util.cqlbatch.Batch import execute [as 别名]
def test_batch_param(self):
"""
Test a simple batch with params
"""
params = {"blah": "ff"}
batch = Batch(['INSERT :blah INTO BLAH', 'INSERT * INTO BLOO'],
params)
d = batch.execute(self.connection)
self.successResultOf(d)
expected = 'BEGIN BATCH INSERT :blah INTO BLAH'
expected += ' INSERT * INTO BLOO APPLY BATCH;'
self.connection.execute.assert_called_once_with(expected, params,
ConsistencyLevel.ONE)
示例13: _do_create
# 需要导入模块: from otter.util.cqlbatch import Batch [as 别名]
# 或者: from otter.util.cqlbatch.Batch import execute [as 别名]
def _do_create(lastRev):
queries = []
cql_params = {"tenantId": self.tenant_id,
"groupId": self.uuid,
"policyId": policy_id}
output = _build_webhooks(data, self.webhooks_table, queries,
cql_params)
b = Batch(queries, cql_params,
consistency=get_consistency_level('create', 'webhook'))
d = b.execute(self.connection)
return d.addCallback(lambda _: output)
示例14: update_events_trigger
# 需要导入模块: from otter.util.cqlbatch import Batch [as 别名]
# 或者: from otter.util.cqlbatch.Batch import execute [as 别名]
def update_events_trigger(self, policy_and_triggers):
"""
see :meth:`otter.models.interface.IScalingScheduleCollection.update_events_trigger`
"""
queries = []
data = {}
for i, (policy_id, trigger) in enumerate(policy_and_triggers):
queries.append(_cql_update_event.format(cf=self.event_table,
trigger=':trigger{0}'.format(i),
policy_id=':policyid{0}'.format(i)))
data.update({'trigger{0}'.format(i): trigger,
'policyid{0}'.format(i): policy_id})
b = Batch(queries, data, get_consistency_level('update', 'events'))
return b.execute(self.connection)
示例15: _do_update_launch
# 需要导入模块: from otter.util.cqlbatch import Batch [as 别名]
# 或者: from otter.util.cqlbatch.Batch import execute [as 别名]
def _do_update_launch(lastRev):
if "type" in lastRev:
if lastRev["type"] != data["type"]:
raise ValidationError("Cannot change type of a scaling policy")
queries = [_cql_update_policy.format(cf=self.policies_table, name=":policy")]
b = Batch(queries, {"tenantId": self.tenant_id,
"groupId": self.uuid,
"policyId": policy_id,
"policy": serialize_json_data(data, 1)},
consistency=get_consistency_level('update', 'policy'))
d = b.execute(self.connection)
return d