Revision ef8002fd

View differences:

include/cloud_helper.h
69 69
struct nodeID* get_cloud_node(struct cloud_helper_context *context);
70 70

  
71 71
/**
72
 * @brief Check if the specified node references the cloud
73
 * This function transparently handles the comparation of cloud nodes.
74
 * @param[in] context The contex representing the desired cloud_helper instance.
75
 * @param[in] node The supposed cloud node
76
 * @return 1 if cloud node, 0 otherwise
77
 */
78
int is_cloud_node(struct cloud_helper_context *context, struct nodeID* node);
79

  
80
/**
72 81
 * @brief Check for cloud responses.
73 82
 * Check if the some cloud GET operation has concluded. It sets a timeout to return at most after a given time.
74 83
 * @param[in] context The contex representing the desired cloud_helper instance.
src/Tests/Makefile
67 67
cloud_test: LDFLAGS += -ldl
68 68

  
69 69

  
70
libfilecloud.so: net_helpers.o
71
libfilecloud.so: ../net_helper$(NH_INCARNATION).o
70 72
libfilecloud.so: CFLAGS += -shared -pthread
71 73
libfilecloud.so: cloud_helper_delegate_file.o
72 74
	$(CC) $(CFLAGS) -o $@ $^
src/Tests/cloud_helper_delegate_file.c
14 14
  int (*get_from_cloud)(void *context, char *key, uint8_t *header_ptr, int header_size);
15 15
  int (*put_on_cloud)(void *context, char *key, uint8_t *buffer_ptr, int buffer_size);
16 16
  struct nodeID* (*get_cloud_node)(void *context);
17
  int (*is_cloud_node)(void *context, struct nodeID* node);
17 18
  int (*wait4cloud)(void *context, struct timeval *tout);
18 19
  int (*recv_from_cloud)(void *context, uint8_t *buffer_ptr, int buffer_size);
19 20
};
......
30 31
  struct mem_offset out_len[10];
31 32
  int out_cnt;
32 33
  int key_error;
34
  struct nodeID* cloud_node_base;
33 35
};
34 36

  
35 37

  
......
169 171
  sem_init(&ctx->sem, 0, 1);
170 172
  ctx->path = path;
171 173
  ctx->out_cnt = -1;
174
  ctx->cloud_node_base = create_node("0.0.0.0", 0);
172 175
  return ctx;
173 176
}
174 177

  
......
223 226

  
224 227
struct nodeID* file_cloud_get_cloud_node(void *context)
225 228
{
226
  return NULL;
229
  struct file_cloud_context *ctx;
230
  ctx = (struct file_cloud_context *)context;
231
  return ctx->cloud_node_base;
232
}
233

  
234
int file_cloud_is_cloud_node(void *context, struct nodeID* node)
235
{
236
  struct file_cloud_context *ctx;
237
  struct nodeID *candidate_node;
238
  int result = -1;
239
  ctx = (struct file_cloud_context *)context;
240
  candidate_node = create_node(node_ip(node), 0);
241

  
242
  result = nodeid_equal(ctx->cloud_node_base, candidate_node);
243
  nodeid_free(candidate_node);
244
  return result;
227 245
}
228 246

  
229 247
static int file_cloud_wait4cloud(void *context, struct timeval *tout)
......
283 301
  .get_from_cloud = &file_cloud_get_from_cloud,
284 302
  .put_on_cloud = &file_cloud_put_on_cloud,
285 303
  .get_cloud_node = &file_cloud_get_cloud_node,
304
  .is_cloud_node = &file_cloud_is_cloud_node,
286 305
  .wait4cloud = file_cloud_wait4cloud,
287 306
  .recv_from_cloud = file_cloud_recv_from_cloud
288 307
};
src/Tests/cloud_test.c
5 5
 *
6 6
 *  This is a small test program for the cloud interface
7 7
 *  To try the simple test: run it with
8
 *    ./cloud_test -c "provider=<cloud_provider>,<provider_opts>" [-g key | -p key=value]
8
 *    ./cloud_test -c "provider=<cloud_provider>,<provider_opts>" [-g key | -p key=value | -n | -e ip:port]
9 9
 *
10
 *    the "-g" and "-p" parameters select the GET or PUT operation
10
 *    -g  GET key from cloud
11
 *    -p  PUT key=value on cloud
12
 *    -n  print the cloud node
13
 *    -e  check if ip:port references the cloud
14
 *    -c  set the configuration of the cloud provider
11 15
 *
12 16
 *    For example, run
13 17
 *      ./cloud_test -c "provider=delegate,delegate_lib=libfilecloud.so" -p hello=world
......
26 30

  
27 31
#define GET 0
28 32
#define PUT 1
33
#define GET_CLOUD_NODE 2
34
#define EQ_CLOUD_NODE 3
29 35

  
30 36
static const char *config;
31 37
static int operation;
......
40 46
  int o;
41 47
  char *temp;
42 48
      
43
  while ((o = getopt(argc, argv, "c:g:p:")) != -1) {
49
  while ((o = getopt(argc, argv, "c:g:p:ne:")) != -1) {
44 50
    switch(o) {
45 51
    case 'c':
46 52
      config = strdup(optarg);
......
61 67
      case 'g':
62 68
        key =  strdup(optarg);
63 69
        break;
64
      default:
70
    case 'n':
71
      operation = GET_CLOUD_NODE;
72
      break;
73
    case 'e':
74
      operation = EQ_CLOUD_NODE;
75
      temp = strdup(optarg);
76
      
77
      key = strsep(&optarg, ":");
78
      value = optarg;
79

  
80

  
81
      if (!value || !key){
82
	printf("Expected ip:port for option -e");
83
	free(temp);
84
	exit(-1);
85
      }  
86
      break;
87
    default:
65 88
        fprintf(stderr, "Error: unknown option %c\n", o);
66 89

  
67 90
        exit(-1);
......
96 119
  struct cloud_helper_context *cloud;
97 120
  char buffer[100];
98 121
  int err;
122
  struct nodeID *t;
99 123
  struct timeval tout = {10, 0};
100 124

  
101 125
  cmdline_parse(argc, argv);
......
142 166
      printf("No value for the specified key. Received: %s\n", buffer);
143 167
      return 1;      
144 168
    }
169
    break;
170
  case GET_CLOUD_NODE:
171
    printf("Cloud node: %s\n", node_addr(get_cloud_node(cloud)));
172
    break;
173
  case EQ_CLOUD_NODE:
174
    t = create_node(key, atoi(value));
175
    printf("Node %s references cloud? %d\n", node_addr(get_cloud_node(cloud)),
176
	   is_cloud_node(cloud, t));
177
    break;
145 178
  }
146 179

  
147 180

  
src/TopologyManager/cloud_helper.c
87 87
  return context->ch->get_cloud_node(context->ch_context);
88 88
}
89 89

  
90
int is_cloud_node(struct cloud_helper_context *context, struct nodeID* node)
91
{
92
  return context->ch->is_cloud_node(context->ch_context, node);
93
}
94

  
90 95
int wait4cloud(struct cloud_helper_context *context, struct timeval *tout)
91 96
{
92 97
  return context->ch->wait4cloud(context->ch_context, tout);
src/TopologyManager/cloud_helper_delegate.c
10 10
  int (*get_from_cloud)(void *context, char *key, uint8_t *header_ptr, int header_size);
11 11
  int (*put_on_cloud)(void *context, char *key, uint8_t *buffer_ptr, int buffer_size);
12 12
  struct nodeID* (*get_cloud_node)(void *context);
13
  int (*is_cloud_node)(void *context, struct nodeID* node);
13 14
  int (*wait4cloud)(void *context, struct timeval *tout);
14 15
  int (*recv_from_cloud)(void *context, uint8_t *buffer_ptr, int buffer_size);
15 16
};
......
66 67
  return context->delegate->get_cloud_node(context->delegate_context);
67 68
}
68 69

  
70
int delegate_is_cloud_node(struct cloud_helper_impl_context *context, struct nodeID* node)
71
{
72
  return context->delegate->is_cloud_node(context->delegate_context, node);
73
}
74

  
69 75
static int delegate_cloud_wait4cloud(struct cloud_helper_impl_context *context, struct timeval *tout)
70 76
{
71 77
  return context->delegate->wait4cloud(context->delegate_context, tout);
......
81 87
  .get_from_cloud = delegate_cloud_get_from_cloud,
82 88
  .put_on_cloud = delegate_cloud_put_on_cloud,
83 89
  .get_cloud_node = delegate_cloud_get_cloud_node,
90
  .is_cloud_node = delegate_is_cloud_node,
84 91
  .wait4cloud = delegate_cloud_wait4cloud,
85 92
  .recv_from_cloud = delegate_cloud_recv_from_cloud,
86 93
};
src/TopologyManager/cloud_helper_iface.h
10 10
  int (*get_from_cloud)(struct cloud_helper_impl_context *context, char *key, uint8_t *header_ptr, int header_size);
11 11
  int (*put_on_cloud)(struct cloud_helper_impl_context *context, char *key, uint8_t *buffer_ptr, int buffer_size);
12 12
  struct nodeID* (*get_cloud_node)(struct cloud_helper_impl_context *context);
13
  int (*is_cloud_node)(struct cloud_helper_impl_context *context, struct nodeID* node);
13 14
  int (*wait4cloud)(struct cloud_helper_impl_context *context, struct timeval *tout);
14 15
  int (*recv_from_cloud)(struct cloud_helper_impl_context *context, uint8_t *buffer_ptr, int buffer_size);
15 16
};

Also available in: Unified diff