Exemple #1
0
JNIEXPORT jint JNICALL
Java_com_sun_netstorage_samqfs_mgmt_fs_Host_addHosts(JNIEnv *env,
    jclass cls /*ARGSUSED*/, jobject ctx, jstring fsName,
    jobjectArray hostInfos, jstring options) {

	jboolean isCopy1, isCopy2;
	char *cstr1 = GET_STR(fsName, isCopy1);
	char *cstr2 = GET_STR(options, isCopy2);
	int ret;
	sqm_lst_t *lst;
	int len;
	int i;

	PTRACE(1, "jni:Host_addHosts(%s...) entry", Str(cstr1));

	lst = jarray2lst(env, hostInfos, BASEPKG"/fs/Host", Host2host);

	if (lst == NULL) {
		REL_STR(fsName, cstr1, isCopy1);
		REL_STR(options, cstr2, isCopy2);
		ThrowEx(env);
		return (NULL);
	}

	ret = add_hosts(CTX, cstr1, lst, cstr2);

	REL_STR(fsName, cstr1, isCopy1);
	REL_STR(options, cstr2, isCopy2);
	free_list_of_host_info(lst);
	if (-1 == ret) {
		ThrowEx(env);
		return (NULL);
	}


	PTRACE(1, "jni:Host_add_hosts() done");
	return (ret);
}
Exemple #2
0
int 
main(int argc, const char** argv){
  ndb_init();
  int help = 0;
  const char *cmd=0, *name=0, *group=0, *owner=0;
  int list = 0, start = 0, stop = 0, rm = 0;
  struct getargs args[] = {
    { "cmd", 'c', arg_string, &cmd, "command", "command to run (default ls)" }
    ,{ "name", 'n', arg_string, &name, 
       "apply command for all processes with name" }
    ,{ "group", 'g', arg_string, &group, 
       "apply command for all processes in group" }
    ,{ "owner", 'g', arg_string, &owner,
       "apply command for all processes with owner" }
    ,{ "long", 'l', arg_flag, &g_settings.m_longl, "long", "long listing"}
    ,{ "usage", '?', arg_flag, &help, "Print help", "" }
    ,{ "ls",  0, arg_flag, &list, "-c list", "list process(es)" }
    ,{ "start", 0, arg_flag, &start, "-c start", "start process(es)" }
    ,{ "stop",  0, arg_flag, &stop, "-c stop", "stop process(es)" }
    ,{ "rm",    0, arg_flag, &rm, "-c rm", "undefine process(es)" }
  };
  const int num_args = 10;
  int i; 
  int optind = 0;
  char desc[] = "[host:[port]]\n";
  
  if(getarg(args, num_args, argc, argv, &optind) || help) {
    arg_printusage(args, num_args, argv[0], desc);
    return 1;
  }

  if(list + start + stop + rm > 1){
    ndbout_c("Can only specify one command");
    arg_printusage(args, num_args, argv[0], desc);
    return 1;
  }
  
  if(list) cmd = "list";
  if(start) cmd = "start";
  if(stop) cmd = "stop";
  if(rm) cmd = "rm";
  if(!cmd) cmd = "list";
  
  Expression * m_expr = 0;

  for(i = optind; i<argc; i++){
    add_host(g_hosts, argv[i]);
  }

  OrExpr * orE = new OrExpr(new Operate(cmd, g_settings), true);
  m_expr = orE;
  for(i = optind; i<argc; i++){
    BaseString tmp(argv[i]);
    Vector<BaseString> split;
    tmp.split(split, ":");
    
    if(split.size() > 2){
      Uint32 id = atoi(split[2].c_str());
      orE->push_back(new ProcEQ(g_hosts[i-optind], id));	
    }
  }

  if(g_hosts.size() == 0){
    char buf[1024];
    if(NdbEnv_GetEnv(ENV_HOSTS, buf, sizeof(buf))){
      add_hosts(g_hosts, BaseString(buf));
    }
  }
  
  if(g_hosts.size() == 0){
    g_hosts.push_back(new SimpleCpcClient("localhost", g_settings.m_port));
  }
  
  if(group != 0){
    Expression * tmp = new FieldEQ("group", group);
    m_expr = new Match(* tmp, * m_expr);
  }
  
  if(name != 0){
    Expression * tmp = new FieldEQ("name", name);
    m_expr = new Match(* tmp, * m_expr);
  }

  if(owner != 0){
    Expression * tmp = new FieldEQ("owner", owner);
    m_expr = new Match(* tmp, * m_expr);
  }

  connect(g_hosts);
  for_each(g_hosts, * m_expr);
  
  return 0;
}