def UpdateSAToken(self, name=None, token=None): payload = { "token": "%s" % token, } if token: __RQE = self.url + "/api/v1/serviceaccount/" + name + '/revoke' self.updateSAToken = exec_request( __METHOD="put", __EXPECTED="json", __URL=__RQE, __HEADERS=self.admin_text_plain_headers, __DATA=payload ) else: __RQE = self.url + "/api/v1/serviceaccount/" + name + '/revoke' self.updateSAToken = exec_request( __METHOD="put", __EXPECTED="json", __URL=__RQE, __HEADERS=self.admin_text_plain_headers, __DATA='{}', __DT='data' ) return self.updateSAToken
def CreateTopic(self, topicName, replication, partitions, config): """ Example of request { "topicName": "topicA", "replication": 1, "partitions": 1, "configs": { "cleanup.policy": "compact", "compression.type": "snappy" } } :param topicName:Name of topic :param replication: :param partitions: :param config: is dict ,for example { "cleanup.policy": "compact", "compression.type": "snappy" } """ params = dict(topicName=topicName, replication=int(replication), partitions=int(partitions), configs=config) self.createTopic = exec_request(__METHOD="post", __EXPECTED="text", __URL=self.manage_topic_endpoint, __HEADERS=self.topic_headers, __DATA=params) return self.createTopic
def SetConnectorConfig(self, cluster, connector, config): """ :param cluster: :param connector: :param config: For example { 'connector.class': 'org.apache.kafka.connect.file.FileStreamSinkConnector', 'task.max': 5, 'topics': 'nyc_yellow_taxi_trip_data,reddit_posts,sea_vessel_position_reports, telecom_italia_data', 'file': '/dev/null', 'tasks.max': '4', 'name': 'nullsink' } """ __RQE = self.lenses_connect_endpoint __RQE = __RQE + '/' + cluster + '/connectors/' __RQE = __RQE + connector + '/config' self.setConnectorConfig = exec_request( __METHOD="put", __EXPECTED="json", __URL=__RQE, __HEADERS=self.connector_headers, __DATA=config ) return self.setConnectorConfig
def RegisterNewSchema(self, subject, schema_json): """ Parameters: - subject name (String) - subject's schema (Json) - Example: { 'schema': '{ "type":"record","name":"reddit_post_key",' '"namespace":"com.lensesio.social.reddit.post.key",' '"fields": [ { "name":"subreddit_id","type":"string" } ] }' } Returns: Json: {"id":subjectID} """ __RQE = self.schemas_end_point __RQE = __RQE + '/' + subject + '/versions' self.registerNewSchema = exec_request(__METHOD="post", __EXPECTED="json", __URL=__RQE, __HEADERS=self.registry_headers, __DATA=schema_json, __VERIFY=self.verify_cert) return self.registerNewSchema
def GetQuotas(self): self.getQuotas = exec_request(__METHOD="get", __EXPECTED="json", __URL=self.quotas_end_point, __HEADERS=self.quota_headers) return self.getQuotas
def ViewPolicy(self): self.viewPolicy = exec_request(__METHOD="get", __EXPECTED="json", __URL=self.lenses_policies_endpoint, __HEADERS=self.policy_headers) return self.viewPolicy
def CreateSA(self, name=None, owner=None, groups=None, token=None): if type(groups) is not list: groups = [groups] if name and groups and owner and not token: payload = { "name": "%s" % name, "groups": groups, "owner": "%s" % owner } elif name and groups and owner and token: payload = { "name": "%s" % name, "groups": groups, "owner": "%s" % owner, "token": "%s" % token } else: return "Missing parameters: name=, groups=, owner=, token=" __RQE = self.url + "/api/v1/serviceaccount" self.createSA = exec_request( __METHOD="post", __EXPECTED="json", __URL=__RQE, __HEADERS=self.admin_text_plain_headers, __DATA=payload ) return self.createSA
def UpdateSA(self, name=None, owner=None, groups=None): if type(groups) is not list: groups = [groups] if name and groups and owner: payload = { "name": "%s" % name, "groups": groups, "owner": "%s" % owner } elif name and groups and owner: payload = { "name": "%s" % name, "groups": groups, "owner": "%s" % owner, } else: return "Missing parameters: name=, groups=, owner=" __RQE = self.url + "/api/v1/serviceaccount/" + name self.updateSA = exec_request( __METHOD="put", __EXPECTED="text", __URL=__RQE, __HEADERS=self.admin_text_plain_headers, __DATA=payload ) return self.updateSA
def GetProcessors(self): self.getProcessors = exec_request(__METHOD="get", __EXPECTED="json", __URL=self.processor_end_point, __HEADERS=self.processor_headers) return self.getProcessors
def CreateProcessor(self, name, sql, runners, clusterName, namespace=None, pipeline=None): """ :param name: string :param sql:string, query :param runners:int :param clusterName:string :param namespace:string :param pipeline:string, applies for Kubernetes mode """ headers = { 'Content-Type': 'application/json', 'Accept': 'text/plain', 'x-kafka-lenses-token': self.token } params = dict(name=name, sql=sql, runners=runners, clusterName=clusterName) self.createProcessor = exec_request(__METHOD="post", __EXPECTED="text", __URL=self.processor_end_point, __HEADERS=headers, __DATA=params) return self.createProcessor
def GetAllTopics(self): self.allTopics = exec_request(__METHOD="get", __EXPECTED="json", __URL=self.topic_end_point, __HEADERS=self.topic_headers) return self.allTopics
def DelAcl(self, resourceType, resourceName, principal, permissionType, host, operation): """ :param resourceType: string, required :param resourceName: string, required :param principal: string, required :param permissionType: string, required (either Allow or Deny) :param host: string, required :param operation: string, required """ params = dict(resourceType=resourceType, resourceName=resourceName, principal=principal, permissionType=permissionType, host=host, operation=operation, selectedColumns=[]) self.setAcl = exec_request(__METHOD="delete", __EXPECTED="text", __URL=self.lenses_acl_endpoint, __HEADERS=self.acls_headers, __DATA=params, __VERIFY=self.verify_cert) return self.setAcl
def GetConfig(self): self.getConfig = exec_request(__METHOD="get", __EXPECTED="json", __URL=self.admin_config_info_endpoint, __HEADERS=self.admin_text_plain_headers, __VERIFY=self.verify_cert) return self.getConfig
def DefaultTopicConfigs(self): self.defaultTopicConfigs = exec_request( __METHOD="get", __EXPECTED="json", __URL=self.topic_config_end_point, __HEADERS=self.topic_headers) return self.defaultTopicConfigs
def TopicInfo(self, topicname): __RQE = self.manage_topic_endpoint + '/' + topicname self.topicInfo = exec_request(__METHOD="get", __EXPECTED="json", __URL=__RQE, __HEADERS=self.topic_headers) return self.topicInfo
def GetConsumers(self): __RQE = self.lenses_consumers_endpoint self.getConsumers = exec_request(__METHOD="get", __EXPECTED="json", __URL=__RQE, __HEADERS=self.consumers_headers) return self.getConsumers
def GetAlerts(self, pageSize=999999999): __RQE = self.admin_alerts_endpoint __RQE = __RQE + '?pageSize=%s' % pageSize self.alerts = exec_request(__METHOD="get", __EXPECTED="json", __URL=__RQE, __HEADERS=self.admin_x_headers, __VERIFY=self.verify_cert) return self.alerts
def GetGlobalCompatibility(self): __RQE = self.schemas_config_end_point self.getGlobalCompatibility = exec_request( __METHOD="get", __EXPECTED="json", __URL=__RQE, __HEADERS=self.registry_headers) return self.getGlobalCompatibility
def DeleteUser(self, username): __RQE = self.url + "/api/v1/user/" + username self.deleteUser = exec_request(__METHOD="delete", __EXPECTED="text", __URL=__RQE, __HEADERS=self.admin_text_plain_headers, __VERIFY=self.verify_cert) return self.deleteUser
def DeleteSA(self, name=None): __RQE = self.url + "/api/v1/serviceaccount/" + name self.deleteSA = exec_request(__METHOD="delete", __EXPECTED="text", __URL=__RQE, __HEADERS=self.admin_x_headers, __VERIFY=self.verify_cert) return self.deleteSA
def AvailableTopicConfigKeys(self): __RQE = self.topic_config_end_point + "/keys" self.availableTopicConfigKeys = exec_request( __METHOD="get", __EXPECTED="json", __URL=__RQE, __HEADERS=self.topic_headers) return self.availableTopicConfigKeys
def GetTopology(self): __RQE = self.lenses_topology_endpoint self.getTopology = exec_request(__METHOD="get", __EXPECTED="json", __URL=__RQE, __HEADERS=self.topology_headers, __VERIFY=self.verify_cert) return self.getTopology
def GetUsers(self): __RQE = self.admin_users_endpoint self.getUsers = exec_request(__METHOD="get", __EXPECTED="json", __URL=__RQE, __HEADERS=self.admin_x_headers, __VERIFY=self.verify_cert) return self.getUsers
def GetUsers(self): __RQE = self.admin_users_endpoint self.getUsers = exec_request( __METHOD="get", __EXPECTED="json", __URL=__RQE, __HEADERS=self.admin_text_plain_headers ) return self.getUsers
def DeleteGroup(self, group): __RQE = self.url + "/api/v1/group/" + group self.deleteGroup = exec_request( __METHOD="delete", __EXPECTED="text", __URL=__RQE, __HEADERS=self.admin_text_plain_headers ) return self.deleteGroup
def ValidateSqlQuery(self): self.validateSqlQuery = exec_request( __METHOD="get", __EXPECTED="text", __URL=self.lenses_sql_query_validation, __HEADERS=self.active_headers, __DATA=self.params) if 'Expected one of Alter' in self.validateSqlQuery: raise Exception(self.validateSqlQuery.text)
def CreateGroup(self, payload): __RQE = self.url + "/api/v1/group" self.createGroup = exec_request(__METHOD="post", __EXPECTED="text", __URL=__RQE, __HEADERS=self.admin_x_headers, __DATA=payload, __VERIFY=self.verify_cert) return self.createGroup
def UpdateGroup(self, group, payload): __RQE = self.url + "/api/v1/group/" + group self.updateGroup = exec_request( __METHOD="put", __EXPECTED="text", __URL=__RQE, __HEADERS=self.admin_text_plain_headers, __DATA=payload ) return self.updateGroup
def GetAllSubjects(self): """ Returns: List with all subjects """ self.getAllSubjects = exec_request(__METHOD="get", __EXPECTED="json", __URL=self.schemas_end_point, __HEADERS=self.registry_headers) return self.getAllSubjects
def UpdateSchema(self, subject, schema_json): __RQE = self.url __RQE = __RQE + "/api/proxy-sr/subjects/" __RQE = __RQE + subject + "/versions/" self.registerNewSchema = exec_request(__METHOD="post", __EXPECTED="json", __URL=__RQE, __HEADERS=self.registry_headers, __DATA=schema_json) return self.registerNewSchema