int env_set (HASHTBL *task_tbl, oph_operator_struct *handle)
{
  if (!handle){
  	pmesg(LOG_ERROR, __FILE__, __LINE__, "Null Handle\n");
	  return OPH_ANALYTICS_OPERATOR_NULL_OPERATOR_HANDLE;
  }

  if (!task_tbl){
	  pmesg(LOG_ERROR, __FILE__, __LINE__, "Null operator string\n");
      return OPH_ANALYTICS_OPERATOR_BAD_PARAMETER;
  }

  if (handle->operator_handle){
	pmesg(LOG_ERROR, __FILE__, __LINE__, "Operator handle already initialized\n");
    return OPH_ANALYTICS_OPERATOR_NOT_NULL_OPERATOR_HANDLE;
  }

  if (!(handle->operator_handle = (OPH_DELETECONTAINER_operator_handle *) calloc (1, sizeof (OPH_DELETECONTAINER_operator_handle)))){
	pmesg(LOG_ERROR, __FILE__, __LINE__, "Error allocating memory\n");
    logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_DELETECONTAINER_MEMORY_ERROR_HANDLE );
    return OPH_ANALYTICS_OPERATOR_MEMORY_ERR;
  }

  //1 - Set up struct to empty values
  ((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->id_input_container = 0;
  ((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->container_input = NULL;
  ((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->cwd = NULL;
  ((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->user = NULL;
  ((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->hidden = 0;
  ((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->delete_type = 0;
  ((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->objkeys = NULL;
  ((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->objkeys_num = -1;
  ((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->sessionid = NULL;

  ophidiadb *oDB = &((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->oDB;
  oph_odb_init_ophidiadb(oDB);	

  //Only master process has to continue
  if (handle->proc_rank != 0)
	return OPH_ANALYTICS_OPERATOR_SUCCESS;

  //3 - Fill struct with the correct data
  char *container_name, *value;

  // retrieve objkeys
  value = hashtbl_get(task_tbl, OPH_IN_PARAM_OBJKEY_FILTER);
  if(!value){
    pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_OBJKEY_FILTER);
    logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_FRAMEWORK_MISSING_INPUT_PARAMETER, OPH_IN_PARAM_OBJKEY_FILTER );
    return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
  }
  if(oph_tp_parse_multiple_value_param(value, &((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->objkeys, &((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->objkeys_num)){
    pmesg(LOG_ERROR, __FILE__, __LINE__, "Operator string not valid\n");
    logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, "Operator string not valid\n");
    oph_tp_free_multiple_value_param_list(((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->objkeys, ((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->objkeys_num);
    return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
  }

  // retrieve sessionid
  value = hashtbl_get(task_tbl, OPH_ARG_SESSIONID);
  if(!value){
	pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_ARG_SESSIONID);
    logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_FRAMEWORK_MISSING_INPUT_PARAMETER, OPH_ARG_SESSIONID);
	return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
  }
  if(!(((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->sessionid = (char *) strndup (value, OPH_TP_TASKLEN))){
	pmesg(LOG_ERROR, __FILE__, __LINE__, "Error allocating memory\n");
    logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_GENERIC_MEMORY_ERROR_INPUT, "sessionid" );
	return OPH_ANALYTICS_OPERATOR_MEMORY_ERR;
  }

  container_name = (!hashtbl_get(task_tbl, OPH_IN_PARAM_CONTAINER_INPUT) ? "NO-CONTAINER" : hashtbl_get(task_tbl, OPH_IN_PARAM_CONTAINER_INPUT));
  value = hashtbl_get(task_tbl, OPH_IN_PARAM_CONTAINER_INPUT);
  if(!value){
	pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_CONTAINER_INPUT);
    logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_DELETECONTAINER_MISSING_INPUT_PARAMETER, container_name, OPH_IN_PARAM_CONTAINER_INPUT );
    return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
  }
  if(!(((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->container_input = (char *) strndup (value, OPH_TP_TASKLEN))){
	pmesg(LOG_ERROR, __FILE__, __LINE__, "Error allocating memory\n");
	logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_DELETECONTAINER_MEMORY_ERROR_INPUT_NO_CONTAINER, container_name, "container output name" );
	return OPH_ANALYTICS_OPERATOR_MEMORY_ERR;
  }	

  value = hashtbl_get(task_tbl, OPH_IN_PARAM_CWD);
  if(!value){
	pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_CWD);
	logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_DELETECONTAINER_MISSING_INPUT_PARAMETER, container_name, OPH_IN_PARAM_CWD );
	return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
  }
  if(!(((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->cwd = (char *) strndup (value, OPH_TP_TASKLEN))){
	pmesg(LOG_ERROR, __FILE__, __LINE__, "Error allocating memory\n");
	logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_DELETECONTAINER_MEMORY_ERROR_INPUT_NO_CONTAINER, container_name, "input path" );
	
	return OPH_ANALYTICS_OPERATOR_MEMORY_ERR;
  }	

  value = hashtbl_get(task_tbl, OPH_ARG_USERNAME);
  if(!value){
	pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_ARG_USERNAME);
	logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_DELETECONTAINER_MISSING_INPUT_PARAMETER, container_name, OPH_ARG_USERNAME );
	return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
  }
  if(!(((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->user = (char *) strndup (value, OPH_TP_TASKLEN))){
	pmesg(LOG_ERROR, __FILE__, __LINE__, "Error allocating memory\n");
	logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_DELETECONTAINER_MEMORY_ERROR_INPUT_NO_CONTAINER, container_name, "username" );
  }

  value = hashtbl_get(task_tbl, OPH_IN_PARAM_DELETE_TYPE);
  if(!value){
	pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_DELETE_TYPE);
	logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_DELETECONTAINER_MISSING_INPUT_PARAMETER, container_name, OPH_IN_PARAM_DELETE_TYPE );
	return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
  }
  if( !strcmp(value, OPH_DELETE_PHYSIC_TYPE) ){
	((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->delete_type = OPH_DELETE_PHYSIC_CODE;
  }
  else{
	((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->delete_type = OPH_DELETE_LOGIC_CODE;
  }

  value = hashtbl_get(task_tbl, OPH_IN_PARAM_HIDDEN);
  if(!value){
	pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_HIDDEN);
	logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_DELETECONTAINER_MISSING_INPUT_PARAMETER, container_name, OPH_IN_PARAM_HIDDEN );
	return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
  }
  if( !strcmp(value, OPH_COMMON_NO_VALUE) ){
	  ((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->hidden = 0;
  }
  else{
	((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->hidden = 1;
  }

  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_DELETECONTAINER_OPHIDIADB_CONFIGURATION_FILE, container_name );
	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_DELETECONTAINER_OPHIDIADB_CONNECTION_ERROR, container_name );
	return OPH_ANALYTICS_OPERATOR_MYSQL_ERROR;
  }

  return OPH_ANALYTICS_OPERATOR_SUCCESS;
}
int env_set(HASHTBL * task_tbl, oph_operator_struct * handle)
{
	if (!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;
	}

	if (!task_tbl) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Null operator string\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_NULL_TASK_TABLE);
		return OPH_ANALYTICS_OPERATOR_BAD_PARAMETER;
	}

	if (handle->operator_handle) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Operator handle already initialized\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_HANDLE_ALREADY_INITIALIZED);
		return OPH_ANALYTICS_OPERATOR_NOT_NULL_OPERATOR_HANDLE;
	}

	if (!(handle->operator_handle = (OPH_PRIMITIVES_LIST_operator_handle *) calloc(1, sizeof(OPH_PRIMITIVES_LIST_operator_handle)))) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Error allocating memory\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_MEMORY_ERROR_HANDLE);
		return OPH_ANALYTICS_OPERATOR_MEMORY_ERR;
	}
	//1 - Set up struct to empty values
	((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->level = 0;
	((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->func_ret = NULL;
	((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->func_type = NULL;
	((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->name_filter = NULL;
	((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->limit = 0;
	((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->id_dbms = 0;
	((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server = NULL;
	ophidiadb *oDB = &((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->oDB;
	((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->objkeys = NULL;
	((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->objkeys_num = -1;

	//Only master process has to continue
	if (handle->proc_rank != 0)
		return OPH_ANALYTICS_OPERATOR_SUCCESS;

	oph_odb_init_ophidiadb(oDB);

	//3 - Fill struct with the correct data
	char *value;

	// retrieve objkeys
	value = hashtbl_get(task_tbl, OPH_IN_PARAM_OBJKEY_FILTER);
	if (!value) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_OBJKEY_FILTER);
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_FRAMEWORK_MISSING_INPUT_PARAMETER, OPH_IN_PARAM_OBJKEY_FILTER);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}
	if (oph_tp_parse_multiple_value_param
	    (value, &((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->objkeys, &((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->objkeys_num)) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Operator string not valid\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, "Operator string not valid\n");
		oph_tp_free_multiple_value_param_list(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->objkeys,
						      ((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->objkeys_num);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}

	value = hashtbl_get(task_tbl, OPH_IN_PARAM_PRIMITIVE_NAME_FILTER);
	if (!value) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_PRIMITIVE_NAME_FILTER);
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_MISSING_INPUT_PARAMETER, "NO-CONTAINER", OPH_IN_PARAM_PRIMITIVE_NAME_FILTER);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}
	if (!(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->name_filter = (char *) strndup(value, OPH_TP_TASKLEN))) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Error allocating memory\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_MEMORY_ERROR_INPUT, "name_filter");
		return OPH_ANALYTICS_OPERATOR_MEMORY_ERR;
	}

	value = hashtbl_get(task_tbl, OPH_IN_PARAM_LIMIT_FILTER);
	if (!value) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_LIMIT_FILTER);
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_MISSING_INPUT_PARAMETER, "NO-CONTAINER", OPH_IN_PARAM_LIMIT_FILTER);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}
	((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->limit = (int) strtol(value, NULL, 10);
	if (((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->limit < 0) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Limit must be positive\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_BAD_LIMIT, OPH_IN_PARAM_LIMIT_FILTER);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}

	value = hashtbl_get(task_tbl, OPH_IN_PARAM_VISUALIZZATION_LEVEL);
	if (!value) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_VISUALIZZATION_LEVEL);
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_MISSING_INPUT_PARAMETER, "NO-CONTAINER", OPH_IN_PARAM_VISUALIZZATION_LEVEL);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}
	((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->level = (int) strtol(value, NULL, 10);
	if (((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->level < 1 || ((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->level > 5) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "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;
	}

	value = hashtbl_get(task_tbl, OPH_IN_PARAM_DBMS_ID_FILTER);
	if (!value) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_DBMS_ID_FILTER);
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_MISSING_INPUT_PARAMETER, "NO-CONTAINER", OPH_IN_PARAM_DBMS_ID_FILTER);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}
	if (strcmp(value, OPH_COMMON_DEFAULT_EMPTY_VALUE) == 0) {
		((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->id_dbms = 0;
	} else {
		((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->id_dbms = (int) strtol(value, NULL, 10);
		if (((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->id_dbms < 1) {
			pmesg(LOG_ERROR, __FILE__, __LINE__, "id of dbms must be positive\n");
			logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_BAD_LIMIT, OPH_IN_PARAM_DBMS_ID_FILTER);
			return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
		}
	}

	value = hashtbl_get(task_tbl, OPH_IN_PARAM_PRIMITIVE_RETURN_TYPE_FILTER);
	if (!value) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_PRIMITIVE_RETURN_TYPE_FILTER);
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_MISSING_INPUT_PARAMETER, "NO-CONTAINER", OPH_IN_PARAM_PRIMITIVE_RETURN_TYPE_FILTER);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}
	if (strcmp(value, OPH_COMMON_ALL_FILTER) != 0) {
		if (!(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->func_ret = (char *) strndup(value, OPH_TP_TASKLEN))) {
			pmesg(LOG_ERROR, __FILE__, __LINE__, "Error allocating memory\n");
			logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_MEMORY_ERROR_INPUT, "func_ret");
			return OPH_ANALYTICS_OPERATOR_MEMORY_ERR;
		}
	}

	value = hashtbl_get(task_tbl, OPH_IN_PARAM_PRIMITIVE_TYPE_FILTER);
	if (!value) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_PRIMITIVE_TYPE_FILTER);
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_MISSING_INPUT_PARAMETER, "NO-CONTAINER", OPH_IN_PARAM_PRIMITIVE_TYPE_FILTER);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}
	if (strcmp(value, OPH_COMMON_ALL_FILTER) != 0) {
		if (!(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->func_type = (char *) strndup(value, OPH_TP_TASKLEN))) {
			pmesg(LOG_ERROR, __FILE__, __LINE__, "Error allocating memory\n");
			logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_MEMORY_ERROR_INPUT, "func_type");
			return OPH_ANALYTICS_OPERATOR_MEMORY_ERR;
		}
	}

	return OPH_ANALYTICS_OPERATOR_SUCCESS;
}
int env_set(HASHTBL * task_tbl, oph_operator_struct * handle)
{
	if (!handle) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Null Handle\n");
		return OPH_ANALYTICS_OPERATOR_NULL_OPERATOR_HANDLE;
	}

	if (!task_tbl) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Null operator string\n");
		return OPH_ANALYTICS_OPERATOR_BAD_PARAMETER;
	}

	if (handle->operator_handle) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Operator handle already initialized\n");
		return OPH_ANALYTICS_OPERATOR_NOT_NULL_OPERATOR_HANDLE;
	}

	if (!(handle->operator_handle = (OPH_UNPUBLISH_operator_handle *) calloc(1, sizeof(OPH_UNPUBLISH_operator_handle)))) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Error allocating memory\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_UNPUBLISH_MEMORY_ERROR_HANDLE);
		return OPH_ANALYTICS_OPERATOR_MEMORY_ERR;
	}
	//1 - Set up struct to empty values
	((OPH_UNPUBLISH_operator_handle *) handle->operator_handle)->datacube_path = NULL;
	((OPH_UNPUBLISH_operator_handle *) handle->operator_handle)->objkeys = NULL;
	((OPH_UNPUBLISH_operator_handle *) handle->operator_handle)->objkeys_num = -1;
	((OPH_UNPUBLISH_operator_handle *) handle->operator_handle)->sessionid = NULL;

	//Only master process has to continue
	if (handle->proc_rank != 0)
		return OPH_ANALYTICS_OPERATOR_SUCCESS;

	ophidiadb *oDB = &((OPH_UNPUBLISH_operator_handle *) handle->operator_handle)->oDB;
	oph_odb_init_ophidiadb(oDB);

	char *datacube_name;
	int id_container = 0;
	char *value;

	// retrieve objkeys
	value = hashtbl_get(task_tbl, OPH_IN_PARAM_OBJKEY_FILTER);
	if (!value) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_OBJKEY_FILTER);
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_FRAMEWORK_MISSING_INPUT_PARAMETER, OPH_IN_PARAM_OBJKEY_FILTER);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}
	if (oph_tp_parse_multiple_value_param(value, &((OPH_UNPUBLISH_operator_handle *) handle->operator_handle)->objkeys, &((OPH_UNPUBLISH_operator_handle *) handle->operator_handle)->objkeys_num)) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Operator string not valid\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, "Operator string not valid\n");
		oph_tp_free_multiple_value_param_list(((OPH_UNPUBLISH_operator_handle *) handle->operator_handle)->objkeys, ((OPH_UNPUBLISH_operator_handle *) handle->operator_handle)->objkeys_num);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}
	// retrieve sessionid
	value = hashtbl_get(task_tbl, OPH_ARG_SESSIONID);
	if (!value) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_ARG_SESSIONID);
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_FRAMEWORK_MISSING_INPUT_PARAMETER, OPH_ARG_SESSIONID);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}
	if (!(((OPH_UNPUBLISH_operator_handle *) handle->operator_handle)->sessionid = (char *) strndup(value, OPH_TP_TASKLEN))) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Error allocating memory\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_GENERIC_MEMORY_ERROR_INPUT, "sessionid");
		return OPH_ANALYTICS_OPERATOR_MEMORY_ERR;
	}
	//3 - Fill struct with the correct data
	char *tmp_username = NULL;
	value = hashtbl_get(task_tbl, OPH_ARG_USERNAME);
	if (!value) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_ARG_USERNAME);
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_UNPUBLISH_MISSING_INPUT_PARAMETER, OPH_ARG_USERNAME);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}
	if (!(tmp_username = (char *) strndup(value, OPH_TP_TASKLEN))) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Error allocating memory\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_UNPUBLISH_MEMORY_ERROR_INPUT, OPH_ARG_USERNAME);
		return OPH_ANALYTICS_OPERATOR_MEMORY_ERR;
	}

	value = hashtbl_get(task_tbl, OPH_IN_PARAM_DATACUBE_INPUT);
	datacube_name = value;
	if (!value) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_DATACUBE_INPUT);
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_UNPUBLISH_MISSING_INPUT_PARAMETER, OPH_IN_PARAM_DATACUBE_INPUT);
		free(tmp_username);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}

	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_UNPUBLISH_OPHIDIADB_CONFIGURATION_FILE);
		free(tmp_username);
		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_UNPUBLISH_OPHIDIADB_CONNECTION_ERROR);
		free(tmp_username);
		return OPH_ANALYTICS_OPERATOR_MYSQL_ERROR;
	}

	int id_datacube = 0;

	//Check if datacube exists (by ID container and datacube)
	int exists = 0;
	char *uri = NULL;
	int folder_id = 0;
	int permission = 0;
	if (oph_pid_parse_pid(value, &id_container, &id_datacube, &uri)) {
		if (uri)
			free(uri);
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to parse the PID string\n");
		logging(LOG_ERROR, __FILE__, __LINE__, id_container, OPH_LOG_OPH_UNPUBLISH_PID_ERROR, datacube_name);
		free(tmp_username);
		return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
	}
	if ((oph_odb_cube_check_if_datacube_not_present_by_pid(oDB, uri, id_container, id_datacube, &exists)) || !exists) {
		free(uri);
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Unknown input container - datacube combination\n");
		logging(LOG_ERROR, __FILE__, __LINE__, id_container, OPH_LOG_OPH_UNPUBLISH_NO_INPUT_DATACUBE, datacube_name);
		free(tmp_username);
		return OPH_ANALYTICS_OPERATOR_MYSQL_ERROR;
	}
	if ((oph_odb_fs_retrive_container_folder_id(oDB, id_container, 1, &folder_id))) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to retrieve folder of specified datacube or container is hidden\n");
		logging(LOG_ERROR, __FILE__, __LINE__, id_container, OPH_LOG_OPH_UNPUBLISH_DATACUBE_FOLDER_ERROR, datacube_name);
		free(uri);
		free(tmp_username);
		return OPH_ANALYTICS_OPERATOR_MYSQL_ERROR;
	}
	if ((oph_odb_fs_check_folder_session(folder_id, ((OPH_UNPUBLISH_operator_handle *) handle->operator_handle)->sessionid, oDB, &permission)) || !permission) {
		//Check if user can work on datacube
		pmesg(LOG_ERROR, __FILE__, __LINE__, "User %s is not allowed to work on this datacube\n", tmp_username);
		logging(LOG_ERROR, __FILE__, __LINE__, id_container, OPH_LOG_OPH_UNPUBLISH_DATACUBE_PERMISSION_ERROR, tmp_username);
		free(uri);
		free(tmp_username);
		return OPH_ANALYTICS_OPERATOR_MYSQL_ERROR;
	}
	free(tmp_username);
	free(uri);
	((OPH_UNPUBLISH_operator_handle *) handle->operator_handle)->id_input_container = id_container;

	char session_code[OPH_COMMON_BUFFER_LEN];
	oph_pid_get_session_code(hashtbl_get(task_tbl, OPH_ARG_SESSIONID), session_code);
	int n = snprintf(NULL, 0, OPH_FRAMEWORK_HTML_FILES_PATH, oph_pid_path()? oph_pid_path() : OPH_PREFIX_CLUSTER, session_code,
			 ((OPH_UNPUBLISH_operator_handle *) handle->operator_handle)->id_input_container, id_datacube) + 1;
	if (n >= OPH_TP_TASKLEN) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Size of path exceeded limit.\n");
		logging(LOG_ERROR, __FILE__, __LINE__, ((OPH_UNPUBLISH_operator_handle *) handle->operator_handle)->id_input_container, OPH_LOG_OPH_UNPUBLISH_STRING_BUFFER_OVERFLOW, "path",
			OPH_FRAMEWORK_HTML_FILES_PATH);
		return OPH_ANALYTICS_OPERATOR_MEMORY_ERR;
	}
	if (!(((OPH_UNPUBLISH_operator_handle *) handle->operator_handle)->datacube_path = (char *) malloc(n * sizeof(char)))) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Error allocating memory\n");
		logging(LOG_ERROR, __FILE__, __LINE__, ((OPH_UNPUBLISH_operator_handle *) handle->operator_handle)->id_input_container, OPH_LOG_OPH_UNPUBLISH_MEMORY_ERROR_INPUT, "datacube path");
		return OPH_ANALYTICS_OPERATOR_MEMORY_ERR;
	}
	snprintf(((OPH_UNPUBLISH_operator_handle *) handle->operator_handle)->datacube_path, n, OPH_FRAMEWORK_HTML_FILES_PATH, oph_pid_path()? oph_pid_path() : OPH_PREFIX_CLUSTER, session_code,
		 ((OPH_UNPUBLISH_operator_handle *) handle->operator_handle)->id_input_container, id_datacube);

	return OPH_ANALYTICS_OPERATOR_SUCCESS;
}
int env_set(HASHTBL * task_tbl, oph_operator_struct * handle)
{
	if (!handle) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Null Handle\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_SEARCH_NULL_OPERATOR_HANDLE);
		return OPH_ANALYTICS_OPERATOR_NULL_OPERATOR_HANDLE;
	}

	if (!task_tbl) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Null operator string\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_SEARCH_NULL_TASK_TABLE);
		return OPH_ANALYTICS_OPERATOR_BAD_PARAMETER;
	}

	if (handle->operator_handle) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Operator handle already initialized\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_SEARCH_HANDLE_ALREADY_INITIALIZED);
		return OPH_ANALYTICS_OPERATOR_NOT_NULL_OPERATOR_HANDLE;
	}

	if (!(handle->operator_handle = (OPH_SEARCH_operator_handle *) calloc(1, sizeof(OPH_SEARCH_operator_handle)))) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Error allocating memory\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_SEARCH_MEMORY_ERROR_HANDLE);
		return OPH_ANALYTICS_OPERATOR_MEMORY_ERR;
	}
	//1 - Set up struct to empty values
	((OPH_SEARCH_operator_handle *) handle->operator_handle)->container_filter = NULL;
	((OPH_SEARCH_operator_handle *) handle->operator_handle)->container_filter_num = 0;
	((OPH_SEARCH_operator_handle *) handle->operator_handle)->cwd = NULL;
	((OPH_SEARCH_operator_handle *) handle->operator_handle)->metadata_key_filter = NULL;
	((OPH_SEARCH_operator_handle *) handle->operator_handle)->metadata_key_filter_num = 0;
	((OPH_SEARCH_operator_handle *) handle->operator_handle)->metadata_value_filter = NULL;
	((OPH_SEARCH_operator_handle *) handle->operator_handle)->metadata_value_filter_num = 0;
	((OPH_SEARCH_operator_handle *) handle->operator_handle)->path = NULL;
	((OPH_SEARCH_operator_handle *) handle->operator_handle)->user = NULL;
	((OPH_SEARCH_operator_handle *) handle->operator_handle)->objkeys = NULL;
	((OPH_SEARCH_operator_handle *) handle->operator_handle)->objkeys_num = -1;
	((OPH_SEARCH_operator_handle *) handle->operator_handle)->sessionid = NULL;

	ophidiadb *oDB = &((OPH_SEARCH_operator_handle *) handle->operator_handle)->oDB;

	//Only master process has to continue
	if (handle->proc_rank != 0)
		return OPH_ANALYTICS_OPERATOR_SUCCESS;

	oph_odb_init_ophidiadb(oDB);

	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_SEARCH_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_SEARCH_OPHIDIADB_CONNECTION_ERROR_NO_CONTAINER);
		return OPH_ANALYTICS_OPERATOR_MYSQL_ERROR;
	}
	//3 - Fill struct with the correct data

	char *value;

	// retrieve objkeys
	value = hashtbl_get(task_tbl, OPH_IN_PARAM_OBJKEY_FILTER);
	if (!value) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_OBJKEY_FILTER);
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_FRAMEWORK_MISSING_INPUT_PARAMETER, OPH_IN_PARAM_OBJKEY_FILTER);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}
	if (oph_tp_parse_multiple_value_param(value, &((OPH_SEARCH_operator_handle *) handle->operator_handle)->objkeys, &((OPH_SEARCH_operator_handle *) handle->operator_handle)->objkeys_num)) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Operator string not valid\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, "Operator string not valid\n");
		oph_tp_free_multiple_value_param_list(((OPH_SEARCH_operator_handle *) handle->operator_handle)->objkeys, ((OPH_SEARCH_operator_handle *) handle->operator_handle)->objkeys_num);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}
	// retrieve sessionid
	value = hashtbl_get(task_tbl, OPH_ARG_SESSIONID);
	if (!value) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_ARG_SESSIONID);
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_FRAMEWORK_MISSING_INPUT_PARAMETER, OPH_ARG_SESSIONID);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}
	if (!(((OPH_SEARCH_operator_handle *) handle->operator_handle)->sessionid = (char *) strndup(value, OPH_TP_TASKLEN))) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Error allocating memory\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_GENERIC_MEMORY_ERROR_INPUT, "sessionid");
		return OPH_ANALYTICS_OPERATOR_MEMORY_ERR;
	}

	value = hashtbl_get(task_tbl, OPH_IN_PARAM_PATH);
	if (!value) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_PATH);
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_SEARCH_MISSING_INPUT_PARAMETER, OPH_IN_PARAM_PATH);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}
	if (!(((OPH_SEARCH_operator_handle *) handle->operator_handle)->path = (char *) strdup(value))) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Error allocating memory\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_SEARCH_MEMORY_ERROR_INPUT, OPH_IN_PARAM_PATH);
		return OPH_ANALYTICS_OPERATOR_MEMORY_ERR;
	}

	value = hashtbl_get(task_tbl, OPH_IN_PARAM_CWD);
	if (!value) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_CWD);
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_SEARCH_MISSING_INPUT_PARAMETER, OPH_IN_PARAM_CWD);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}
	if (!(((OPH_SEARCH_operator_handle *) handle->operator_handle)->cwd = (char *) strdup(value))) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Error allocating memory\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_SEARCH_MEMORY_ERROR_INPUT, OPH_IN_PARAM_CWD);
		return OPH_ANALYTICS_OPERATOR_MEMORY_ERR;
	}

	value = hashtbl_get(task_tbl, OPH_IN_PARAM_CONTAINER_NAME_FILTER);
	if (!value) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_CONTAINER_NAME_FILTER);
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_SEARCH_MISSING_INPUT_PARAMETER, OPH_IN_PARAM_CONTAINER_NAME_FILTER);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}
	if (oph_tp_parse_multiple_value_param
	    (value, &((OPH_SEARCH_operator_handle *) handle->operator_handle)->container_filter, &((OPH_SEARCH_operator_handle *) handle->operator_handle)->container_filter_num)) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Operator string not valid\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_SEARCH_INVALID_INPUT_STRING);
		oph_tp_free_multiple_value_param_list(((OPH_SEARCH_operator_handle *) handle->operator_handle)->container_filter,
						      ((OPH_SEARCH_operator_handle *) handle->operator_handle)->container_filter_num);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}

	value = hashtbl_get(task_tbl, OPH_IN_PARAM_METADATA_KEY_FILTER);
	if (!value) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_METADATA_KEY_FILTER);
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_SEARCH_MISSING_INPUT_PARAMETER, OPH_IN_PARAM_METADATA_KEY_FILTER);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}
	if (oph_tp_parse_multiple_value_param
	    (value, &((OPH_SEARCH_operator_handle *) handle->operator_handle)->metadata_key_filter, &((OPH_SEARCH_operator_handle *) handle->operator_handle)->metadata_key_filter_num)) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Operator string not valid\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_SEARCH_INVALID_INPUT_STRING);
		oph_tp_free_multiple_value_param_list(((OPH_SEARCH_operator_handle *) handle->operator_handle)->metadata_key_filter,
						      ((OPH_SEARCH_operator_handle *) handle->operator_handle)->metadata_key_filter_num);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}

	value = hashtbl_get(task_tbl, OPH_IN_PARAM_METADATA_VALUE_FILTER);
	if (!value) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_METADATA_VALUE_FILTER);
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_SEARCH_MISSING_INPUT_PARAMETER, OPH_IN_PARAM_METADATA_VALUE_FILTER);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}
	if (oph_tp_parse_multiple_value_param
	    (value, &((OPH_SEARCH_operator_handle *) handle->operator_handle)->metadata_value_filter, &((OPH_SEARCH_operator_handle *) handle->operator_handle)->metadata_value_filter_num)) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Operator string not valid\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_SEARCH_INVALID_INPUT_STRING);
		oph_tp_free_multiple_value_param_list(((OPH_SEARCH_operator_handle *) handle->operator_handle)->metadata_value_filter,
						      ((OPH_SEARCH_operator_handle *) handle->operator_handle)->metadata_value_filter_num);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}
	int i;
	for (i = 0; i < ((OPH_SEARCH_operator_handle *) handle->operator_handle)->metadata_value_filter_num; ++i)
		if (strstr(((OPH_SEARCH_operator_handle *) handle->operator_handle)->metadata_value_filter[i], OPH_SEARCH_AND_SEPARATOR)) {
			pmesg(LOG_ERROR, __FILE__, __LINE__, "Separator '%s' cannot be used in filter for values: use it in filter for keys as 'AND'\n", OPH_SEARCH_AND_SEPARATOR);
			logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, "Separator '%s' cannot be used in filter for values: use it in filter for keys as 'AND'\n",
				OPH_SEARCH_AND_SEPARATOR);
			return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
		}

	value = hashtbl_get(task_tbl, OPH_ARG_USERNAME);
	if (!value) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_ARG_USERNAME);
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_SEARCH_MISSING_INPUT_PARAMETER, OPH_ARG_USERNAME);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}
	if (!(((OPH_SEARCH_operator_handle *) handle->operator_handle)->user = (char *) strdup(value))) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Error allocating memory\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_SEARCH_MEMORY_ERROR_INPUT, OPH_ARG_USERNAME);
		return OPH_ANALYTICS_OPERATOR_MEMORY_ERR;
	}

	return OPH_ANALYTICS_OPERATOR_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_SPLIT_operator_handle *) handle->operator_handle)->id_input_container, OPH_LOG_OPH_SPLIT_NULL_OPERATOR_HANDLE);
		return OPH_ANALYTICS_OPERATOR_NULL_OPERATOR_HANDLE;
	}

	if (((OPH_SPLIT_operator_handle *) handle->operator_handle)->fragment_id_start_position < 0 && handle->proc_rank != 0)
		return OPH_ANALYTICS_OPERATOR_SUCCESS;

	((OPH_SPLIT_operator_handle *) handle->operator_handle)->execute_error = 1;

	int i, j, k, l;

	int id_datacube_out = ((OPH_SPLIT_operator_handle *) handle->operator_handle)->id_output_datacube;
	int id_datacube_in = ((OPH_SPLIT_operator_handle *) handle->operator_handle)->id_input_datacube;

	oph_odb_fragment_list frags;
	oph_odb_db_instance_list dbs;
	oph_odb_dbms_instance_list dbmss;

	//Each process has to be connected to a slave ophidiadb
	ophidiadb oDB_slave;
	oph_odb_init_ophidiadb(&oDB_slave);

	if (oph_odb_read_ophidiadb_config_file(&oDB_slave)) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to read OphidiaDB configuration\n");
		logging(LOG_ERROR, __FILE__, __LINE__, ((OPH_SPLIT_operator_handle *) handle->operator_handle)->id_input_container, OPH_LOG_OPH_SPLIT_OPHIDIADB_CONFIGURATION_FILE);
		return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
	}

	if (oph_odb_connect_to_ophidiadb(&oDB_slave)) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to connect to OphidiaDB. Check access parameters.\n");
		logging(LOG_ERROR, __FILE__, __LINE__, ((OPH_SPLIT_operator_handle *) handle->operator_handle)->id_input_container, OPH_LOG_OPH_SPLIT_OPHIDIADB_CONNECTION_ERROR);
		oph_odb_free_ophidiadb(&oDB_slave);
		return OPH_ANALYTICS_OPERATOR_MYSQL_ERROR;
	}
	//retrieve connection string
	if (oph_odb_stge_fetch_fragment_connection_string(&oDB_slave, id_datacube_in, ((OPH_SPLIT_operator_handle *) handle->operator_handle)->fragment_ids, &frags, &dbs, &dbmss)) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to retreive connection strings\n");
		logging(LOG_ERROR, __FILE__, __LINE__, ((OPH_SPLIT_operator_handle *) handle->operator_handle)->id_input_container, OPH_LOG_OPH_SPLIT_CONNECTION_STRINGS_NOT_FOUND);
		oph_odb_free_ophidiadb(&oDB_slave);
		return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
	}
	//char insertQuery[OPH_COMMON_BUFFER_LEN];
	char frag_name_in[1 + OPH_ODB_STGE_FRAG_NAME_SIZE], frag_name_out[OPH_ODB_STGE_FRAG_NAME_SIZE];
	char myquery[OPH_COMMON_BUFFER_LEN];
	int n, txfrag;

	int frag_count = 0;
	int tuple_count = 0;
	int start_index, key_start, tuplexfragment, new_tuplexfragment, new_remainder;
	int result = OPH_ANALYTICS_OPERATOR_SUCCESS;


	if (oph_dc_setup_dbms(&(((OPH_SPLIT_operator_handle *) handle->operator_handle)->server), (dbmss.value[0]).io_server_type)) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to initialize IO server.\n");
		logging(LOG_ERROR, __FILE__, __LINE__, ((OPH_SPLIT_operator_handle *) handle->operator_handle)->id_input_container, OPH_LOG_OPH_SPLIT_IOPLUGIN_SETUP_ERROR, (dbmss.value[0]).id_dbms);
		result = OPH_ANALYTICS_OPERATOR_MYSQL_ERROR;
	}
	//For each DBMS
	for (i = 0; (i < dbmss.size) && (result == OPH_ANALYTICS_OPERATOR_SUCCESS); i++) {

		if (oph_dc_connect_to_dbms(((OPH_SPLIT_operator_handle *) handle->operator_handle)->server, &(dbmss.value[i]), 0)) {
			pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to connect to DBMS. Check access parameters.\n");
			logging(LOG_ERROR, __FILE__, __LINE__, ((OPH_SPLIT_operator_handle *) handle->operator_handle)->id_input_container, OPH_LOG_OPH_SPLIT_DBMS_CONNECTION_ERROR, "output",
				(dbmss.value[i]).id_dbms);
			result = OPH_ANALYTICS_OPERATOR_MYSQL_ERROR;
		}
		//For each DB
		for (j = 0; (j < dbs.size) && (result == OPH_ANALYTICS_OPERATOR_SUCCESS); j++) {
			//Check DB - DBMS Association
			if (dbs.value[j].dbms_instance != &(dbmss.value[i]))
				continue;

			if (oph_dc_use_db_of_dbms(((OPH_SPLIT_operator_handle *) handle->operator_handle)->server, &(dbmss.value[i]), &(dbs.value[j]))) {
				pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to use the DB. Check access parameters.\n");
				logging(LOG_ERROR, __FILE__, __LINE__, ((OPH_SPLIT_operator_handle *) handle->operator_handle)->id_input_container, OPH_LOG_OPH_SPLIT_DB_SELECTION_ERROR, "output",
					(dbs.value[j]).db_name);
				result = OPH_ANALYTICS_OPERATOR_MYSQL_ERROR;
				break;
			}
			//For each fragment
			for (k = 0; (k < frags.size) && (result == OPH_ANALYTICS_OPERATOR_SUCCESS); k++) {
				//Check Fragment - DB Association
				if (frags.value[k].db_instance != &(dbs.value[j]))
					continue;

				//Store the name of fragment I'm going to split
				strncpy(frag_name_in, frags.value[k].fragment_name, OPH_ODB_STGE_FRAG_NAME_SIZE);
				frag_name_in[OPH_ODB_STGE_FRAG_NAME_SIZE] = 0;
				tuple_count = 0;

				start_index = frags.value[k].frag_relative_index;
				key_start = frags.value[k].key_start;
				if (key_start) {
					tuplexfragment = frags.value[k].key_end - key_start + 1;
					new_tuplexfragment = tuplexfragment / ((OPH_SPLIT_operator_handle *) handle->operator_handle)->split_number;
					new_remainder = tuplexfragment % ((OPH_SPLIT_operator_handle *) handle->operator_handle)->split_number;
				} else
					new_tuplexfragment = new_remainder = 0;

				for (l = 0; (l < ((OPH_SPLIT_operator_handle *) handle->operator_handle)->split_number) && (result == OPH_ANALYTICS_OPERATOR_SUCCESS); l++) {

					if (oph_dc_generate_fragment_name(NULL, id_datacube_out, handle->proc_rank, (frag_count + 1), &frag_name_out)) {
						pmesg(LOG_ERROR, __FILE__, __LINE__, "Size of frag  name exceed limit.\n");
						logging(LOG_ERROR, __FILE__, __LINE__, ((OPH_SPLIT_operator_handle *) handle->operator_handle)->id_input_container,
							OPH_LOG_OPH_SPLIT_STRING_BUFFER_OVERFLOW, "fragment name", frag_name_out);
						result = OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
						break;
					}
					//Write new fragment
					//Check if I have to add one more tuple in fragment
					if ((((OPH_SPLIT_operator_handle *) handle->operator_handle)->split_number - new_remainder) <= l)
						txfrag = new_tuplexfragment + 1;
					else
						txfrag = new_tuplexfragment;
#ifdef OPH_DEBUG_MYSQL
					printf("ORIGINAL QUERY: " OPH_SPLIT_QUERY_MYSQL "\n", frag_name_out, MYSQL_FRAG_ID, MYSQL_FRAG_MEASURE, MYSQL_FRAG_ID, MYSQL_FRAG_MEASURE, frag_name_in,
					       MYSQL_FRAG_ID, tuple_count, txfrag);
#endif

					n = snprintf(myquery, OPH_COMMON_BUFFER_LEN, OPH_SPLIT_QUERY, frag_name_out, MYSQL_FRAG_ID, MYSQL_FRAG_MEASURE, frag_name_in, MYSQL_FRAG_ID, tuple_count,
						     txfrag);
					if (n >= OPH_COMMON_BUFFER_LEN) {
						pmesg(LOG_ERROR, __FILE__, __LINE__, "Size of frag  name exceed limit.\n");
						logging(LOG_ERROR, __FILE__, __LINE__, ((OPH_SPLIT_operator_handle *) handle->operator_handle)->id_input_container,
							OPH_LOG_OPH_SPLIT_STRING_BUFFER_OVERFLOW, "MySQL operation name", myquery);
						result = OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
						break;
					}
					if (oph_dc_create_fragment_from_query(((OPH_SPLIT_operator_handle *) handle->operator_handle)->server, &(frags.value[k]), NULL, myquery, 0, 0, 0)) {
						pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to insert new fragment.\n");
						logging(LOG_ERROR, __FILE__, __LINE__, ((OPH_SPLIT_operator_handle *) handle->operator_handle)->id_input_container, OPH_LOG_OPH_SPLIT_NEW_FRAG_ERROR,
							frag_name_out);
						result = OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
						break;
					}
					//Change fragment fields
					frags.value[k].id_datacube = id_datacube_out;
					strncpy(frags.value[k].fragment_name, frag_name_out, OPH_ODB_STGE_FRAG_NAME_SIZE);
					frags.value[k].fragment_name[OPH_ODB_STGE_FRAG_NAME_SIZE] = 0;
					frags.value[k].frag_relative_index = (start_index - 1) * ((OPH_SPLIT_operator_handle *) handle->operator_handle)->split_number + l + 1;
					if (key_start) {
						if (l)
							frags.value[k].key_start = key_start + tuple_count;
						frags.value[k].key_end = key_start + tuple_count + txfrag - 1;
					}
					//Insert new fragment
					if (oph_odb_stge_insert_into_fragment_table(&oDB_slave, &(frags.value[k]))) {
						pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to update fragment table.\n");
						logging(LOG_ERROR, __FILE__, __LINE__, ((OPH_SPLIT_operator_handle *) handle->operator_handle)->id_input_container,
							OPH_LOG_OPH_SPLIT_FRAGMENT_INSERT_ERROR, frag_name_out);
						result = OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
						break;
					}
					frag_count++;
					tuple_count += txfrag;
				}
			}
		}
		oph_dc_disconnect_from_dbms(((OPH_SPLIT_operator_handle *) handle->operator_handle)->server, &(dbmss.value[i]));
	}

	if (oph_dc_cleanup_dbms(((OPH_SPLIT_operator_handle *) handle->operator_handle)->server)) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to finalize IO server.\n");
		logging(LOG_ERROR, __FILE__, __LINE__, ((OPH_SPLIT_operator_handle *) handle->operator_handle)->id_input_container, OPH_LOG_OPH_SPLIT_IOPLUGIN_CLEANUP_ERROR, (dbmss.value[0]).id_dbms);
		result = OPH_ANALYTICS_OPERATOR_MYSQL_ERROR;
	}

	oph_odb_free_ophidiadb(&oDB_slave);
	oph_odb_stge_free_fragment_list(&frags);
	oph_odb_stge_free_db_list(&dbs);
	oph_odb_stge_free_dbms_list(&dbmss);

	if (handle->proc_rank == 0 && (result == OPH_ANALYTICS_OPERATOR_SUCCESS)) {
		//Master process print output datacube PID
		char *tmp_uri = NULL;
		if (oph_pid_get_uri(&tmp_uri)) {
			pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to retrieve web server URI.\n");
			logging(LOG_WARNING, __FILE__, __LINE__, ((OPH_SPLIT_operator_handle *) handle->operator_handle)->id_input_container, OPH_LOG_OPH_SPLIT_PID_URI_ERROR);
			return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
		}
		if (oph_pid_show_pid
		    (((OPH_SPLIT_operator_handle *) handle->operator_handle)->id_output_container, ((OPH_SPLIT_operator_handle *) handle->operator_handle)->id_output_datacube, tmp_uri)) {
			pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to print PID string\n");
			logging(LOG_WARNING, __FILE__, __LINE__, ((OPH_SPLIT_operator_handle *) handle->operator_handle)->id_input_container, OPH_LOG_OPH_SPLIT_PID_SHOW_ERROR);
			free(tmp_uri);
			return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
		}

		char jsonbuf[OPH_COMMON_BUFFER_LEN];
		memset(jsonbuf, 0, OPH_COMMON_BUFFER_LEN);
		snprintf(jsonbuf, OPH_COMMON_BUFFER_LEN, OPH_PID_FORMAT, tmp_uri, ((OPH_SPLIT_operator_handle *) handle->operator_handle)->id_output_container,
			 ((OPH_SPLIT_operator_handle *) handle->operator_handle)->id_output_datacube);

		// ADD OUTPUT PID TO JSON AS TEXT
		if (oph_json_is_objkey_printable
		    (((OPH_SPLIT_operator_handle *) handle->operator_handle)->objkeys, ((OPH_SPLIT_operator_handle *) handle->operator_handle)->objkeys_num, OPH_JSON_OBJKEY_SPLIT)) {
			if (oph_json_add_text(handle->operator_json, OPH_JSON_OBJKEY_SPLIT, "Output Cube", jsonbuf)) {
				pmesg(LOG_ERROR, __FILE__, __LINE__, "ADD TEXT error\n");
				logging(LOG_WARNING, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, "ADD TEXT error\n");
				free(tmp_uri);
				return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
			}
		}
		// ADD OUTPUT PID TO NOTIFICATION STRING
		char tmp_string[OPH_COMMON_BUFFER_LEN];
		snprintf(tmp_string, OPH_COMMON_BUFFER_LEN, "%s=%s;", OPH_IN_PARAM_DATACUBE_INPUT, jsonbuf);
		if (handle->output_string) {
			strncat(tmp_string, handle->output_string, OPH_COMMON_BUFFER_LEN - strlen(tmp_string));
			free(handle->output_string);
		}
		handle->output_string = strdup(tmp_string);

		free(tmp_uri);
	}

	if (result == OPH_ANALYTICS_OPERATOR_SUCCESS)
		((OPH_SPLIT_operator_handle *) handle->operator_handle)->execute_error = 0;

	return result;
}
int env_set(HASHTBL * task_tbl, oph_operator_struct * handle)
{
	if (!handle) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Null Handle\n");
		return OPH_ANALYTICS_OPERATOR_NULL_OPERATOR_HANDLE;
	}

	if (!task_tbl) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Null operator string\n");
		return OPH_ANALYTICS_OPERATOR_BAD_PARAMETER;
	}

	if (handle->operator_handle) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Operator handle already initialized\n");
		return OPH_ANALYTICS_OPERATOR_NOT_NULL_OPERATOR_HANDLE;
	}

	if (!(handle->operator_handle = (OPH_SPLIT_operator_handle *) calloc(1, sizeof(OPH_SPLIT_operator_handle)))) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Error allocating memory\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_SPLIT_MEMORY_ERROR_HANDLE);
		return OPH_ANALYTICS_OPERATOR_MEMORY_ERR;
	}
	//1 - Set up struct to empty values
	((OPH_SPLIT_operator_handle *) handle->operator_handle)->id_input_datacube = 0;
	((OPH_SPLIT_operator_handle *) handle->operator_handle)->id_output_datacube = 0;
	((OPH_SPLIT_operator_handle *) handle->operator_handle)->id_input_container = 0;
	((OPH_SPLIT_operator_handle *) handle->operator_handle)->id_output_container = 0;
	((OPH_SPLIT_operator_handle *) handle->operator_handle)->id_job = 0;
	((OPH_SPLIT_operator_handle *) handle->operator_handle)->fragment_ids = NULL;
	((OPH_SPLIT_operator_handle *) handle->operator_handle)->objkeys = NULL;
	((OPH_SPLIT_operator_handle *) handle->operator_handle)->objkeys_num = -1;
	((OPH_SPLIT_operator_handle *) handle->operator_handle)->server = NULL;
	((OPH_SPLIT_operator_handle *) handle->operator_handle)->sessionid = NULL;
	((OPH_SPLIT_operator_handle *) handle->operator_handle)->id_user = 0;
	((OPH_SPLIT_operator_handle *) handle->operator_handle)->description = NULL;
	((OPH_SPLIT_operator_handle *) handle->operator_handle)->execute_error = 0;

	char *datacube_in;
	char *value;

	// retrieve objkeys
	value = hashtbl_get(task_tbl, OPH_IN_PARAM_OBJKEY_FILTER);
	if (!value) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_OBJKEY_FILTER);
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_FRAMEWORK_MISSING_INPUT_PARAMETER, OPH_IN_PARAM_OBJKEY_FILTER);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}
	if (oph_tp_parse_multiple_value_param(value, &((OPH_SPLIT_operator_handle *) handle->operator_handle)->objkeys, &((OPH_SPLIT_operator_handle *) handle->operator_handle)->objkeys_num)) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Operator string not valid\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, "Operator string not valid\n");
		oph_tp_free_multiple_value_param_list(((OPH_SPLIT_operator_handle *) handle->operator_handle)->objkeys, ((OPH_SPLIT_operator_handle *) handle->operator_handle)->objkeys_num);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}
	// retrieve sessionid
	value = hashtbl_get(task_tbl, OPH_ARG_SESSIONID);
	if (!value) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_ARG_SESSIONID);
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_FRAMEWORK_MISSING_INPUT_PARAMETER, OPH_ARG_SESSIONID);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}
	if (!(((OPH_SPLIT_operator_handle *) handle->operator_handle)->sessionid = (char *) strndup(value, OPH_TP_TASKLEN))) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Error allocating memory\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_GENERIC_MEMORY_ERROR_INPUT, "sessionid");
		return OPH_ANALYTICS_OPERATOR_MEMORY_ERR;
	}
	//3 - Fill struct with the correct data
	value = hashtbl_get(task_tbl, OPH_IN_PARAM_DATACUBE_INPUT);
	datacube_in = value;
	if (!value) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_DATACUBE_INPUT);
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_SPLIT_MISSING_INPUT_PARAMETER, OPH_IN_PARAM_DATACUBE_INPUT);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}
	//For error checking
	int id_datacube_in[3] = { 0, 0, 0 };

	value = hashtbl_get(task_tbl, OPH_ARG_USERNAME);
	if (!value) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_ARG_USERNAME);
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_SPLIT_MISSING_INPUT_PARAMETER, OPH_ARG_USERNAME);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}
	char *username = value;

	if (handle->proc_rank == 0) {
		//Only master process has to initialize and open connection to management OphidiaDB
		ophidiadb *oDB = &((OPH_SPLIT_operator_handle *) handle->operator_handle)->oDB;
		oph_odb_init_ophidiadb(oDB);

		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_SPLIT_OPHIDIADB_CONFIGURATION_FILE);
			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_SPLIT_OPHIDIADB_CONNECTION_ERROR);
			return OPH_ANALYTICS_OPERATOR_MYSQL_ERROR;
		}
		//Check if datacube exists (by ID container and datacube)
		int exists = 0;
		int status = 0;
		char *uri = NULL;
		int folder_id = 0;
		int permission = 0;

		if (oph_pid_parse_pid(datacube_in, &id_datacube_in[1], &id_datacube_in[0], &uri)) {
			pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to parse the PID string\n");
			logging(LOG_ERROR, __FILE__, __LINE__, id_datacube_in[1], OPH_LOG_OPH_SPLIT_PID_ERROR, datacube_in);
			id_datacube_in[0] = 0;
			id_datacube_in[1] = 0;
		} else if ((oph_odb_cube_check_if_datacube_not_present_by_pid(oDB, uri, id_datacube_in[1], id_datacube_in[0], &exists)) || !exists) {
			pmesg(LOG_ERROR, __FILE__, __LINE__, "Unknown input container - datacube combination\n");
			logging(LOG_ERROR, __FILE__, __LINE__, id_datacube_in[1], OPH_LOG_OPH_SPLIT_NO_INPUT_DATACUBE, datacube_in);
			id_datacube_in[0] = 0;
			id_datacube_in[1] = 0;
		} else if ((oph_odb_cube_check_datacube_availability(oDB, id_datacube_in[0], 0, &status)) || !status) {
			pmesg(LOG_ERROR, __FILE__, __LINE__, "I/O nodes storing datacube aren't available\n");
			logging(LOG_ERROR, __FILE__, __LINE__, id_datacube_in[1], OPH_LOG_OPH_SPLIT_DATACUBE_AVAILABILITY_ERROR, datacube_in);
			id_datacube_in[0] = 0;
			id_datacube_in[1] = 0;
		} else if ((oph_odb_fs_retrive_container_folder_id(oDB, id_datacube_in[1], 1, &folder_id))) {
			pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to retrieve folder of specified datacube or container is hidden\n");
			logging(LOG_ERROR, __FILE__, __LINE__, id_datacube_in[1], OPH_LOG_OPH_SPLIT_DATACUBE_FOLDER_ERROR, datacube_in);
			id_datacube_in[0] = 0;
			id_datacube_in[1] = 0;
		} else if ((oph_odb_fs_check_folder_session(folder_id, ((OPH_SPLIT_operator_handle *) handle->operator_handle)->sessionid, oDB, &permission)) || !permission) {
			//Check if user can work on datacube
			pmesg(LOG_ERROR, __FILE__, __LINE__, "User %s is not allowed to work on this datacube\n", username);
			logging(LOG_ERROR, __FILE__, __LINE__, id_datacube_in[1], OPH_LOG_OPH_SPLIT_DATACUBE_PERMISSION_ERROR, username);
			id_datacube_in[0] = 0;
			id_datacube_in[1] = 0;
		}
		if (uri)
			free(uri);
		uri = NULL;

		if (oph_odb_user_retrieve_user_id(oDB, username, &(((OPH_SPLIT_operator_handle *) handle->operator_handle)->id_user))) {
			pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to extract userid.\n");
			logging(LOG_ERROR, __FILE__, __LINE__, ((OPH_SPLIT_operator_handle *) handle->operator_handle)->id_input_container, OPH_LOG_GENERIC_USER_ID_ERROR);
			return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
		}

		id_datacube_in[2] = id_datacube_in[1];
		if (id_datacube_in[1]) {
			value = hashtbl_get(task_tbl, OPH_IN_PARAM_CONTAINER_INPUT);
			if (!value) {
				pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_CONTAINER_INPUT);
				logging(LOG_ERROR, __FILE__, __LINE__, id_datacube_in[1], OPH_LOG_FRAMEWORK_MISSING_INPUT_PARAMETER, OPH_IN_PARAM_CONTAINER_INPUT);
				return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
			}
			if (strncmp(value, OPH_COMMON_DEFAULT_EMPTY_VALUE, OPH_TP_TASKLEN)) {
				if (oph_odb_fs_retrieve_container_id_from_container_name(oDB, folder_id, value, 0, &id_datacube_in[2])) {
					pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to retrieve folder of specified container or it is hidden\n");
					logging(LOG_ERROR, __FILE__, __LINE__, id_datacube_in[1], OPH_LOG_GENERIC_DATACUBE_FOLDER_ERROR, value);
					id_datacube_in[0] = 0;
					id_datacube_in[1] = 0;
				}
			}
		}
	}
	//Broadcast to all other processes the fragment relative index        
	MPI_Bcast(id_datacube_in, 3, MPI_INT, 0, MPI_COMM_WORLD);

	//Check if sequential part has been completed
	if (id_datacube_in[0] == 0) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Master procedure or broadcasting has failed\n");
		logging(LOG_ERROR, __FILE__, __LINE__, id_datacube_in[1], OPH_LOG_OPH_SPLIT_NO_INPUT_DATACUBE, datacube_in);
		return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
	}
	((OPH_SPLIT_operator_handle *) handle->operator_handle)->id_input_datacube = id_datacube_in[0];
	if (id_datacube_in[1] == 0) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Master procedure or broadcasting has failed\n");
		logging(LOG_ERROR, __FILE__, __LINE__, id_datacube_in[1], OPH_LOG_OPH_SPLIT_NO_INPUT_CONTAINER, datacube_in);
		return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
	}
	((OPH_SPLIT_operator_handle *) handle->operator_handle)->id_input_container = id_datacube_in[1];
	((OPH_SPLIT_operator_handle *) handle->operator_handle)->id_output_container = id_datacube_in[2];

	value = hashtbl_get(task_tbl, OPH_IN_PARAM_SCHEDULE_ALGORITHM);
	if (!value) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_SCHEDULE_ALGORITHM);
		logging(LOG_ERROR, __FILE__, __LINE__, id_datacube_in[1], OPH_LOG_OPH_SPLIT_MISSING_INPUT_PARAMETER, OPH_IN_PARAM_SCHEDULE_ALGORITHM);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}
	((OPH_SPLIT_operator_handle *) handle->operator_handle)->schedule_algo = (int) strtol(value, NULL, 10);

	value = hashtbl_get(task_tbl, OPH_IN_PARAM_SPLIT_IN_FRAGMENTS);
	if (!value) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_SPLIT_IN_FRAGMENTS);
		logging(LOG_ERROR, __FILE__, __LINE__, id_datacube_in[1], OPH_LOG_OPH_SPLIT_MISSING_INPUT_PARAMETER, OPH_IN_PARAM_SPLIT_IN_FRAGMENTS);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}
	((OPH_SPLIT_operator_handle *) handle->operator_handle)->split_number = (int) strtol(value, NULL, 10);

	value = hashtbl_get(task_tbl, OPH_ARG_IDJOB);
	if (!value)
		((OPH_SPLIT_operator_handle *) handle->operator_handle)->id_job = 0;
	else
		((OPH_SPLIT_operator_handle *) handle->operator_handle)->id_job = (int) strtol(value, NULL, 10);

	value = hashtbl_get(task_tbl, OPH_IN_PARAM_DESCRIPTION);
	if (!value) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_DESCRIPTION);
		logging(LOG_ERROR, __FILE__, __LINE__, id_datacube_in[1], OPH_LOG_FRAMEWORK_MISSING_INPUT_PARAMETER, OPH_IN_PARAM_DESCRIPTION);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}
	if (strncmp(value, OPH_COMMON_DEFAULT_EMPTY_VALUE, OPH_TP_TASKLEN)) {
		if (!(((OPH_SPLIT_operator_handle *) handle->operator_handle)->description = (char *) strndup(value, OPH_TP_TASKLEN))) {
			logging(LOG_ERROR, __FILE__, __LINE__, id_datacube_in[1], OPH_LOG_OPH_SPLIT_MEMORY_ERROR_INPUT, "description");
			pmesg(LOG_ERROR, __FILE__, __LINE__, "Error allocating memory\n");
			return OPH_ANALYTICS_OPERATOR_MEMORY_ERR;
		}
	}

	return OPH_ANALYTICS_OPERATOR_SUCCESS;
}
int env_set(HASHTBL * task_tbl, oph_operator_struct * handle)
{
	if (!handle) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Null Handle\n");
		return OPH_ANALYTICS_OPERATOR_NULL_OPERATOR_HANDLE;
	}

	if (!task_tbl) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Null operator string\n");
		return OPH_ANALYTICS_OPERATOR_BAD_PARAMETER;
	}

	if (handle->operator_handle) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Operator handle already initialized\n");
		return OPH_ANALYTICS_OPERATOR_NOT_NULL_OPERATOR_HANDLE;
	}

	if (!(handle->operator_handle = (OPH_CUBEIO_operator_handle *) calloc(1, sizeof(OPH_CUBEIO_operator_handle)))) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Error allocating memory\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_CUBEIO_MEMORY_ERROR_HANDLE);
		return OPH_ANALYTICS_OPERATOR_MEMORY_ERR;
	}
	//1 - Set up struct to empty values
	((OPH_CUBEIO_operator_handle *) handle->operator_handle)->direction = 0;
	((OPH_CUBEIO_operator_handle *) handle->operator_handle)->id_input_container = 0;
	((OPH_CUBEIO_operator_handle *) handle->operator_handle)->id_input_datacube = 0;
	((OPH_CUBEIO_operator_handle *) handle->operator_handle)->datacube_name = NULL;
	((OPH_CUBEIO_operator_handle *) handle->operator_handle)->objkeys = NULL;
	((OPH_CUBEIO_operator_handle *) handle->operator_handle)->objkeys_num = -1;
	((OPH_CUBEIO_operator_handle *) handle->operator_handle)->sessionid = NULL;

	ophidiadb *oDB = &((OPH_CUBEIO_operator_handle *) handle->operator_handle)->oDB;

	//Only master process has to continue
	if (handle->proc_rank != 0)
		return OPH_ANALYTICS_OPERATOR_SUCCESS;

	oph_odb_init_ophidiadb(oDB);


	//3 - Fill struct with the correct data
	char *datacube_name, *value;

	// retrieve objkeys
	value = hashtbl_get(task_tbl, OPH_IN_PARAM_OBJKEY_FILTER);
	if (!value) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_OBJKEY_FILTER);
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_FRAMEWORK_MISSING_INPUT_PARAMETER, OPH_IN_PARAM_OBJKEY_FILTER);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}
	if (oph_tp_parse_multiple_value_param(value, &((OPH_CUBEIO_operator_handle *) handle->operator_handle)->objkeys, &((OPH_CUBEIO_operator_handle *) handle->operator_handle)->objkeys_num)) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Operator string not valid\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, "Operator string not valid\n");
		oph_tp_free_multiple_value_param_list(((OPH_CUBEIO_operator_handle *) handle->operator_handle)->objkeys, ((OPH_CUBEIO_operator_handle *) handle->operator_handle)->objkeys_num);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}
	// retrieve sessionid
	value = hashtbl_get(task_tbl, OPH_ARG_SESSIONID);
	if (!value) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_ARG_SESSIONID);
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_FRAMEWORK_MISSING_INPUT_PARAMETER, OPH_ARG_SESSIONID);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}
	if (!(((OPH_CUBEIO_operator_handle *) handle->operator_handle)->sessionid = (char *) strndup(value, OPH_TP_TASKLEN))) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Error allocating memory\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_GENERIC_MEMORY_ERROR_INPUT, "sessionid");
		return OPH_ANALYTICS_OPERATOR_MEMORY_ERR;
	}

	value = hashtbl_get(task_tbl, OPH_IN_PARAM_DATACUBE_INPUT);
	datacube_name = value;
	if (!value) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_DATACUBE_INPUT);
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_CUBEIO_MISSING_INPUT_PARAMETER, OPH_IN_PARAM_DATACUBE_INPUT);

		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}

	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_CUBEIO_OPHIDIADB_CONFIGURATION_FILE);

		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_CUBEIO_OPHIDIADB_CONNECTION_ERROR);

		return OPH_ANALYTICS_OPERATOR_MYSQL_ERROR;
	}

	value = hashtbl_get(task_tbl, OPH_ARG_USERNAME);
	if (!value) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_ARG_USERNAME);
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_CUBEIO_MISSING_INPUT_PARAMETER, OPH_ARG_USERNAME);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}
	char *username = value;

	int id_container = 0, id_datacube = 0;

	//Check if datacube exists (by ID container and datacube)
	int exists = 0;
	char *uri = NULL;
	int folder_id = 0;
	int permission = 0;

	if (oph_pid_parse_pid(datacube_name, &id_container, &id_datacube, &uri)) {
		if (uri)
			free(uri);
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to parse the PID string\n");
		logging(LOG_ERROR, __FILE__, __LINE__, id_container, OPH_LOG_OPH_CUBEIO_PID_ERROR, datacube_name);
		return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
	} else if ((oph_odb_cube_check_if_datacube_not_present_by_pid(oDB, uri, id_container, id_datacube, &exists)) || !exists) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Unknown input container - datacube combination\n");
		logging(LOG_ERROR, __FILE__, __LINE__, id_container, OPH_LOG_OPH_CUBEIO_NO_INPUT_DATACUBE, datacube_name);
		free(uri);
		return OPH_ANALYTICS_OPERATOR_MYSQL_ERROR;
	} else if ((oph_odb_fs_retrive_container_folder_id(oDB, id_container, 1, &folder_id))) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to retrieve folder of specified datacube or container is hidden\n");
		logging(LOG_ERROR, __FILE__, __LINE__, id_container, OPH_LOG_OPH_CUBEIO_DATACUBE_FOLDER_ERROR, datacube_name);
		free(uri);
		return OPH_ANALYTICS_OPERATOR_MYSQL_ERROR;
	} else if ((oph_odb_fs_check_folder_session(folder_id, ((OPH_CUBEIO_operator_handle *) handle->operator_handle)->sessionid, oDB, &permission)) || !permission) {
		//Check if user can work on datacube
		pmesg(LOG_ERROR, __FILE__, __LINE__, "User %s is not allowed to work on this datacube\n", username);
		logging(LOG_ERROR, __FILE__, __LINE__, id_container, OPH_LOG_OPH_CUBEIO_DATACUBE_PERMISSION_ERROR, username);
		free(uri);
		return OPH_ANALYTICS_OPERATOR_MYSQL_ERROR;
	}

	free(uri);
	((OPH_CUBEIO_operator_handle *) handle->operator_handle)->id_input_container = id_container;
	((OPH_CUBEIO_operator_handle *) handle->operator_handle)->id_input_datacube = id_datacube;


	if (!(((OPH_CUBEIO_operator_handle *) handle->operator_handle)->datacube_name = (char *) strndup(datacube_name, OPH_TP_TASKLEN))) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Error allocating memory\n");
		logging(LOG_ERROR, __FILE__, __LINE__, id_container, OPH_LOG_OPH_CUBEIO_MEMORY_ERROR_INPUT, "datacube name");

		return OPH_ANALYTICS_OPERATOR_MEMORY_ERR;
	}


	value = hashtbl_get(task_tbl, OPH_IN_PARAM_CUBEIO_HIERARCHY_DIRECTION);
	if (!value) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_CUBEIO_HIERARCHY_DIRECTION);
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_CUBEIO_MISSING_INPUT_PARAMETER, OPH_IN_PARAM_CUBEIO_HIERARCHY_DIRECTION);

		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}
	if (strcmp(value, OPH_CUBEIO_PARENT_VALUE) == 0)
		((OPH_CUBEIO_operator_handle *) handle->operator_handle)->direction = OPH_CUBEIO_BRANCH_IN;
	else if (strcmp(value, OPH_CUBEIO_CHILDREN_VALUE) == 0)
		((OPH_CUBEIO_operator_handle *) handle->operator_handle)->direction = OPH_CUBEIO_BRANCH_OUT;
	else
		((OPH_CUBEIO_operator_handle *) handle->operator_handle)->direction = OPH_CUBEIO_BRANCH_BOTH;

	return OPH_ANALYTICS_OPERATOR_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_DELETE_operator_handle*)handle->operator_handle)->id_input_container, OPH_LOG_OPH_DELETE_NULL_OPERATOR_HANDLE);    
	  return OPH_ANALYTICS_OPERATOR_NULL_OPERATOR_HANDLE;
  }

  if(((OPH_DELETE_operator_handle*)handle->operator_handle)->fragment_id_start_position < 0 && handle->proc_rank!= 0)
	return OPH_ANALYTICS_OPERATOR_SUCCESS;

  int i, j, k;

  int id_datacube = ((OPH_DELETE_operator_handle*)handle->operator_handle)->id_input_datacube;
  
  oph_odb_fragment_list frags;
  oph_odb_db_instance_list dbs;
  oph_odb_dbms_instance_list dbmss;

  int datacubexdb_number = 0;

	//Each process has to be connected to a slave ophidiadb
  ophidiadb oDB_slave;
  oph_odb_init_ophidiadb(&oDB_slave);	

  if(oph_odb_read_ophidiadb_config_file(&oDB_slave)){
	pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to read OphidiaDB configuration\n");
	logging(LOG_ERROR, __FILE__, __LINE__, ((OPH_DELETE_operator_handle*)handle->operator_handle)->id_input_container, OPH_LOG_OPH_DELETE_OPHIDIADB_CONFIGURATION_FILE);
	return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
  }

  if( oph_odb_connect_to_ophidiadb(&oDB_slave)){
	pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to connect to OphidiaDB. Check access parameters.\n");
	logging(LOG_ERROR, __FILE__, __LINE__, ((OPH_DELETE_operator_handle*)handle->operator_handle)->id_input_container, OPH_LOG_OPH_DELETE_OPHIDIADB_CONNECTION_ERROR);
    oph_odb_free_ophidiadb(&oDB_slave);
	return OPH_ANALYTICS_OPERATOR_MYSQL_ERROR;
  }


  //retrieve connection string
  if(oph_odb_stge_fetch_fragment_connection_string_for_deletion(&oDB_slave, id_datacube, ((OPH_DELETE_operator_handle*)handle->operator_handle)->fragment_ids, &frags, &dbs, &dbmss)){
	pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to retreive connection strings\n");
	logging(LOG_ERROR, __FILE__, __LINE__, ((OPH_DELETE_operator_handle*)handle->operator_handle)->id_input_container, OPH_LOG_OPH_DELETE_CONNECTION_STRINGS_NOT_FOUND);    
	oph_odb_free_ophidiadb(&oDB_slave);
	return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
  }

  if (!frags.size)
  {
	oph_odb_stge_free_fragment_list(&frags);
	oph_odb_stge_free_db_list(&dbs);
	oph_odb_stge_free_dbms_list(&dbmss);
	oph_odb_free_ophidiadb(&oDB_slave);
	return OPH_ANALYTICS_OPERATOR_SUCCESS;
  }

  int result = OPH_ANALYTICS_OPERATOR_SUCCESS;	

  if(oph_dc2_setup_dbms(&(((OPH_DELETE_operator_handle*)handle->operator_handle)->server), (dbmss.value[0]).io_server_type))
	{
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to initialize IO server.\n");
		logging(LOG_ERROR, __FILE__, __LINE__, ((OPH_DELETE_operator_handle*)handle->operator_handle)->id_input_container, OPH_LOG_OPH_DELETE_IOPLUGIN_SETUP_ERROR, (dbmss.value[0]).id_dbms);    
		result = OPH_ANALYTICS_OPERATOR_MYSQL_ERROR;
	}

  //For each DBMS
  for(i = 0; (i < dbmss.size) && (result == OPH_ANALYTICS_OPERATOR_SUCCESS);  i++){
	if(oph_dc2_connect_to_dbms(((OPH_DELETE_operator_handle*)handle->operator_handle)->server, &(dbmss.value[i]), 0))
	{
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to connect to DBMS. Check access parameters.\n");
		logging(LOG_ERROR, __FILE__, __LINE__, ((OPH_DELETE_operator_handle*)handle->operator_handle)->id_input_container, OPH_LOG_OPH_DELETE_DBMS_CONNECTION_ERROR, (dbmss.value[i]).id_dbms);    
		result = OPH_ANALYTICS_OPERATOR_MYSQL_ERROR;
	}

	//For each DB
	for(j = 0; (j < dbs.size) && (result == OPH_ANALYTICS_OPERATOR_SUCCESS); j++){
		//Check DB - DBMS Association
		if(dbs.value[j].dbms_instance != &(dbmss.value[i])) continue;

		//For each dbinstance count the number of stored datacubes
		if(oph_odb_stge_get_number_of_datacube_for_db(&oDB_slave, dbs.value[j].id_db, &datacubexdb_number))
		{
			pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to retrieve database instance information.\n");
			logging(LOG_ERROR, __FILE__, __LINE__, ((OPH_DELETE_operator_handle*)handle->operator_handle)->id_input_container, OPH_LOG_OPH_DELETE_DB_DATACUBE_COUNT_ERROR, (dbs.value[j]).db_name);    
			result = OPH_ANALYTICS_OPERATOR_MYSQL_ERROR;
			break;
		}

	    //If the db stores just one datacube then directly drop the dbinstance
		if(datacubexdb_number == 1){
			//Databse drop
			if(oph_dc2_delete_db(((OPH_DELETE_operator_handle*)handle->operator_handle)->server, &(dbs.value[j])))
			{
				pmesg(LOG_ERROR, __FILE__, __LINE__, "Error while dropping database.\n");
				logging(LOG_ERROR, __FILE__, __LINE__, ((OPH_DELETE_operator_handle*)handle->operator_handle)->id_input_container, OPH_LOG_OPH_DELETE_DROP_DB_ERROR, (dbs.value[j]).db_name);    
				result = OPH_ANALYTICS_OPERATOR_MYSQL_ERROR;
				break;
			}
			continue;
		}
		//In this case the dbinstance may be already been deleted before
		else if(datacubexdb_number == 0)
			continue;

		if(oph_dc2_use_db_of_dbms(((OPH_DELETE_operator_handle*)handle->operator_handle)->server, &(dbmss.value[i]), &(dbs.value[j])))
		{
			pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to use the DB. Check access parameters.\n");
			logging(LOG_ERROR, __FILE__, __LINE__, ((OPH_DELETE_operator_handle*)handle->operator_handle)->id_input_container, OPH_LOG_OPH_DELETE_DB_SELECTION_ERROR, (dbs.value[j]).db_name);    
			result = OPH_ANALYTICS_OPERATOR_MYSQL_ERROR;
			break;
		}

		//For each fragment
		for(k = 0; k < frags.size; k++){
			//Check Fragment - DB Association
			if(frags.value[k].db_instance != &(dbs.value[j])) continue;

			//Delete fragment
			if(oph_dc2_delete_fragment(((OPH_DELETE_operator_handle*)handle->operator_handle)->server, &(frags.value[k]))){
				pmesg(LOG_ERROR, __FILE__, __LINE__, "Error while dropping table.\n");
				logging(LOG_ERROR, __FILE__, __LINE__, ((OPH_DELETE_operator_handle*)handle->operator_handle)->id_input_container, OPH_LOG_OPH_DELETE_DROP_FRAGMENT_ERROR, (frags.value[j]).fragment_name);    
				result = OPH_ANALYTICS_OPERATOR_MYSQL_ERROR;
				break;
			}
		}
	}
	oph_dc2_disconnect_from_dbms(((OPH_DELETE_operator_handle*)handle->operator_handle)->server, &(dbmss.value[i]));
  }
  if(oph_dc2_cleanup_dbms(((OPH_DELETE_operator_handle*)handle->operator_handle)->server))
	{
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to finalize IO server.\n");
		logging(LOG_ERROR, __FILE__, __LINE__, ((OPH_DELETE_operator_handle*)handle->operator_handle)->id_input_container, OPH_LOG_OPH_DELETE_IOPLUGIN_CLEANUP_ERROR, (dbmss.value[0]).id_dbms);    
		result = OPH_ANALYTICS_OPERATOR_MYSQL_ERROR;
	}

  oph_odb_stge_free_fragment_list(&frags);
  oph_odb_stge_free_db_list(&dbs);
  oph_odb_stge_free_dbms_list(&dbmss);
  oph_odb_free_ophidiadb(&oDB_slave);

  return result;
}
int env_set (HASHTBL *task_tbl, oph_operator_struct *handle)
{
  if (!handle){
  	pmesg(LOG_ERROR, __FILE__, __LINE__, "Null Handle\n");
 	logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_METADATA_NULL_OPERATOR_HANDLE);
	  return OPH_ANALYTICS_OPERATOR_NULL_OPERATOR_HANDLE;
  }

  if (!task_tbl){
	  pmesg(LOG_ERROR, __FILE__, __LINE__, "Null operator string\n");
 	  logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_METADATA_NULL_TASK_TABLE);
      return OPH_ANALYTICS_OPERATOR_BAD_PARAMETER;
  }

  if (handle->operator_handle){
	pmesg(LOG_ERROR, __FILE__, __LINE__, "Operator handle already initialized\n");
 	logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_METADATA_HANDLE_ALREADY_INITIALIZED);
    return OPH_ANALYTICS_OPERATOR_NOT_NULL_OPERATOR_HANDLE;
  }

  if (!(handle->operator_handle = (OPH_METADATA_operator_handle *) calloc (1, sizeof (OPH_METADATA_operator_handle)))){
	pmesg(LOG_ERROR, __FILE__, __LINE__, "Error allocating memory\n");
	logging(LOG_ERROR,__FILE__,__LINE__, OPH_GENERIC_CONTAINER_ID,OPH_LOG_OPH_METADATA_MEMORY_ERROR_HANDLE);
    return OPH_ANALYTICS_OPERATOR_MEMORY_ERR;
  }

  //1 - Set up struct to empty values
  ((OPH_METADATA_operator_handle*)handle->operator_handle)->id_datacube_input = 0;
  ((OPH_METADATA_operator_handle*)handle->operator_handle)->id_container_input = 0;
  ((OPH_METADATA_operator_handle*)handle->operator_handle)->metadata_id = 0;
  ((OPH_METADATA_operator_handle*)handle->operator_handle)->metadata_id_str = NULL;
  ((OPH_METADATA_operator_handle*)handle->operator_handle)->metadata_keys = NULL;
  ((OPH_METADATA_operator_handle*)handle->operator_handle)->metadata_keys_num = 0;
  ((OPH_METADATA_operator_handle*)handle->operator_handle)->variable = NULL;
  ((OPH_METADATA_operator_handle*)handle->operator_handle)->metadata_type = NULL;
  ((OPH_METADATA_operator_handle*)handle->operator_handle)->metadata_type_filter = NULL;
  ((OPH_METADATA_operator_handle*)handle->operator_handle)->metadata_value = NULL;
  ((OPH_METADATA_operator_handle*)handle->operator_handle)->metadata_value_filter = NULL;
  ((OPH_METADATA_operator_handle*)handle->operator_handle)->mode = -1;
  ((OPH_METADATA_operator_handle*)handle->operator_handle)->force = 0;
  ((OPH_METADATA_operator_handle*)handle->operator_handle)->user = NULL;
  ((OPH_METADATA_operator_handle*)handle->operator_handle)->objkeys = NULL;
  ((OPH_METADATA_operator_handle*)handle->operator_handle)->objkeys_num = -1;
  ((OPH_METADATA_operator_handle*)handle->operator_handle)->sessionid = NULL;
  ((OPH_METADATA_operator_handle*)handle->operator_handle)->userrole = OPH_ROLE_NONE;

  ophidiadb *oDB = &((OPH_METADATA_operator_handle*)handle->operator_handle)->oDB;

  //Only master process has to continue
  if (handle->proc_rank != 0)
	return OPH_ANALYTICS_OPERATOR_SUCCESS;

  oph_odb_init_ophidiadb(oDB);

  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_METADATA_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_METADATA_OPHIDIADB_CONNECTION_ERROR_NO_CONTAINER);
    return OPH_ANALYTICS_OPERATOR_MYSQL_ERROR;
  }

  //3 - Fill struct with the correct data

  char *value;

  // retrieve objkeys
  value = hashtbl_get(task_tbl, OPH_IN_PARAM_OBJKEY_FILTER);
  if(!value){
    pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_OBJKEY_FILTER);
    logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_FRAMEWORK_MISSING_INPUT_PARAMETER, OPH_IN_PARAM_OBJKEY_FILTER );
    return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
  }
  if(oph_tp_parse_multiple_value_param(value, &((OPH_METADATA_operator_handle*)handle->operator_handle)->objkeys, &((OPH_METADATA_operator_handle*)handle->operator_handle)->objkeys_num)){
    pmesg(LOG_ERROR, __FILE__, __LINE__, "Operator string not valid\n");
    logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, "Operator string not valid\n");
    oph_tp_free_multiple_value_param_list(((OPH_METADATA_operator_handle*)handle->operator_handle)->objkeys, ((OPH_METADATA_operator_handle*)handle->operator_handle)->objkeys_num);
    return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
  }

  // retrieve sessionid
  value = hashtbl_get(task_tbl, OPH_ARG_SESSIONID);
  if(!value){
	pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_ARG_SESSIONID);
    logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_FRAMEWORK_MISSING_INPUT_PARAMETER, OPH_ARG_SESSIONID);
	return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
  }
  if(!(((OPH_METADATA_operator_handle*)handle->operator_handle)->sessionid = (char *) strndup (value, OPH_TP_TASKLEN))){
	pmesg(LOG_ERROR, __FILE__, __LINE__, "Error allocating memory\n");
    logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_GENERIC_MEMORY_ERROR_INPUT, "sessionid" );
	return OPH_ANALYTICS_OPERATOR_MEMORY_ERR;
  }

  value = hashtbl_get(task_tbl, OPH_IN_PARAM_MODE);
  if(!value){
	pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_MODE);
    logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_METADATA_MISSING_INPUT_PARAMETER, OPH_IN_PARAM_MODE );
    return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
  }
  if (!strcasecmp(value,OPH_METADATA_MODE_INSERT)) {
      ((OPH_METADATA_operator_handle*)handle->operator_handle)->mode = OPH_METADATA_MODE_INSERT_VALUE;
  } else if (!strcasecmp(value,OPH_METADATA_MODE_READ)) {
      ((OPH_METADATA_operator_handle*)handle->operator_handle)->mode = OPH_METADATA_MODE_READ_VALUE;
  } else if (!strcasecmp(value,OPH_METADATA_MODE_UPDATE)) {
      ((OPH_METADATA_operator_handle*)handle->operator_handle)->mode = OPH_METADATA_MODE_UPDATE_VALUE;
  } else if (!strcasecmp(value,OPH_METADATA_MODE_DELETE)) {
      ((OPH_METADATA_operator_handle*)handle->operator_handle)->mode = OPH_METADATA_MODE_DELETE_VALUE;
  } else {
      pmesg(LOG_ERROR, __FILE__, __LINE__, "Invalid input parameter %s\n", value);
      logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_METADATA_INVALID_INPUT_PARAMETER, value );
      return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
  }

  //Check if user can access container and retrieve container id
  value = hashtbl_get(task_tbl, OPH_ARG_USERNAME);
  if(!value){
    pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_ARG_USERNAME);
    logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_METADATA_MISSING_INPUT_PARAMETER, OPH_ARG_USERNAME );
    return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
  }
  if(!(((OPH_METADATA_operator_handle*)handle->operator_handle)->user = (char *) strdup(value))){
      pmesg(LOG_ERROR, __FILE__, __LINE__, "Error allocating memory\n");
      logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_METADATA_MEMORY_ERROR_INPUT, OPH_ARG_USERNAME );
      return OPH_ANALYTICS_OPERATOR_MEMORY_ERR;
  }

  value = hashtbl_get(task_tbl, OPH_IN_PARAM_DATACUBE_INPUT);
  if(!value){
	pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_DATACUBE_INPUT);
	logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_METADATA_MISSING_INPUT_PARAMETER, OPH_IN_PARAM_DATACUBE_INPUT );
	return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
  }
	  //Check if datacube exists (by ID container and datacube)
	  int exists = 0;
	  int status = 0;
	  int folder_id = 0;
	  int permission = 0;
	  char *uri = NULL;
	  if(oph_pid_parse_pid(value, &(((OPH_METADATA_operator_handle*)handle->operator_handle)->id_container_input), &(((OPH_METADATA_operator_handle*)handle->operator_handle)->id_datacube_input), &uri)){
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to parse the PID string\n");
		logging(LOG_ERROR, __FILE__, __LINE__, ((OPH_METADATA_operator_handle*)handle->operator_handle)->id_container_input, OPH_LOG_OPH_METADATA_PID_ERROR, value );
		if(uri) free(uri);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	  }
	  else if((oph_odb_cube_check_if_datacube_not_present_by_pid(oDB, uri, ((OPH_METADATA_operator_handle*)handle->operator_handle)->id_container_input, ((OPH_METADATA_operator_handle*)handle->operator_handle)->id_datacube_input, &exists)) || !exists){
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Unknown input container - datacube combination\n");
		logging(LOG_ERROR, __FILE__, __LINE__, ((OPH_METADATA_operator_handle*)handle->operator_handle)->id_container_input, OPH_LOG_OPH_METADATA_NO_INPUT_DATACUBE, value );
		if(uri) free(uri);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	  }
	  else if((oph_odb_cube_check_datacube_availability(oDB, ((OPH_METADATA_operator_handle*)handle->operator_handle)->id_datacube_input, 0, &status)) || !status){
		pmesg(LOG_ERROR, __FILE__, __LINE__, "I/O nodes storing datacube aren't available\n");
		logging(LOG_ERROR, __FILE__, __LINE__, ((OPH_METADATA_operator_handle*)handle->operator_handle)->id_container_input, OPH_LOG_OPH_METADATA_DATACUBE_AVAILABILITY_ERROR, value );
		if(uri) free(uri);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	  }
	  else if((oph_odb_fs_retrive_container_folder_id(oDB, ((OPH_METADATA_operator_handle*)handle->operator_handle)->id_container_input, 1, &folder_id))){
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to retrieve folder of specified datacube or container is hidden\n");
		logging(LOG_ERROR, __FILE__, __LINE__, ((OPH_METADATA_operator_handle*)handle->operator_handle)->id_container_input, OPH_LOG_OPH_METADATA_DATACUBE_FOLDER_ERROR, value );
		if(uri) free(uri);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	  }
	  else if((oph_odb_fs_check_folder_session(folder_id, ((OPH_METADATA_operator_handle*)handle->operator_handle)->sessionid, oDB, &permission)) || !permission){
		//Check if user can work on datacube
		pmesg(LOG_ERROR, __FILE__, __LINE__, "User %s is not allowed to work on this datacube\n", ((OPH_METADATA_operator_handle*)handle->operator_handle)->user);
		logging(LOG_ERROR, __FILE__, __LINE__, ((OPH_METADATA_operator_handle*)handle->operator_handle)->id_container_input, OPH_LOG_OPH_METADATA_DATACUBE_PERMISSION_ERROR, ((OPH_METADATA_operator_handle*)handle->operator_handle)->user );
		if(uri) free(uri);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	  }
	if(uri) free(uri);
	uri = NULL;

  value = hashtbl_get(task_tbl, OPH_IN_PARAM_METADATA_KEY);
  if(!value){
    pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_METADATA_KEY);
    logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_METADATA_MISSING_INPUT_PARAMETER, OPH_IN_PARAM_METADATA_KEY );
    return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
  }
  if(oph_tp_parse_multiple_value_param(value, &((OPH_METADATA_operator_handle*)handle->operator_handle)->metadata_keys, &((OPH_METADATA_operator_handle*)handle->operator_handle)->metadata_keys_num)){
    pmesg(LOG_ERROR, __FILE__, __LINE__, "Operator string not valid\n");
    logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_METADATA_INVALID_INPUT_STRING);
    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);
    return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
  }
  //If first value supplied as key is ALL, then free the structure and set values to NULL and 0
  if(strncmp(((OPH_METADATA_operator_handle*)handle->operator_handle)->metadata_keys[0], OPH_COMMON_ALL_FILTER, strlen(OPH_COMMON_ALL_FILTER)) == 0){
	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;
	((OPH_METADATA_operator_handle*)handle->operator_handle)->metadata_keys_num = 0;
  }

  value = hashtbl_get(task_tbl, OPH_IN_PARAM_METADATA_ID);
  if(!value){
    pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_METADATA_ID);
    logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_METADATA_MISSING_INPUT_PARAMETER, OPH_IN_PARAM_METADATA_ID );
    return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
  }
  if(!(((OPH_METADATA_operator_handle*)handle->operator_handle)->metadata_id_str = (char *) strdup(value))){
      pmesg(LOG_ERROR, __FILE__, __LINE__, "Error allocating memory\n");
      logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_METADATA_MEMORY_ERROR_INPUT, OPH_IN_PARAM_METADATA_ID );
      return OPH_ANALYTICS_OPERATOR_MEMORY_ERR;
  }
  ((OPH_METADATA_operator_handle*)handle->operator_handle)->metadata_id = (int)strtol(value,NULL,10);

  value = hashtbl_get(task_tbl, OPH_IN_PARAM_METADATA_VARIABLE);
  if(!value){
    pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_METADATA_VARIABLE);
    logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_METADATA_MISSING_INPUT_PARAMETER, OPH_IN_PARAM_METADATA_VARIABLE );
    return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
  }
  if (strcasecmp(value,OPH_COMMON_GLOBAL_VALUE)) {
	  if(!(((OPH_METADATA_operator_handle*)handle->operator_handle)->variable = (char *) strdup(value))){
	      pmesg(LOG_ERROR, __FILE__, __LINE__, "Error allocating memory\n");
	      logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_METADATA_MEMORY_ERROR_INPUT, OPH_IN_PARAM_METADATA_VARIABLE );
	      return OPH_ANALYTICS_OPERATOR_MEMORY_ERR;
	  }
  }

  value = hashtbl_get(task_tbl, OPH_IN_PARAM_METADATA_TYPE);
  if(!value){
    pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_METADATA_TYPE);
    logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_METADATA_MISSING_INPUT_PARAMETER, OPH_IN_PARAM_METADATA_TYPE );
    return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
  }
  if(!(((OPH_METADATA_operator_handle*)handle->operator_handle)->metadata_type = (char *) strdup(value))){
      pmesg(LOG_ERROR, __FILE__, __LINE__, "Error allocating memory\n");
      logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_METADATA_MEMORY_ERROR_INPUT, OPH_IN_PARAM_METADATA_TYPE );
      return OPH_ANALYTICS_OPERATOR_MEMORY_ERR;
  }

  value = hashtbl_get(task_tbl, OPH_IN_PARAM_METADATA_VALUE);
  if(!value){
    pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_METADATA_VALUE);
    logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_METADATA_MISSING_INPUT_PARAMETER, OPH_IN_PARAM_METADATA_VALUE );
    return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
  }
  if(strncmp(value, OPH_COMMON_DEFAULT_EMPTY_VALUE, OPH_TP_TASKLEN) != 0){
	  if(!(((OPH_METADATA_operator_handle*)handle->operator_handle)->metadata_value = (char *) strdup(value))){
		  pmesg(LOG_ERROR, __FILE__, __LINE__, "Error allocating memory\n");
		  logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_METADATA_MEMORY_ERROR_INPUT, OPH_IN_PARAM_METADATA_VALUE );
		  return OPH_ANALYTICS_OPERATOR_MEMORY_ERR;
	  }
  }

  value = hashtbl_get(task_tbl, OPH_IN_PARAM_METADATA_TYPE_FILTER);
  if(!value){
    pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_METADATA_TYPE_FILTER);
    logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_METADATA_MISSING_INPUT_PARAMETER, OPH_IN_PARAM_METADATA_TYPE_FILTER );
    return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
  }
  if(strcasecmp(value,OPH_COMMON_ALL_FILTER) != 0){
	  if(!(((OPH_METADATA_operator_handle*)handle->operator_handle)->metadata_type_filter = (char *) strdup(value))){
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Error allocating memory\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_METADATA_MEMORY_ERROR_INPUT, OPH_IN_PARAM_METADATA_TYPE_FILTER );
		return OPH_ANALYTICS_OPERATOR_MEMORY_ERR;
	  }
  } else {
      if(!(((OPH_METADATA_operator_handle*)handle->operator_handle)->metadata_type_filter = (char *) strdup("%"))){
        pmesg(LOG_ERROR, __FILE__, __LINE__, "Error allocating memory\n");
        logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_METADATA_MEMORY_ERROR_INPUT, OPH_IN_PARAM_METADATA_TYPE_FILTER );
        return OPH_ANALYTICS_OPERATOR_MEMORY_ERR;
      }
  }

  value = hashtbl_get(task_tbl, OPH_IN_PARAM_METADATA_VALUE_FILTER);
  if(!value){
    pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_METADATA_VALUE_FILTER);
    logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_METADATA_MISSING_INPUT_PARAMETER, OPH_IN_PARAM_METADATA_VALUE_FILTER );
    return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
  }
  if(strcasecmp(value,OPH_COMMON_ALL_FILTER) != 0){
      if(!(((OPH_METADATA_operator_handle*)handle->operator_handle)->metadata_value_filter = (char *) strdup(value))){
        pmesg(LOG_ERROR, __FILE__, __LINE__, "Error allocating memory\n");
        logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_METADATA_MEMORY_ERROR_INPUT, OPH_IN_PARAM_METADATA_VALUE_FILTER );
        return OPH_ANALYTICS_OPERATOR_MEMORY_ERR;
      }
  } else {
      if(!(((OPH_METADATA_operator_handle*)handle->operator_handle)->metadata_value_filter = (char *) strdup("%"))){
        pmesg(LOG_ERROR, __FILE__, __LINE__, "Error allocating memory\n");
        logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_METADATA_MEMORY_ERROR_INPUT, OPH_IN_PARAM_METADATA_VALUE_FILTER );
        return OPH_ANALYTICS_OPERATOR_MEMORY_ERR;
      }
  }

  value = hashtbl_get(task_tbl, OPH_IN_PARAM_FORCE);
  if(!value){
	pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_FORCE);
	logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_METADATA_MISSING_INPUT_PARAMETER, OPH_IN_PARAM_FORCE );
	return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
  }
  if(strcmp(value,OPH_COMMON_YES_VALUE) == 0){
	  ((OPH_METADATA_operator_handle*)handle->operator_handle)->force = 1;
  }

  value = hashtbl_get(task_tbl, OPH_ARG_USERROLE);
  if(!value){
    pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_ARG_USERROLE);
    logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_METADATA_MISSING_INPUT_PARAMETER, OPH_ARG_USERROLE );
    return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
  }
  ((OPH_METADATA_operator_handle*)handle->operator_handle)->userrole = (int)strtol(value, NULL, 10);

  return OPH_ANALYTICS_OPERATOR_SUCCESS;
}