Skip to content

Commit

Permalink
[irods#296] Replace proxy_connection with client_connection
Browse files Browse the repository at this point in the history
The proxy_connections used by this plugin are equivalent to
using the irods::experimental::client_connection provided by
the iRODS client library except for modifying the authFlag.
Seeing as everything is done by client connections as admins
in the plugin now, the authFlag doesn't matter as much anymore.
As such, all instances of proxy_connection can be replaced and
the whole header file has been removed.

Also removes the unused exec_as_user header file.
  • Loading branch information
alanking committed Jan 23, 2025
1 parent 61ad6bc commit 885a78d
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 186 deletions.
41 changes: 0 additions & 41 deletions include/irods/private/storage_tiering/exec_as_user.hpp

This file was deleted.

71 changes: 0 additions & 71 deletions include/irods/private/storage_tiering/proxy_connection.hpp

This file was deleted.

77 changes: 32 additions & 45 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include <irods/irods_re_ruleexistshelper.hpp>
#include "irods/private/storage_tiering/utilities.hpp"
#include <irods/irods_resource_backport.hpp>
#include "irods/private/storage_tiering/proxy_connection.hpp"

#include <irods/client_connection.hpp>
#include <irods/modAVUMetadata.h>
#include <irods/openCollection.h>
#include <irods/readCollection.h>
Expand Down Expand Up @@ -129,9 +129,7 @@ namespace {
addKeyVal(&data_obj_inp.condInput, RESC_NAME_KW, _source_resource.c_str());
addKeyVal(&data_obj_inp.condInput, DEST_RESC_NAME_KW, _destination_resource.c_str());

if(_comm->clientUser.authInfo.authFlag >= LOCAL_PRIV_USER_AUTH) {
addKeyVal(&data_obj_inp.condInput, ADMIN_KW, "");
}
addKeyVal(&data_obj_inp.condInput, ADMIN_KW, "");

transferStat_t* trans_stat{};
const auto repl_err = rcDataObjRepl(_comm, &data_obj_inp);
Expand Down Expand Up @@ -168,9 +166,7 @@ namespace {
&obj_inp.condInput,
COPIES_KW,
"1");
if(_comm->clientUser.authInfo.authFlag >= LOCAL_PRIV_USER_AUTH) {
addKeyVal(&obj_inp.condInput, ADMIN_KW, "");
}
addKeyVal(&obj_inp.condInput, ADMIN_KW, "");

const auto trim_err = rcDataObjTrim(_comm, &obj_inp);
if(trim_err < 0) {
Expand All @@ -197,12 +193,10 @@ namespace {
""};
const auto free_cond_input = irods::at_scope_exit{[&avuOp] { clearKeyVal(&avuOp.condInput); }};

if (_comm->clientUser.authInfo.authFlag >= LOCAL_PRIV_USER_AUTH) {
addKeyVal(&avuOp.condInput, ADMIN_KW, "");
}
addKeyVal(&avuOp.condInput, ADMIN_KW, "");

auto status = rcModAVUMetadata(_comm, &avuOp);
if(status < 0) {
if (status < 0) {
const auto msg = fmt::format("{}: failed to set access time for [{}]", __func__, _logical_path);
log_re::error(msg);
THROW(status, msg);
Expand Down Expand Up @@ -242,10 +236,10 @@ namespace {
const std::string& _object_path,
const std::string& _collection_type,
const std::string& _attribute) {
auto proxy_conn = irods::proxy_connection();
rcComm_t* comm = proxy_conn.make_rodsadmin_connection();
irods::experimental::client_connection conn;
RcComm& comm = static_cast<RcComm&>(conn);
if(_collection_type.size() == 0) {
update_access_time_for_data_object(comm, _object_path, _attribute);
update_access_time_for_data_object(&comm, _object_path, _attribute);
}
else {
// register a collection
Expand All @@ -255,15 +249,15 @@ namespace {
coll_inp.collName,
_object_path.c_str(),
MAX_NAME_LEN);
int handle = rcOpenCollection(comm, &coll_inp);
int handle = rcOpenCollection(&comm, &coll_inp);
if(handle < 0) {
THROW(
handle,
boost::format("failed to open collection [%s]") %
_object_path);
}

apply_access_time_to_collection(comm, handle, _attribute);
apply_access_time_to_collection(&comm, handle, _attribute);
}
} // set_access_time_metadata

Expand Down Expand Up @@ -439,16 +433,13 @@ namespace {
parser.set_string(source_hier);
parser.first_resc(source_resource);

auto proxy_conn = irods::proxy_connection();
rcComm_t* comm = proxy_conn.make_rodsadmin_connection();
irods::experimental::client_connection conn;
RcComm& comm = static_cast<RcComm&>(conn);

irods::storage_tiering st{comm, _rei, plugin_instance_name};
irods::storage_tiering st{&comm, _rei, plugin_instance_name};

st.migrate_object_to_minimum_restage_tier(
object_path,
_rei->rsComm->clientUser.userName,
_rei->rsComm->clientUser.rodsZone,
source_resource);
object_path, _rei->rsComm->clientUser.userName, _rei->rsComm->clientUser.rodsZone, source_resource);
}
else if("pep_api_data_obj_open_post" == _rn ||
"pep_api_data_obj_create_post" == _rn) {
Expand Down Expand Up @@ -488,15 +479,14 @@ namespace {
if(opened_objects.find(l1_idx) != opened_objects.end()) {
auto [object_path, resource_name] = opened_objects[l1_idx];

auto proxy_conn = irods::proxy_connection();
rcComm_t* comm = proxy_conn.make_rodsadmin_connection();
irods::experimental::client_connection conn;
RcComm& comm = static_cast<RcComm&>(conn);

irods::storage_tiering st{comm, _rei, plugin_instance_name};
st.migrate_object_to_minimum_restage_tier(
object_path,
_rei->rsComm->clientUser.userName,
_rei->rsComm->clientUser.rodsZone,
resource_name);
irods::storage_tiering st{&comm, _rei, plugin_instance_name};
st.migrate_object_to_minimum_restage_tier(object_path,
_rei->rsComm->clientUser.userName,
_rei->rsComm->clientUser.rodsZone,
resource_name);
}
}
}
Expand Down Expand Up @@ -675,13 +665,11 @@ irods::error exec_rule_text(
delay_obj["rule-engine-operation"] = irods::storage_tiering::policy::storage_tiering;
delay_obj["storage-tier-groups"] = rule_obj["storage-tier-groups"];

auto proxy_conn = irods::proxy_connection();
rcComm_t* comm = proxy_conn.make_rodsadmin_connection();
irods::experimental::client_connection conn;
RcComm& comm = static_cast<RcComm&>(conn);

irods::storage_tiering st{comm, rei, plugin_instance_name};
st.schedule_storage_tiering_policy(
delay_obj.dump(),
params);
irods::storage_tiering st{&comm, rei, plugin_instance_name};
st.schedule_storage_tiering_policy(delay_obj.dump(), params);
}
else {
return ERROR(
Expand Down Expand Up @@ -735,10 +723,10 @@ irods::error exec_rule_expression(
if(rule_obj.contains("rule-engine-operation") &&
irods::storage_tiering::policy::storage_tiering == rule_obj.at("rule-engine-operation")) {
try {
auto proxy_conn = irods::proxy_connection();
rcComm_t* comm = proxy_conn.make_rodsadmin_connection();
irods::experimental::client_connection conn;
RcComm& comm = static_cast<RcComm&>(conn);

irods::storage_tiering st{comm, rei, plugin_instance_name};
irods::storage_tiering st{&comm, rei, plugin_instance_name};
for(const auto& group : rule_obj["storage-tier-groups"]) {
st.apply_policy_for_tier_group(group);
}
Expand All @@ -759,11 +747,11 @@ irods::error exec_rule_expression(
const std::string& user_zone = rule_obj["user-zone"];
auto& pin = plugin_instance_name;

auto proxy_conn = irods::proxy_connection();
rcComm_t* comm = proxy_conn.make_rodsadmin_connection();
irods::experimental::client_connection conn;
RcComm& comm = static_cast<RcComm&>(conn);

// TODO(#297): Use get or get_ref for these parameters.
auto status = apply_data_movement_policy(comm,
auto status = apply_data_movement_policy(&comm,
plugin_instance_name,
rule_obj["object-path"],
rule_obj["user-name"],
Expand All @@ -774,7 +762,7 @@ irods::error exec_rule_expression(
rule_obj["preserve-replicas"],
rule_obj["verification-type"]);

irods::storage_tiering st{comm, rei, plugin_instance_name};
irods::storage_tiering st{&comm, rei, plugin_instance_name};
// TODO(#297): Use get or get_ref for these parameters.
status = apply_tier_group_metadata_policy(st,
rule_obj["group-name"],
Expand All @@ -791,7 +779,6 @@ irods::error exec_rule_expression(
_e.code(),
_e.what());
}

}
else {
return CODE(RULE_ENGINE_CONTINUE);
Expand Down
48 changes: 19 additions & 29 deletions src/storage_tiering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#include <irods/irods_resource_manager.hpp>
#include <irods/irods_resource_backport.hpp>
#include <irods/query_processor.hpp>
#include "irods/private/storage_tiering/proxy_connection.hpp"

#include <irods/client_connection.hpp>
#include <irods/modAVUMetadata.h>
#include <irods/rsExecMyRule.hpp>
#include <irods/execMyRule.h>
Expand Down Expand Up @@ -635,31 +635,27 @@ namespace irods {
object_is_processed[object_path] = 1;
}

auto proxy_conn = irods::proxy_connection();
rcComm_t* comm = proxy_conn.make_rodsadmin_connection();
irods::experimental::client_connection conn;
RcComm& comm = static_cast<RcComm&>(conn);

if(preserve_replicas) {
if(skip_object_in_lower_tier(
comm,
object_path,
_partial_list)) {
if (skip_object_in_lower_tier(&comm, object_path, _partial_list)) {
return;
}
}

queue_data_movement(
comm,
config_.instance_name,
_group_name,
object_path,
_results[2],
_results[3],
_results[4],
_source_resource,
_destination_resource,
get_verification_for_resc(comm, _destination_resource),
get_preserve_replicas_for_resc(comm, _source_resource),
get_data_movement_parameters_for_resource(comm, _source_resource));
queue_data_movement(&comm,
config_.instance_name,
_group_name,
object_path,
_results[2],
_results[3],
_results[4],
_source_resource,
_destination_resource,
get_verification_for_resc(&comm, _destination_resource),
get_preserve_replicas_for_resc(&comm, _source_resource),
get_data_movement_parameters_for_resource(&comm, _source_resource));

}; // job

Expand Down Expand Up @@ -989,9 +985,7 @@ namespace irods {
const_cast<char*>(access_time.c_str()),
const_cast<char*>(config_.migration_scheduled_flag.c_str())};

if (_comm->clientUser.authInfo.authFlag >= LOCAL_PRIV_USER_AUTH) {
addKeyVal(&set_op.condInput, ADMIN_KW, "");
}
addKeyVal(&set_op.condInput, ADMIN_KW, "");

if (const auto ec = rcModAVUMetadata(_comm, &set_op); ec < 0) {
const auto msg = fmt::format("{}: failed to set migration scheduled flag for [{}]", __func__, _object_path);
Expand All @@ -1017,9 +1011,7 @@ namespace irods {
const_cast<char*>(access_time.c_str()),
nullptr};

if (_comm->clientUser.authInfo.authFlag >= LOCAL_PRIV_USER_AUTH) {
addKeyVal(&set_op.condInput, ADMIN_KW, "");
}
addKeyVal(&set_op.condInput, ADMIN_KW, "");

if (const auto ec = rcModAVUMetadata(_comm, &set_op); ec < 0) {
const auto msg =
Expand Down Expand Up @@ -1078,9 +1070,7 @@ namespace irods {
const_cast<char*>(_group_name.c_str()),
const_cast<char*>(destination_replica_number.c_str())};

if (comm_->clientUser.authInfo.authFlag >= LOCAL_PRIV_USER_AUTH) {
addKeyVal(&set_op.condInput, ADMIN_KW, "");
}
addKeyVal(&set_op.condInput, ADMIN_KW, "");

auto status = rcModAVUMetadata(comm_, &set_op);
if (status < 0) {
Expand Down

0 comments on commit 885a78d

Please sign in to comment.