Example #1
0
int oph_odb_free_ophidiadb(ophidiadb * oDB)
{
	if (!oDB)
		return OPH_ODB_NULL_PARAM;

	if (oDB->name) {
		free(oDB->name);
		oDB->name = NULL;
	}
	if (oDB->hostname) {
		free(oDB->hostname);
		oDB->hostname = NULL;
	}
	if (oDB->username) {
		free(oDB->username);
		oDB->username = NULL;
	}
	if (oDB->pwd) {
		free(oDB->pwd);
		oDB->pwd = NULL;
	}
	if (oDB->conn) {
		oph_odb_disconnect_from_ophidiadb(oDB);
		oDB->conn = NULL;
	}

	free(oDB);

	return OPH_ODB_SUCCESS;
}
int env_unset(oph_operator_struct *handle)
{
  //If NULL return success; it's already free
  if (!handle || !handle->operator_handle)
    return OPH_ANALYTICS_OPERATOR_SUCCESS;    
 
  oph_odb_disconnect_from_ophidiadb(&((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->oDB);
  oph_odb_free_ophidiadb(&((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->oDB);
  if(((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->container_input){
	  free((char *)((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->container_input); 
	  ((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->container_input = NULL;
  }

  if(((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->cwd){
	  free((char *)((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->cwd); 
	  ((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->cwd = NULL;
  }

  if(((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->user){
	  free((char *)((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->user); 
	  ((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->user = NULL;
  }
  if(((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->objkeys){
      oph_tp_free_multiple_value_param_list(((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->objkeys, ((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->objkeys_num);
      ((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->objkeys = NULL;
  }
  if(((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->sessionid){
	  free((char *)((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->sessionid);
	  ((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->sessionid = NULL;
  }
  free((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle);
  handle->operator_handle = NULL;
  
  return OPH_ANALYTICS_OPERATOR_SUCCESS;
}
int env_unset(oph_operator_struct * handle)
{
	//If NULL return success; it's already free
	if (!handle || !handle->operator_handle)
		return OPH_ANALYTICS_OPERATOR_SUCCESS;

	oph_odb_disconnect_from_ophidiadb(&((OPH_UNPUBLISH_operator_handle *) handle->operator_handle)->oDB);
	oph_odb_free_ophidiadb(&((OPH_UNPUBLISH_operator_handle *) handle->operator_handle)->oDB);
	if (((OPH_UNPUBLISH_operator_handle *) handle->operator_handle)->datacube_path) {
		free((char *) ((OPH_UNPUBLISH_operator_handle *) handle->operator_handle)->datacube_path);
		((OPH_UNPUBLISH_operator_handle *) handle->operator_handle)->datacube_path = NULL;
	}
	if (((OPH_UNPUBLISH_operator_handle *) handle->operator_handle)->objkeys) {
		oph_tp_free_multiple_value_param_list(((OPH_UNPUBLISH_operator_handle *) handle->operator_handle)->objkeys, ((OPH_UNPUBLISH_operator_handle *) handle->operator_handle)->objkeys_num);
		((OPH_UNPUBLISH_operator_handle *) handle->operator_handle)->objkeys = NULL;
	}
	if (((OPH_UNPUBLISH_operator_handle *) handle->operator_handle)->sessionid) {
		free((char *) ((OPH_UNPUBLISH_operator_handle *) handle->operator_handle)->sessionid);
		((OPH_UNPUBLISH_operator_handle *) handle->operator_handle)->sessionid = NULL;
	}
	free((OPH_UNPUBLISH_operator_handle *) handle->operator_handle);
	handle->operator_handle = NULL;

	return OPH_ANALYTICS_OPERATOR_SUCCESS;
}
int env_unset(oph_operator_struct * handle)
{
	//If NULL return success; it's already free
	if (!handle || !handle->operator_handle)
		return OPH_ANALYTICS_OPERATOR_SUCCESS;

	//Only master process has to close and release connection to management OphidiaDB
	if (handle->proc_rank == 0) {
		oph_odb_disconnect_from_ophidiadb(&((OPH_SPLIT_operator_handle *) handle->operator_handle)->oDB);
		oph_odb_free_ophidiadb(&((OPH_SPLIT_operator_handle *) handle->operator_handle)->oDB);
	}
	if (((OPH_SPLIT_operator_handle *) handle->operator_handle)->fragment_ids) {
		free((char *) ((OPH_SPLIT_operator_handle *) handle->operator_handle)->fragment_ids);
		((OPH_SPLIT_operator_handle *) handle->operator_handle)->fragment_ids = NULL;
	}
	if (((OPH_SPLIT_operator_handle *) handle->operator_handle)->objkeys) {
		oph_tp_free_multiple_value_param_list(((OPH_SPLIT_operator_handle *) handle->operator_handle)->objkeys, ((OPH_SPLIT_operator_handle *) handle->operator_handle)->objkeys_num);
		((OPH_SPLIT_operator_handle *) handle->operator_handle)->objkeys = NULL;
	}
	if (((OPH_SPLIT_operator_handle *) handle->operator_handle)->sessionid) {
		free((char *) ((OPH_SPLIT_operator_handle *) handle->operator_handle)->sessionid);
		((OPH_SPLIT_operator_handle *) handle->operator_handle)->sessionid = NULL;
	}
	if (((OPH_SPLIT_operator_handle *) handle->operator_handle)->description) {
		free((char *) ((OPH_SPLIT_operator_handle *) handle->operator_handle)->description);
		((OPH_SPLIT_operator_handle *) handle->operator_handle)->description = NULL;
	}
	free((OPH_SPLIT_operator_handle *) handle->operator_handle);
	handle->operator_handle = NULL;

	return OPH_ANALYTICS_OPERATOR_SUCCESS;
}
Example #5
0
int oph_odb_connect_to_ophidiadb(ophidiadb * oDB)
{
	if (!oDB)
		return OPH_ODB_NULL_PARAM;

	oDB->conn = NULL;
	if (!(oDB->conn = mysql_init(NULL))) {
		oph_odb_disconnect_from_ophidiadb(oDB);
		return OPH_ODB_MYSQL_ERROR;
	}

	/* Connect to database */
	if (!mysql_real_connect(oDB->conn, oDB->hostname, oDB->username, oDB->pwd, oDB->name, oDB->server_port, NULL, 0)) {
		oph_odb_disconnect_from_ophidiadb(oDB);
		return OPH_ODB_MYSQL_ERROR;
	}

	return OPH_ODB_SUCCESS;
}
int env_unset(oph_operator_struct *handle)
{
  //If NULL return success; it's already free
  if (!handle || !handle->operator_handle)
    return OPH_ANALYTICS_OPERATOR_SUCCESS;    

  oph_odb_disconnect_from_ophidiadb(&((OPH_METADATA_operator_handle*)handle->operator_handle)->oDB);
  oph_odb_free_ophidiadb(&((OPH_METADATA_operator_handle*)handle->operator_handle)->oDB);

  if(((OPH_METADATA_operator_handle*)handle->operator_handle)->metadata_id_str){
	  free((char *)((OPH_METADATA_operator_handle*)handle->operator_handle)->metadata_id_str);
	  ((OPH_METADATA_operator_handle*)handle->operator_handle)->metadata_id_str = NULL;
  }
  if(((OPH_METADATA_operator_handle*)handle->operator_handle)->metadata_keys){
      oph_tp_free_multiple_value_param_list(((OPH_METADATA_operator_handle*)handle->operator_handle)->metadata_keys, ((OPH_METADATA_operator_handle*)handle->operator_handle)->metadata_keys_num);
      ((OPH_METADATA_operator_handle*)handle->operator_handle)->metadata_keys = NULL;
  }
  if(((OPH_METADATA_operator_handle*)handle->operator_handle)->variable){
      free((char *)((OPH_METADATA_operator_handle*)handle->operator_handle)->variable);
      ((OPH_METADATA_operator_handle*)handle->operator_handle)->variable = NULL;
  }
  if(((OPH_METADATA_operator_handle*)handle->operator_handle)->metadata_type){
      free((char *)((OPH_METADATA_operator_handle*)handle->operator_handle)->metadata_type);
      ((OPH_METADATA_operator_handle*)handle->operator_handle)->metadata_type = NULL;
  }
  if(((OPH_METADATA_operator_handle*)handle->operator_handle)->metadata_type_filter){
      free((char *)((OPH_METADATA_operator_handle*)handle->operator_handle)->metadata_type_filter);
      ((OPH_METADATA_operator_handle*)handle->operator_handle)->metadata_type_filter = NULL;
  }
  if(((OPH_METADATA_operator_handle*)handle->operator_handle)->metadata_value){
      free((char *)((OPH_METADATA_operator_handle*)handle->operator_handle)->metadata_value);
      ((OPH_METADATA_operator_handle*)handle->operator_handle)->metadata_value = NULL;
  }
  if(((OPH_METADATA_operator_handle*)handle->operator_handle)->metadata_value_filter){
      free((char *)((OPH_METADATA_operator_handle*)handle->operator_handle)->metadata_value_filter);
      ((OPH_METADATA_operator_handle*)handle->operator_handle)->metadata_value_filter = NULL;
  }
  if(((OPH_METADATA_operator_handle*)handle->operator_handle)->user){
      free((char *)((OPH_METADATA_operator_handle*)handle->operator_handle)->user);
      ((OPH_METADATA_operator_handle*)handle->operator_handle)->user = NULL;
  }
  if(((OPH_METADATA_operator_handle*)handle->operator_handle)->objkeys){
      oph_tp_free_multiple_value_param_list(((OPH_METADATA_operator_handle*)handle->operator_handle)->objkeys, ((OPH_METADATA_operator_handle*)handle->operator_handle)->objkeys_num);
      ((OPH_METADATA_operator_handle*)handle->operator_handle)->objkeys = NULL;
  }
  if(((OPH_METADATA_operator_handle*)handle->operator_handle)->sessionid){
      free((char *)((OPH_METADATA_operator_handle*)handle->operator_handle)->sessionid);
      ((OPH_METADATA_operator_handle*)handle->operator_handle)->sessionid = NULL;
  }
  free((OPH_METADATA_operator_handle*)handle->operator_handle);
  handle->operator_handle = NULL;
  
  return OPH_ANALYTICS_OPERATOR_SUCCESS;
}
Example #7
0
int oph_odb_change_job_status(int idjob, enum oph__oph_odb_job_status status)
{
	int res;
	ophidiadb oDB;

	oph_odb_initialize_ophidiadb(&oDB);
	if ((res = oph_odb_read_config_ophidiadb(&oDB))) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to read OphidiaDB configuration\n");
		oph_odb_disconnect_from_ophidiadb(&oDB);
		return res;
	}
	if ((res = oph_odb_connect_to_ophidiadb(&oDB))) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to connect to OphidiaDB. Check access parameters.\n");
		oph_odb_disconnect_from_ophidiadb(&oDB);
		return res;
	}

	oph_odb_set_job_status(idjob, status, &oDB);

	oph_odb_disconnect_from_ophidiadb(&oDB);

	return OPH_ODB_SUCCESS;
}
Example #8
0
int oph_odb_check_connection_to_ophidiadb(ophidiadb * oDB)
{
	if (!oDB)
		return OPH_ODB_NULL_PARAM;

	if (!(oDB->conn))
		return OPH_ODB_MYSQL_ERROR;

	if (mysql_ping(oDB->conn)) {
		mysql_close(oDB->conn);
		/* Connect to database */
		if (oph_odb_connect_to_ophidiadb(oDB)) {
			oph_odb_disconnect_from_ophidiadb(oDB);
			return OPH_ODB_MYSQL_ERROR;
		}
	}
	return OPH_ODB_SUCCESS;
}
int task_execute(oph_operator_struct * handle)
{
	if (!handle || !handle->operator_handle) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Null Handle\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_NULL_OPERATOR_HANDLE);
		return OPH_ANALYTICS_OPERATOR_NULL_OPERATOR_HANDLE;
	}
	//Only master process has to continue
	if (handle->proc_rank != 0)
		return OPH_ANALYTICS_OPERATOR_SUCCESS;

	logging(LOG_INFO, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_INFO_START);

	int level = ((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->level;
	char *func_ret = ((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->func_ret;
	char *func_type = ((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->func_type;
	char *name_filter = ((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->name_filter;
	int limit = ((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->limit;
	int id_dbms = ((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->id_dbms;
	ophidiadb *oDB = &((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->oDB;
	char **objkeys = ((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->objkeys;
	int objkeys_num = ((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->objkeys_num;

	if (oph_odb_read_ophidiadb_config_file(oDB)) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to read OphidiaDB configuration\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_OPHIDIADB_CONFIGURATION_FILE_NO_CONTAINER);
		return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
	}

	if (oph_odb_connect_to_ophidiadb(oDB)) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to connect to OphidiaDB. Check access parameters.\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_OPHIDIADB_CONNECTION_ERROR_NO_CONTAINER);
		oph_odb_disconnect_from_ophidiadb(&((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->oDB);
		return OPH_ANALYTICS_OPERATOR_MYSQL_ERROR;
	}

	oph_odb_dbms_instance dbms;
	if (id_dbms == 0) {
		if (oph_odb_stge_retrieve_first_dbmsinstance(oDB, &dbms)) {
			pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to retrieve DBMS info\n");
			logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_RETRIEVE_DBMS_ERROR, id_dbms);
			oph_odb_disconnect_from_ophidiadb(&((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->oDB);
			return OPH_ANALYTICS_OPERATOR_MYSQL_ERROR;
		}
	} else {
		if (oph_odb_stge_retrieve_dbmsinstance(oDB, id_dbms, &dbms)) {
			pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to retrieve DBMS info\n");
			logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_RETRIEVE_DBMS_ERROR, id_dbms);
			oph_odb_disconnect_from_ophidiadb(&((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->oDB);
			return OPH_ANALYTICS_OPERATOR_MYSQL_ERROR;
		}
	}
	oph_odb_disconnect_from_ophidiadb(&((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->oDB);

	int num_fields;
	switch (level) {
		case 5:
			printf("+-------------------------------------+--------------+-----------------------------------------------+-----------------+---------+\n");
			printf("| %-35s | %-12s | %-45s | %-15s | %-7s |\n", "PRIMITIVE NAME", "RETURN TYPE", "DYNAMIC LIBRARY", "PRIMITIVE TYPE", "DBMS ID");
			printf("+-------------------------------------+--------------+-----------------------------------------------+-----------------+---------+\n");
			if (oph_json_is_objkey_printable(objkeys, objkeys_num, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST)) {
				num_fields = 5;
				char *keys[5] = { "PRIMITIVE NAME", "RETURN TYPE", "DYNAMIC LIBRARY", "PRIMITIVE TYPE", "DBMS ID" };
				char *fieldtypes[5] = { "string", "string", "string", "string", "int" };
				if (oph_json_add_grid(handle->operator_json, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST, "Primitives List", NULL, keys, num_fields, fieldtypes, num_fields)) {
					pmesg(LOG_ERROR, __FILE__, __LINE__, "ADD GRID error\n");
					logging(LOG_WARNING, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, "ADD GRID error\n");
					return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
				}
			}
			break;
		case 4:
			printf("+-------------------------------------+--------------+-----------------------------------------------+-----------------+\n");
			printf("| %-35s | %-12s | %-45s | %-15s |\n", "PRIMITIVE NAME", "RETURN TYPE", "DYNAMIC LIBRARY", "PRIMITIVE TYPE");
			printf("+-------------------------------------+--------------+-----------------------------------------------+-----------------+\n");
			if (oph_json_is_objkey_printable(objkeys, objkeys_num, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST)) {
				num_fields = 4;
				char *keys[4] = { "PRIMITIVE NAME", "RETURN TYPE", "DYNAMIC LIBRARY", "PRIMITIVE TYPE" };
				char *fieldtypes[4] = { "string", "string", "string", "string" };
				if (oph_json_add_grid(handle->operator_json, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST, "Primitives List", NULL, keys, num_fields, fieldtypes, num_fields)) {
					pmesg(LOG_ERROR, __FILE__, __LINE__, "ADD GRID error\n");
					logging(LOG_WARNING, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, "ADD GRID error\n");
					return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
				}
			}
			break;
		case 3:
			printf("+-------------------------------------+--------------+-----------------------------------------------+\n");
			printf("| %-35s | %-12s | %-45s |\n", "PRIMITIVE NAME", "RETURN TYPE", "DYNAMIC LIBRARY");
			printf("+-------------------------------------+--------------+-----------------------------------------------+\n");
			if (oph_json_is_objkey_printable(objkeys, objkeys_num, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST)) {
				num_fields = 3;
				char *keys[3] = { "PRIMITIVE NAME", "RETURN TYPE", "DYNAMIC LIBRARY" };
				char *fieldtypes[3] = { "string", "string", "string" };
				if (oph_json_add_grid(handle->operator_json, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST, "Primitives List", NULL, keys, num_fields, fieldtypes, num_fields)) {
					pmesg(LOG_ERROR, __FILE__, __LINE__, "ADD GRID error\n");
					logging(LOG_WARNING, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, "ADD GRID error\n");
					return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
				}
			}
			break;
		case 2:
			printf("+-------------------------------------+--------------+\n");
			printf("| %-35s | %-12s |\n", "PRIMITIVE NAME", "RETURN TYPE");
			printf("+-------------------------------------+--------------+\n");
			if (oph_json_is_objkey_printable(objkeys, objkeys_num, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST)) {
				num_fields = 2;
				char *keys[2] = { "PRIMITIVE NAME", "RETURN TYPE" };
				char *fieldtypes[2] = { "string", "string" };
				if (oph_json_add_grid(handle->operator_json, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST, "Primitives List", NULL, keys, num_fields, fieldtypes, num_fields)) {
					pmesg(LOG_ERROR, __FILE__, __LINE__, "ADD GRID error\n");
					logging(LOG_WARNING, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, "ADD GRID error\n");
					return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
				}
			}
			break;
		case 1:
			printf("+-------------------------------------+\n");
			printf("| %-35s |\n", "PRIMITIVE NAME");
			printf("+-------------------------------------+\n");
			if (oph_json_is_objkey_printable(objkeys, objkeys_num, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST)) {
				num_fields = 1;
				char *keys[1] = { "PRIMITIVE NAME" };
				char *fieldtypes[1] = { "string" };
				if (oph_json_add_grid(handle->operator_json, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST, "Primitives List", NULL, keys, num_fields, fieldtypes, num_fields)) {
					pmesg(LOG_ERROR, __FILE__, __LINE__, "ADD GRID error\n");
					logging(LOG_WARNING, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, "ADD GRID error\n");
					return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
				}
			}
			break;
		default:
			pmesg(LOG_ERROR, __FILE__, __LINE__, "List level unrecognized\n");
			logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_BAD_LEVEL);
			return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}

	if (oph_dc_setup_dbms(&(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server), dbms.io_server_type)) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to initialize IO server.\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_IOPLUGIN_SETUP_ERROR, dbms.io_server_type);
		return OPH_ANALYTICS_OPERATOR_MEMORY_ERR;
	}

	if (oph_dc_connect_to_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, &dbms, 0)) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to connect to DBMS. Check access parameters.\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_CONNECT_DBMS_ERROR, dbms.id_dbms);
		oph_dc_disconnect_from_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, &dbms);
		oph_dc_cleanup_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server);
		return OPH_ANALYTICS_OPERATOR_MYSQL_ERROR;
	}

	oph_ioserver_result *primitives_list = NULL;

	//retrieve primitives list
	if (oph_dc_get_primitives(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, &dbms, name_filter, &primitives_list)) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to retrieve primitives list\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_RETRIEVE_LIST_ERROR, dbms.id_dbms);
		oph_dc_disconnect_from_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, &dbms);
		oph_dc_cleanup_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server);
		return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
	}

	int num_rows = 0;

	//Empty set
	if (!(num_rows = primitives_list->num_rows)) {
		pmesg(LOG_WARNING, __FILE__, __LINE__, "No rows found by query\n");
		logging(LOG_WARNING, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_NO_ROWS_FOUND);
		oph_ioserver_free_result(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, primitives_list);
		oph_dc_disconnect_from_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, &dbms);
		oph_dc_cleanup_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server);
		return OPH_ANALYTICS_OPERATOR_SUCCESS;
	}

	if (primitives_list->num_fields != 4) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Not enough fields found by query\n");
		logging(LOG_WARNING, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_NO_ROWS_FOUND);
		oph_ioserver_free_result(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, primitives_list);
		oph_dc_disconnect_from_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, &dbms);
		oph_dc_cleanup_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server);
		return OPH_ANALYTICS_OPERATOR_SUCCESS;
	}

	oph_ioserver_row *curr_row = NULL;

	if (oph_ioserver_fetch_row(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, primitives_list, &curr_row)) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to fetch row\n");
		logging(LOG_WARNING, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_ROW_ERROR);
		oph_ioserver_free_result(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, primitives_list);
		oph_dc_disconnect_from_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, &dbms);
		oph_dc_cleanup_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server);
		return OPH_DC_SERVER_ERROR;
	}
	//For each ROW
	char tmp_ret[OPH_COMMON_BUFFER_LEN] = { '\0' }, tmp_type[OPH_COMMON_BUFFER_LEN] = {
	'\0'};
	int n;
	int count_limit = 0;
	while (curr_row->row) {
		if (limit > 0 && count_limit >= limit)
			break;
		switch (level) {
			case 5:
				if (func_ret || func_type) {
					if (func_ret) {
						n = snprintf(tmp_ret, OPH_COMMON_BUFFER_LEN, "%s", (curr_row->row[1][0] == '0') ? "array" : "number");
						if (n <= 0)
							break;
						if (strncmp(tmp_ret, func_ret, OPH_COMMON_BUFFER_LEN) != 0)
							break;
					}
					if (func_type) {
						n = snprintf(tmp_type, OPH_COMMON_BUFFER_LEN, "%s", (curr_row->row[3][0] == 'f') ? "simple" : "aggregate");
						if (n <= 0)
							break;
						if (strncmp(tmp_type, func_type, OPH_COMMON_BUFFER_LEN) != 0)
							break;
					}
					printf("| %-35s | %-12s | %-45s | %-15s | %7d |\n", curr_row->row[0], (curr_row->row[1][0] == '0') ? "array" : "number", curr_row->row[2],
					       (curr_row->row[3][0] == 'f') ? "simple" : "aggregate", dbms.id_dbms);
					if (oph_json_is_objkey_printable(objkeys, objkeys_num, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST)) {
						char tmpbuf[20];
						snprintf(tmpbuf, 20, "%d", dbms.id_dbms);
						char *my_row[5] =
						    { curr_row->row[0], (curr_row->row[1][0] == '0') ? "array" : "number", curr_row->row[2], (curr_row->row[3][0] == 'f') ? "simple" : "aggregate",
							tmpbuf
						};
						if (oph_json_add_grid_row(handle->operator_json, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST, my_row)) {
							pmesg(LOG_ERROR, __FILE__, __LINE__, "ADD GRID ROW error\n");
							logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, "ADD GRID ROW error\n");
							oph_ioserver_free_result(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, primitives_list);
							oph_dc_disconnect_from_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, &dbms);
							oph_dc_cleanup_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server);
							return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
						}
					}
				} else {
					printf("| %-35s | %-12s | %-45s | %-15s | %7d |\n", curr_row->row[0], (curr_row->row[1][0] == '0') ? "array" : "number", curr_row->row[2],
					       (curr_row->row[3][0] == 'f') ? "simple" : "aggregate", dbms.id_dbms);
					if (oph_json_is_objkey_printable(objkeys, objkeys_num, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST)) {
						char tmpbuf[20];
						snprintf(tmpbuf, 20, "%d", dbms.id_dbms);
						char *my_row[5] =
						    { curr_row->row[0], (curr_row->row[1][0] == '0') ? "array" : "number", curr_row->row[2], (curr_row->row[3][0] == 'f') ? "simple" : "aggregate",
							tmpbuf
						};
						if (oph_json_add_grid_row(handle->operator_json, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST, my_row)) {
							pmesg(LOG_ERROR, __FILE__, __LINE__, "ADD GRID ROW error\n");
							logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, "ADD GRID ROW error\n");
							oph_ioserver_free_result(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, primitives_list);
							oph_dc_disconnect_from_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, &dbms);
							oph_dc_cleanup_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server);
							return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
						}
					}
				}
				count_limit++;
				break;
			case 4:
				if (func_ret || func_type) {
					if (func_ret) {
						n = snprintf(tmp_ret, OPH_COMMON_BUFFER_LEN, "%s", (curr_row->row[1][0] == '0') ? "array" : "number");
						if (n <= 0)
							break;
						if (strncmp(tmp_ret, func_ret, OPH_COMMON_BUFFER_LEN) != 0)
							break;
					}
					if (func_type) {
						n = snprintf(tmp_type, OPH_COMMON_BUFFER_LEN, "%s", (curr_row->row[3][0] == 'f') ? "simple" : "aggregate");
						if (n <= 0)
							break;
						if (strncmp(tmp_type, func_type, OPH_COMMON_BUFFER_LEN) != 0)
							break;
					}
					printf("| %-35s | %-12s | %-45s | %-15s |\n", curr_row->row[0], (curr_row->row[1][0] == '0') ? "array" : "number", curr_row->row[2],
					       (curr_row->row[3][0] == 'f') ? "simple" : "aggregate");
					if (oph_json_is_objkey_printable(objkeys, objkeys_num, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST)) {
						char *my_row[4] =
						    { curr_row->row[0], (curr_row->row[1][0] == '0') ? "array" : "number", curr_row->row[2], (curr_row->row[3][0] == 'f') ? "simple" : "aggregate" };
						if (oph_json_add_grid_row(handle->operator_json, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST, my_row)) {
							pmesg(LOG_ERROR, __FILE__, __LINE__, "ADD GRID ROW error\n");
							logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, "ADD GRID ROW error\n");
							oph_ioserver_free_result(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, primitives_list);
							oph_dc_disconnect_from_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, &dbms);
							oph_dc_cleanup_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server);
							return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
						}
					}
				} else {
					printf("| %-35s | %-12s | %-45s | %-15s |\n", curr_row->row[0], (curr_row->row[1][0] == '0') ? "array" : "number", curr_row->row[2],
					       (curr_row->row[3][0] == 'f') ? "simple" : "aggregate");
					if (oph_json_is_objkey_printable(objkeys, objkeys_num, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST)) {
						char *my_row[4] =
						    { curr_row->row[0], (curr_row->row[1][0] == '0') ? "array" : "number", curr_row->row[2], (curr_row->row[3][0] == 'f') ? "simple" : "aggregate" };
						if (oph_json_add_grid_row(handle->operator_json, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST, my_row)) {
							pmesg(LOG_ERROR, __FILE__, __LINE__, "ADD GRID ROW error\n");
							logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, "ADD GRID ROW error\n");
							oph_ioserver_free_result(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, primitives_list);
							oph_dc_disconnect_from_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, &dbms);
							oph_dc_cleanup_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server);
							return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
						}
					}
				}
				count_limit++;
				break;
			case 3:
				if (func_ret) {
					n = snprintf(tmp_ret, OPH_COMMON_BUFFER_LEN, "%s", (curr_row->row[1][0] == '0') ? "array" : "number");
					if (n <= 0)
						break;
					if (strncmp(tmp_ret, func_ret, OPH_COMMON_BUFFER_LEN) != 0)
						break;
					printf("| %-35s | %-12s | %-45s |\n", curr_row->row[0], (curr_row->row[1][0] == '0') ? "array" : "number", curr_row->row[2]);
					if (oph_json_is_objkey_printable(objkeys, objkeys_num, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST)) {
						char *my_row[3] = { curr_row->row[0], (curr_row->row[1][0] == '0') ? "array" : "number", curr_row->row[2] };
						if (oph_json_add_grid_row(handle->operator_json, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST, my_row)) {
							pmesg(LOG_ERROR, __FILE__, __LINE__, "ADD GRID ROW error\n");
							logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, "ADD GRID ROW error\n");
							oph_ioserver_free_result(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, primitives_list);
							oph_dc_disconnect_from_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, &dbms);
							oph_dc_cleanup_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server);
							return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
						}
					}
				} else {
					printf("| %-35s | %-12s | %-45s |\n", curr_row->row[0], (curr_row->row[1][0] == '0') ? "array" : "number", curr_row->row[2]);
					if (oph_json_is_objkey_printable(objkeys, objkeys_num, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST)) {
						char *my_row[3] = { curr_row->row[0], (curr_row->row[1][0] == '0') ? "array" : "number", curr_row->row[2] };
						if (oph_json_add_grid_row(handle->operator_json, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST, my_row)) {
							pmesg(LOG_ERROR, __FILE__, __LINE__, "ADD GRID ROW error\n");
							logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, "ADD GRID ROW error\n");
							oph_ioserver_free_result(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, primitives_list);
							oph_dc_disconnect_from_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, &dbms);
							oph_dc_cleanup_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server);
							return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
						}
					}
				}
				count_limit++;
				break;
			case 2:
				if (func_ret) {
					n = snprintf(tmp_ret, OPH_COMMON_BUFFER_LEN, "%s", (curr_row->row[1][0] == '0') ? "array" : "number");
					if (n <= 0)
						break;
					if (strncmp(tmp_ret, func_ret, OPH_COMMON_BUFFER_LEN) != 0)
						break;
					printf("| %-35s | %-12s |\n", curr_row->row[0], (curr_row->row[1][0] == '0') ? "array" : "number");
					if (oph_json_is_objkey_printable(objkeys, objkeys_num, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST)) {
						char *my_row[2] = { curr_row->row[0], (curr_row->row[1][0] == '0') ? "array" : "number" };
						if (oph_json_add_grid_row(handle->operator_json, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST, my_row)) {
							pmesg(LOG_ERROR, __FILE__, __LINE__, "ADD GRID ROW error\n");
							logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, "ADD GRID ROW error\n");
							oph_ioserver_free_result(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, primitives_list);
							oph_dc_disconnect_from_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, &dbms);
							oph_dc_cleanup_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server);
							return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
						}
					}
				} else {
					printf("| %-35s | %-12s |\n", curr_row->row[0], (curr_row->row[1][0] == '0') ? "array" : "number");
					if (oph_json_is_objkey_printable(objkeys, objkeys_num, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST)) {
						char *my_row[2] = { curr_row->row[0], (curr_row->row[1][0] == '0') ? "array" : "number" };
						if (oph_json_add_grid_row(handle->operator_json, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST, my_row)) {
							pmesg(LOG_ERROR, __FILE__, __LINE__, "ADD GRID ROW error\n");
							logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, "ADD GRID ROW error\n");
							oph_ioserver_free_result(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, primitives_list);
							oph_dc_disconnect_from_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, &dbms);
							oph_dc_cleanup_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server);
							return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
						}
					}
				}
				count_limit++;
				break;
			case 1:
				printf("| %-35s |\n", curr_row->row[0]);
				if (oph_json_is_objkey_printable(objkeys, objkeys_num, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST)) {
					char *my_row[1] = { curr_row->row[0] };
					if (oph_json_add_grid_row(handle->operator_json, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST, my_row)) {
						pmesg(LOG_ERROR, __FILE__, __LINE__, "ADD GRID ROW error\n");
						logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, "ADD GRID ROW error\n");
						oph_ioserver_free_result(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, primitives_list);
						oph_dc_disconnect_from_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, &dbms);
						oph_dc_cleanup_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server);
						return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
					}
				}
				count_limit++;
				break;
			default:
				pmesg(LOG_ERROR, __FILE__, __LINE__, "List level unrecognized\n");
				logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_BAD_LEVEL);
				oph_ioserver_free_result(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, primitives_list);
				oph_dc_disconnect_from_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, &dbms);
				oph_dc_cleanup_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server);
				return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
		}

		if (oph_ioserver_fetch_row(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, primitives_list, &curr_row)) {
			pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to fetch row\n");
			logging(LOG_WARNING, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_ROW_ERROR);
			oph_ioserver_free_result(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, primitives_list);
			oph_dc_disconnect_from_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, &dbms);
			oph_dc_cleanup_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server);
			return OPH_DC_SERVER_ERROR;
		}

	}

	oph_ioserver_free_result(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, primitives_list);
	oph_dc_disconnect_from_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, &dbms);
	oph_dc_cleanup_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server);

	switch (level) {
		case 5:
			printf("+-------------------------------------+--------------+-----------------------------------------------+-----------------+---------+\n");
			break;
		case 4:
			printf("+-------------------------------------+--------------+-----------------------------------------------+-----------------+\n");
			break;
		case 3:
			printf("+-------------------------------------+--------------+-----------------------------------------------+\n");
			break;
		case 2:
			printf("+-------------------------------------+--------------+\n");
			break;
		case 1:
			printf("+-------------------------------------+\n");
			break;
		default:
			pmesg(LOG_ERROR, __FILE__, __LINE__, "List level unrecognized\n");
			logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_BAD_LEVEL);
			return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}

	printf(OPH_PRIMITIVES_LIST_HELP_MESSAGE);
	if (oph_json_is_objkey_printable(objkeys, objkeys_num, OPH_JSON_OBJKEY_PRIMITIVES_LIST_TIP)) {
		if (oph_json_add_text(handle->operator_json, OPH_JSON_OBJKEY_PRIMITIVES_LIST_TIP, "Useful Tip", OPH_PRIMITIVES_LIST_HELP_MESSAGE)) {
			pmesg(LOG_ERROR, __FILE__, __LINE__, "ADD TEXT error\n");
			logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, "ADD TEXT error\n");
			return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
		}
	}

	logging(LOG_INFO, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_INFO_END);
	return OPH_ANALYTICS_OPERATOR_SUCCESS;
}
int oph_finalize_known_operator(int idjob, oph_json * oper_json, const char *operator_name, char *error_message, int success, char **response, ophidiadb * oDB, enum oph__oph_odb_job_status *exit_code)
{
	pmesg_safe(&global_flag, LOG_DEBUG, __FILE__, __LINE__, "Finalize known operator: %s (%s)\n", success ? "success" : "failure", error_message ? error_message : "-");

	char *jstring = NULL;
	if (oper_json) {
		int return_code = 0;

		if (!success) {
			if (!strlen(error_message)) {
				snprintf(error_message, OPH_MAX_STRING_SIZE, "Operator '%s' failed!", operator_name);
				if (exit_code)
					*exit_code = OPH_ODB_STATUS_ERROR;
			}
			if (oph_json_add_text(oper_json, OPH_JSON_OBJKEY_STATUS, "ERROR", error_message)) {
				pmesg_safe(&global_flag, LOG_WARNING, __FILE__, __LINE__, "ADD TEXT error\n");
				return_code = -1;
			} else if (oph_write_and_get_json(oper_json, &jstring)) {
				pmesg_safe(&global_flag, LOG_WARNING, __FILE__, __LINE__, "JSON file creation error\n");
				return_code = -1;
			}
		} else {
			if (oph_json_add_text(oper_json, OPH_JSON_OBJKEY_STATUS, "SUCCESS", strlen(error_message) ? error_message : NULL)) {
				pmesg_safe(&global_flag, LOG_WARNING, __FILE__, __LINE__, "ADD TEXT error\n");
				return_code = -1;
			} else if (oph_write_and_get_json(oper_json, &jstring)) {
				pmesg_safe(&global_flag, LOG_WARNING, __FILE__, __LINE__, "JSON file creation error\n");
				return_code = -1;
			} else if (exit_code && (*exit_code != OPH_ODB_STATUS_WAIT))
				*exit_code = OPH_ODB_STATUS_COMPLETED;
		}
		oph_json_free(oper_json);

		if (return_code && exit_code)
			*exit_code = OPH_ODB_STATUS_ERROR;

	} else if (exit_code)
		*exit_code = OPH_ODB_STATUS_ERROR;

	if (!jstring) {
		pmesg_safe(&global_flag, LOG_WARNING, __FILE__, __LINE__, "Unable to convert JSON Response into a string\n");
		if (exit_code)
			*exit_code = OPH_ODB_STATUS_ERROR;
		oph_odb_disconnect_from_ophidiadb(oDB);
		return OPH_SERVER_SYSTEM_ERROR;
	}
	if (response)
		*response = jstring;
	else
		free(jstring);

	// Set ODB_STATUS to COMPLETED
	pmesg_safe(&global_flag, LOG_DEBUG, __FILE__, __LINE__, "Finalize OphDB status\n");
	if (exit_code && (*exit_code == OPH_ODB_STATUS_WAIT))
		oph_odb_set_job_status(idjob, OPH_ODB_STATUS_WAIT, oDB);
	else
		oph_odb_stop_job_fast(idjob, oDB);
	oph_odb_disconnect_from_ophidiadb(oDB);

	return OPH_SERVER_OK;
}