def async_cancel_job(self, engine_id, job_id): request = AsyncRequest( "DELETE", self._add_segment(engine_id) + "/jobs/" + job_id) request.set_response_handler(self._ok_response_handler) self._connection.make_request(request) return request
def async_update(self, engine_id, data, data_delete=False, force=False, input=None): """ Asynchronously update engine. :param input: file or directory containing input as raw JSON :param force: :param data_delete: :param data: :param engine_id: :return: """ query = {} if data_delete: query['data_delete'] = True if force: query['force'] = True if input is not None: query['input'] = input path = self._add_segment(engine_id) path = self._add_get_params(path, **query) request = AsyncRequest("POST", path, **data) request.set_response_handler(self._ok_response_handler) self._connection.make_request(request) return request
def create_user(self, role_set_id=None, resource_id=None): request = AsyncRequest("POST", self.path, roleSetId=role_set_id, resourceId=resource_id) request.set_response_handler(self._ok_response_handler) self._connection.make_request(request) return request.get_response()
def grant_permission(self, permitted_user_id, role_set_id, resource_id): path = self.path + "/{}/permissions".format(permitted_user_id) request = AsyncRequest("POST", path, roleSetId=role_set_id, resourceId=resource_id) request.set_response_handler(self._ok_response_handler) self._connection.make_request(request) return request.get_response()
def async_run_command(self, engine_id): data = {} if engine_id is not None: data['engine_id'] = engine_id request = AsyncRequest("POST", self.path + "/batch-train", **data) request.set_response_handler(self._ok_response_handler) self._connection.make_request(request) return request
def async_info(self): """ Asynchronously get system info from Harness Server. :returns: AsyncRequest object. """ request = AsyncRequest("GET", self.path) request.set_response_handler(self._ok_response_handler) self._connection.make_request(request) return request
def async_get(self, event_id): """ Asynchronously get an event from Harness Server. :param event_id: event id returned by the EventServer when creating the event. :returns: AsyncRequest object. """ request = AsyncRequest("GET", self._add_segment(event_id)) request.set_response_handler(self._ok_response_handler) self._connection.make_request(request) return request
def async_create(self, event, entity_type, entity_id, target_entity_type=None, target_entity_id=None, properties=None, event_id=None, event_time=None, creation_time=None): """ Asynchronously create an event. :param event_id: :param event: event name. type str. :param entity_type: entity type. It is the namespace of the entityId and analogous to the table name of a relational database. The entityId must be unique within same entityType. type str. :param entity_id: entity id. *entity_type-entity_id* becomes the unique identifier of the entity. For example, you may have entityType named user, and different entity IDs, say 1 and 2. In this case, user-1 and user-2 uniquely identifies entities. type str :param target_entity_type: target entity type. type str. :param target_entity_id: target entity id. type str. :param properties: a custom dict associated with an event. type dict. :param event_time: the time of the event. type datetime, must contain timezone info. :param creation_time: :returns: AsyncRequest object. You can call the get_response() method using this object to get the final results or status of this asynchronous request. """ data = { "eventId": event_id, "event": event, "entityType": entity_type, "entityId": entity_id, } if target_entity_type is not None: data["targetEntityType"] = target_entity_type if target_entity_id is not None: data["targetEntityId"] = target_entity_id if properties is not None: data["properties"] = properties data["eventTime"] = time_to_string_if_valid(event_time) data["creationTime"] = time_to_string_if_valid(creation_time) request = AsyncRequest("POST", self.path, **data) request.set_response_handler(self._create_response_handler) self._connection.make_request(request) return request
def async_create(self, data): """ Asynchronously create engine. :param data: :return: """ request = AsyncRequest("POST", self.path, **data) request.set_response_handler(self._create_response_handler) self._connection.make_request(request) return request
def async_send_query(self, data): """ Asynchronously send a request to the engine instance with data as the query. :param data: the query: It is converted to an json object using json.dumps method. type dict. :returns: AsyncRequest object. You can call the get_response() method using this object to get the final results or status of this asynchronous request. """ request = AsyncRequest("POST", self.path, **data) request.set_response_handler(self._create_response_handler) self._connection.make_request(request) return request
def get_status(self): """ Get the status of the Harness API Server :returns: status message. :raises: ServerStatusError. """ path = "/" request = AsyncRequest("GET", path) request.set_response_handler(self._ok_response_handler) self._connection.make_request(request) result = request.get_response() return result
def async_update(self, engine_id, import_path, update_type, data): """ Asynchronously update engine with either input events OR new config JSON :param engine_id: should be same as in data, which is json config string :param import_path: if non-empty, defines a path to input json files to import :param update_type: if True means the data = JSON config params for engine :param data: json config data, as in create, engine_id's passed in and in json MUST match :return: """ path = self._add_segment(engine_id) if update_type == "configs": path = path + "/configs" # endpoint on an engine-id, flagging that data is the new config JSON elif update_type == "imports": path = path + "/imports" # endpoint on an engine-id, that tells the engine to import from the import_path query = {'import_path': import_path} path = self._add_get_params(path, **query) elif update_type == "jobs": path = path + "/jobs" # endpoint on an engine-id, that tells the engine to train from existing data # print("Fully constructed path: {}".format(path)) # print("Data supplied: {}".format(data)) request = AsyncRequest("POST", path, **data) # if : # query['force'] = True # if input is not None: # query['input'] = input # path = self._add_segment(engine_id) # path = self._add_get_params(path, **query) # request = AsyncRequest("POST", path, **data) # request.set_response_handler(self._ok_response_handler) # self._connection.make_request(request) # return request # path = self._add_get_params(path, **query) request.set_response_handler(self._ok_response_handler) self._connection.make_request(request) return request
def async_get(self, queried_user_id): """ Asynchronously get an user info from Harness Server. :param user_id: :returns: AsyncRequest object. """ if queried_user_id is None: request = AsyncRequest("GET", self.path) else: request = AsyncRequest("GET", self._add_segment(queried_user_id)) request.set_response_handler(self._ok_response_handler) self._connection.make_request(request) return request
def async_cancel_command(self, command_id): request = AsyncRequest("DELETE", self._add_segment(command_id)) request.set_response_handler(self._ok_response_handler) self._connection.make_request(request) return request
def async_get_commands_list(self): request = AsyncRequest("GET", self.path + "/list/commands") request.set_response_handler(self._ok_response_handler) self._connection.make_request(request) return request
def async_delete(self, engine_id): request = AsyncRequest("DELETE", self._add_segment(engine_id)) request.set_response_handler(self._ok_response_handler) self._connection.make_request(request) return request