Example #1
0
HOT_INLINE
hot_err_t hot_ens_Cast(
    hot_context_t s,
    hot_msg_t msg, 
    hot_ens_MsgSendView *send_view	/*OUT*/
) {
    begin_write(); {
	begin_critical(); {
	    if (s->leaving) {
		hot_sys_Panic("hot_ens_Cast: member is leaving") ;
	    }

	    if (send_view != NULL) {
		*send_view = (s->blocked) ?
		    HOT_ENS_MSG_SEND_NEXT_VIEW : HOT_ENS_MSG_SEND_CURRENT_VIEW ;
	    }  
	} end_critical() ;
	
	/* Write the downcall.
	 */
	write_hdr(s,DN_CAST);
	write_msg(msg);
    } end_write();
    
    return HOT_OK ;
}
Example #2
0
HOT_INLINE
static void cb_Block(
    hot_contextID_t id, 
    unsigned *cs
) {
    hot_context_t s;
    void *env;
    hot_ens_Block_cback block;

    begin_critical(); {
	s = lookup_context(id);
	env = s->env;
	block = s->conf.block;
	s->blocked = 1;
    } end_critical();

    if (block != NULL) {
	(*block)(s, env);
    }

    /* Write the block_ok downcall.
     */
    begin_write(); {
	write_hdr(s,DN_BLOCK_OK) ;
    } end_write();
}
Example #3
0
bool SAS::Connection::connect_init()
{
  int rc;
  struct sockaddr_in addr;

  LOG_STATUS("Attempting to connect to SAS %s", _sas_address.c_str());

  if ((_sock = ::socket(AF_INET, SOCK_STREAM, 0)) == -1)
  {
    LOG_ERROR("Failed to open SAS socket: %d (%s)\n", errno, ::strerror(errno));
    return false;
  }

  memset(&addr, 0, sizeof(addr));
  addr.sin_family = AF_INET;
  addr.sin_port = htons(SAS_PORT);
  addr.sin_addr.s_addr = inet_addr(_sas_address.c_str());

  rc = ::connect(_sock, (struct sockaddr*)&addr, sizeof(addr));

  if (rc != 0)
  {
    LOG_ERROR("Failed to connect to SAS %s:%d : %d %s\n", _sas_address.c_str(), SAS_PORT, errno, ::strerror(errno));
    ::close(_sock);
    return false;
  }

  LOG_DEBUG("Connected SAS socket to %s:%d", _sas_address.c_str(), SAS_PORT);

  // Send an init message to SAS.
  std::string init;
  std::string version("v0.1");
  int init_len = INIT_HDR_SIZE + sizeof(uint8_t) + _system_name.length() + sizeof(uint32_t) + sizeof(uint8_t) + version.length();
  init.reserve(init_len);
  write_hdr(init, init_len, SAS_MSG_INIT);
  write_int8(init, (uint8_t)_system_name.length());
  write_data(init, _system_name.length(), _system_name.data());
  int endianness = 1;
  init.append((char*)&endianness, sizeof(int));     // Endianness must be written in machine order.
  write_int8(init, version.length());
  write_data(init, version.length(), version.data());

  LOG_DEBUG("Sending SAS INIT message");

  rc = ::send(_sock, init.data(), init.length(), 0);
  if (rc < 0)
  {
    LOG_ERROR("SAS connection to %s:%d failed: %d %s", _sas_address.c_str(), SAS_PORT, errno, ::strerror(errno));
    return false;
  }

  LOG_STATUS("Connected to SAS %s:%d", _sas_address.c_str(), SAS_PORT);

  return true;
}
Example #4
0
/* Join a group.  The group context is returned in *contextp.  
 */
hot_err_t hot_ens_Join(
    hot_ens_JoinOps_t *jops,
    hot_context_t *contextp	/*OUT*/ 
) {
    hot_err_t err = HOT_OK ;
    hot_context_t s ;

    /* Initialize global state if not done so already.
     */
    if (!g.initialized) {
	err = hot_ens_Init(jops->outboard, jops->argv); 
	if (err != HOT_OK)
	    return err;
    }

    begin_write(); {    
	begin_critical(); {    
	    /* Allocate a new group context 
	     * Initialize the group record.
	     */
	    s = alloc_context();
	    s->joining = 1 ;
	    s->leaving = 0 ;
	    s->conf = jops->conf;
	    s->env = jops->env;
	    s->view = NULL ;
	    *contextp = s ;
	} end_critical();
	
	/* Write the downcall.
	 */
  	write_hdr(s,DN_JOIN);
	write_int(jops->heartbeat_rate);
	write_string(jops->transports);
	write_string(jops->protocol);
	write_string(jops->group_name);
	write_string(jops->properties);
	write_bool(jops->use_properties);
	write_bool(jops->groupd);
	write_string(jops->params);
	write_bool(jops->client);
	write_bool(jops->debug);

	if (jops->endpt.name[0] != 0x0) {
	    hot_sys_Warning("HOT_OUTBOARD does not support 'endpt' in join ops") ;
	    jops->endpt.name[0] = 0x0;
	}
	write_string(jops->princ);
	write_string(jops->key);
	write_bool(jops->secure);

    } end_write();

    return HOT_OK;
}
Example #5
0
static void write_graph(Agraph_t * g, GVJ_t * job, int top, state_t* sp)
{
    Agnode_t* np; 
    Agedge_t* ep; 
    int ncnt = 0;
    int ecnt = 0;
    int sgcnt = 0;
    int has_subgs;
    Dt_t* map;

    if (top) {
	map = dtopen (&intDisc, Dtoset);
	aginit(g, AGNODE, ID, sizeof(gvid_t), FALSE);
	aginit(g, AGEDGE, ID, sizeof(gvid_t), FALSE);
	aginit(g, AGRAPH, ID, -((int)sizeof(gvid_t)), FALSE);
	sgcnt = label_subgs(g, sgcnt, map);
	for (np = agfstnode(g); np; np = agnxtnode(g,np)) {
	    if (IS_CLUSTER(np)) {
		ND_gid(np) = lookup(map, agnameof(np));
	    }
	    else {
		ND_gid(np) = sgcnt + ncnt++;
	    }
	    for (ep = agfstout(g, np); ep; ep = agnxtout(g,ep)) {
		ED_gid(ep) = ecnt++;
	    }
	}
	dtclose(map);
    }

    indent(job, sp->Level++);
    gvputs(job, "{\n");
    write_hdr(g, job, top, sp);
    write_attrs((Agobj_t*)g, job, sp);
    if (top) {
	gvputs(job, ",\n");
	indent(job, sp->Level);
	gvprintf(job, "\"_subgraph_cnt\": %d", sgcnt);
    } else {
	gvputs(job, ",\n");
	indent(job, sp->Level);
	gvprintf(job, "\"_gvid\": %d", GD_gid(g));
    }
    has_subgs = write_subgs(g, job, top, sp);
    write_nodes (g, job, top, has_subgs, sp);
    write_edges (g, job, top, sp);
    gvputs(job, "\n");
    sp->Level--;
    indent(job, sp->Level);
    if (top)
	gvputs(job, "}\n");
    else
	gvputs(job, "}");
}
Example #6
0
/* Request a Rekey operation.
 */
hot_err_t hot_ens_Rekey(
    hot_context_t s
) {
    begin_write(); {
	begin_critical(); {
	    if (s->leaving) {
		hot_sys_Panic("hot_ens_Rekey: member is leaving") ;
	    }
	} end_critical();
	write_hdr(s,DN_REKEY);
    } end_write();
    return HOT_OK;
}
Example #7
0
/* Request a new view to be installed.
 */
hot_err_t hot_ens_RequestNewView(
    hot_context_t s
) {
    begin_write(); {
	begin_critical(); {
	    if (s->leaving) {
		hot_sys_Panic("hot_ens_RequestNewView: member is leaving") ;
	    }
	} end_critical();
	write_hdr(s,DN_PROMPT);
    } end_write();
    return HOT_OK;
}
Example #8
0
/* Inform Ensemble that the state-transfer is complete. 
 */
hot_err_t hot_ens_XferDone(
    hot_context_t s
) {
    begin_write(); {
	begin_critical(); {
	    if (s->leaving) {
		hot_sys_Panic("hot_ens_XferDone: member is leaving") ;
	    }
	} end_critical();
	write_hdr(s,DN_XFERDONE);
    } end_write();
    return HOT_OK;
}
Example #9
0
HOT_INLINE
hot_err_t hot_ens_Send(
    hot_context_t s, 
    hot_endpt_t *dest,
    hot_msg_t msg,
    hot_ens_MsgSendView *send_view /*OUT*/
) {
    begin_write(); { 
	begin_critical(); {
	    if (s->leaving) {
		hot_sys_Panic("hot_ens_Send: member is leaving") ;
	    }

	    if (send_view != NULL) {
		*send_view = (s->blocked) ?
		    HOT_ENS_MSG_SEND_NEXT_VIEW : HOT_ENS_MSG_SEND_CURRENT_VIEW ;
	    }
	} end_critical() ;

	if (s->blocked) {
	    write_hdr(s,DN_SEND_BLOCKED);
	    write_endpID(dest);
	    write_msg(msg);
	} else {
 	    unsigned i ;
	    begin_critical(); {
		for (i=0;i<s->nmembers;i++) {
		    if (!strcmp(s->view[i].name,dest->name))
			break ;
		}
		assert(i<s->nmembers) ;
	    } end_critical() ;
	    write_hdr(s,DN_SEND);
	    write_int(i);
	    write_msg(msg);
	}
    } end_write();
    return HOT_OK;
}
Example #10
0
void SAS::associate_trails(TrailId trail_a,
                           TrailId trail_b,
                           Marker::Scope scope)
{
  std::string trail_assoc_msg;
  write_hdr(trail_assoc_msg, 29, SAS_MSG_TRAIL_ASSOC, get_current_timestamp());
  write_trail(trail_assoc_msg, trail_a);
  write_trail(trail_assoc_msg, trail_b);
  write_int8(trail_assoc_msg, (uint8_t)scope);
  if (_connection)
  {
    _connection->send_msg(trail_assoc_msg);
  }
}
Example #11
0
/* Request a protocol change specifying properties.
 */
hot_err_t hot_ens_ChangeProperties(
    hot_context_t s,
    char *properties
) {
    assert(properties) ;
    begin_write(); {
	begin_critical(); {
	    if (s->leaving) {
		hot_sys_Panic("hot_ens_ChangeProperties: member is leaving") ;
	    }
	} end_critical();
	write_hdr(s,DN_PROPERTIES);
	write_string(properties); 
    } end_write();
    return HOT_OK;
}
Example #12
0
/* Request a protocol change.
 */
hot_err_t hot_ens_ChangeProtocol(
    hot_context_t s,
    char *protocol
) {
    assert(protocol);
    begin_write(); {
	begin_critical(); {
	    if (s->leaving) {
		hot_sys_Panic("hot_ens_ChangeProtocol: member is leaving") ;
	    }
	} end_critical();
	write_hdr(s,DN_PROTOCOL);
	write_string(protocol); 
    } end_write();
    return HOT_OK;
}
Example #13
0
/* Report group members as failure-suspected.
 * 
 * NB:  In the initial implementation, this downcall will not be supported.
 *      (if invoked, an exeption will be raised by OCAML).
 */
hot_err_t hot_ens_Suspect(
    hot_context_t s,
    hot_endpt_t *suspects, 
    int nsuspects
) {
    begin_write(); {
	begin_critical(); {
	    if (s->leaving) {
		hot_sys_Panic("hot_ens_Suspect: member is leaving") ;
	    }
	} end_critical();
	write_hdr(s,DN_SUSPECT);
	write_endpList(nsuspects, suspects);
    } end_write();
    return HOT_OK;
}
Example #14
0
/* Leave a group.  This should be the last call made to a given context.
 * No more events will be delivered to this context after the call
 * returns.  
 */
hot_err_t hot_ens_Leave(
    hot_context_t s
) {
    begin_write(); {
	begin_critical(); {
	    if (s->leaving) {
		hot_sys_Panic("hot_ens_Leave:this member is already leaving") ;
	    }
	    s->leaving = 1 ;
	} end_critical();
	    
	/* Write the downcall.
	 */
	write_hdr(s,DN_LEAVE);
    } end_write();
    
    return HOT_OK;
}
Example #15
0
bool SAS::Connection::connect_init()
{
  if (_socket_callback)
  {
    _sock = _socket_callback(_sas_address.c_str(), SAS_PORT);
  }
  else
  {
    _sock = get_local_sock(_sas_address.c_str(), SAS_PORT);
  }

  if (_sock < 0)
  {
    return false;
  }
 
  SAS_LOG_DEBUG("Connected SAS socket to %s:%s", _sas_address.c_str(), SAS_PORT);
  set_send_timeout(_sock, SEND_TIMEOUT);

  // Send an init message to SAS.
  std::string init;
  std::string version("v0.1");

  // The resource version is part of the binary protocol but is not currently
  // exposed over the C++ API.
  std::string resource_version("");

  int init_len = INIT_HDR_SIZE +
                 sizeof(uint8_t) + _system_name.length() +
                 sizeof(uint32_t) +
                 sizeof(uint8_t) + version.length() +
                 sizeof(uint8_t) + _system_type.length() +
                 sizeof(uint8_t) + _resource_identifier.length() +
                 sizeof(uint8_t) + resource_version.length();
  init.reserve(init_len);
  write_hdr(init, init_len, SAS_MSG_INIT, get_current_timestamp());
  write_int8(init, (uint8_t)_system_name.length());
  write_data(init, _system_name.length(), _system_name.data());
  int endianness = 1;
  init.append((char*)&endianness, sizeof(int)); // Endianness must be written in machine order.
  write_int8(init, version.length());
  write_data(init, version.length(), version.data());
  write_int8(init, (uint8_t)_system_type.length());
  write_data(init, _system_type.length(), _system_type.data());
  write_int8(init, (uint8_t)_resource_identifier.length());
  write_data(init, _resource_identifier.length(), _resource_identifier.data());
  write_int8(init, (uint8_t)resource_version.length());
  write_data(init, resource_version.length(), resource_version.data());

  SAS_LOG_DEBUG("Sending SAS INIT message");

  int rc = ::send(_sock, init.data(), init.length(), 0);
  if (rc < 0)
  {
    SAS_LOG_ERROR("SAS connection to %s:%s failed: %d %s", _sas_address.c_str(), SAS_PORT, errno, ::strerror(errno));
    ::close(_sock);
    _sock = -1;
    return false;
  }

  SAS_LOG_STATUS("Connected to SAS %s:%s", _sas_address.c_str(), SAS_PORT);

  return true;
}