|
@@ -284,29 +284,26 @@ int myco_daemon_unregister_resource(message msg) {
|
|
|
int myco_daemon_request_resource(message msg) {
|
|
|
myco_resource *current_resource;
|
|
|
|
|
|
- // Check if resource exists
|
|
|
- if ((current_resource = myco_daemon_find_resource(msg.resource_name)) == NULL) {
|
|
|
- sprintf(msg.message, "ERROR: resource %s does not exist\n", msg.resource_name);
|
|
|
- myco_send(msg.agent_message_queue_id, msg);
|
|
|
- return -1;
|
|
|
- }
|
|
|
- // Check if agent that requests already owns the resource
|
|
|
- if (strcmp(current_resource->agent, msg.agent_name) == 0) {
|
|
|
- sprintf(msg.message, "ERROR: resource %s already belongs to agent %s\n", msg.resource_name, msg.agent_name);
|
|
|
- myco_send(msg.agent_message_queue_id, msg);
|
|
|
- return -1;
|
|
|
- }
|
|
|
- // Check if resource is transactional
|
|
|
- if (current_resource->transactional != RESOURCE_TRANSACTIONAL) {
|
|
|
- sprintf(msg.message, "ERROR: resource %s is not transactional\n", msg.resource_name);
|
|
|
- myco_send(msg.agent_message_queue_id, msg);
|
|
|
- return -1;
|
|
|
- }
|
|
|
-
|
|
|
- // Check if resource resides on same node
|
|
|
- //printf("\n The adress is: %s\n", inet_ntoa(*(struct in_addr *)¤t_resource->node_ip));
|
|
|
+ // Check if resource exists on this node
|
|
|
+ if ((current_resource = myco_daemon_find_resource(msg.resource_name)) != NULL) {
|
|
|
+ // Check if agent that requests already owns the resource
|
|
|
+ if (strcmp(current_resource->agent, msg.agent_name) == 0) {
|
|
|
+ sprintf(msg.message, "ERROR: resource %s already belongs to agent %s\n", msg.resource_name, msg.agent_name);
|
|
|
+ myco_send(msg.agent_message_queue_id, msg);
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ // Check if resource is transactional
|
|
|
+ if (current_resource->transactional != RESOURCE_TRANSACTIONAL) {
|
|
|
+ sprintf(msg.message, "ERROR: resource %s is not transactional\n", msg.resource_name);
|
|
|
+ myco_send(msg.agent_message_queue_id, msg);
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Check if resource resides on same node
|
|
|
+ // printf("\n The adress is: %s\n", inet_ntoa(*(struct in_addr *)¤t_resource->node_ip));
|
|
|
+ // if (current_resource->node_ip == myco_daemon_node_ip) {
|
|
|
+
|
|
|
|
|
|
- if (current_resource->node_ip == myco_daemon_node_ip) {
|
|
|
// If on same node, send information
|
|
|
msg.sender_pid = current_resource->pid;
|
|
|
msg.resource_size = current_resource->size;
|
|
@@ -325,7 +322,22 @@ int myco_daemon_request_resource(message msg) {
|
|
|
return -1;
|
|
|
}
|
|
|
} else {
|
|
|
- // TODO: Handle case where resource is on another node
|
|
|
+ // Handle case where resource is on another node
|
|
|
+ // TODO: Request Resource information from indexer
|
|
|
+
|
|
|
+ // fetch resource
|
|
|
+ void *local_resource_pointer;
|
|
|
+ int local_resource_size;
|
|
|
+ char resource_name[RESOURCE_NAME_LENGTH];
|
|
|
+
|
|
|
+ myco_network_fetch_resource(local_resource_pointer, resource_name, local_resource_size);
|
|
|
+
|
|
|
+ // if no resource registered with indexer:
|
|
|
+ if (0 == 1) {
|
|
|
+ sprintf(msg.message, "ERROR: resource %s does not exist\n", msg.resource_name);
|
|
|
+ myco_send(msg.agent_message_queue_id, msg);
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|