Esempio n. 1
0
static void
rwmsgbroker__component__instance_start(RwTaskletPluginComponent *self,
					RwTaskletPluginComponentHandle *h_component,
					RwTaskletPluginInstanceHandle *h_instance)
{
  rwmsgbroker_component_ptr_t component;
  rwmsgbroker_instance_ptr_t instance;
  rwcal_module_ptr_t rwcal;

  // Validate input parameters
  component = (rwmsgbroker_component_ptr_t) h_component->priv;
  RW_CF_TYPE_VALIDATE(component, rwmsgbroker_component_ptr_t);
  instance = (rwmsgbroker_instance_ptr_t) h_instance->priv;
  RW_CF_TYPE_VALIDATE(instance, rwmsgbroker_instance_ptr_t);

  // The instance is started so print a debug message
  RWTRACE_INFO(instance->rwtasklet_info->rwtrace_instance,
	             RWTRACE_CATEGORY_RWTASKLET,
	             "RW.MsgBroker -- Tasklet [%d] is started on VM [%d]!",
               instance->rwtasklet_info->identity.rwtasklet_instance_id, //0);
               instance->rwtasklet_info->rwvcs->identity.rwvm_instance_id);

  rwvcs_instance_ptr_t rwvcs = instance->rwtasklet_info->rwvcs;
  RW_ASSERT(rwvcs);
  int rwvm_instance_id = rwvcs->identity.rwvm_instance_id;
  RW_ASSERT(rwvcs->pb_rwmanifest
            && rwvcs->pb_rwmanifest->init_phase
            && rwvcs->pb_rwmanifest->init_phase->settings
            && rwvcs->pb_rwmanifest->init_phase->settings->rwmsg);
  int multi_broker = (rwvcs->pb_rwmanifest->init_phase->settings->rwmsg->multi_broker &&
                      rwvcs->pb_rwmanifest->init_phase->settings->rwmsg->multi_broker->has_enable &&
                      rwvcs->pb_rwmanifest->init_phase->settings->rwmsg->multi_broker->enable);

  char *ext_ip_address = instance->rwtasklet_info->rwvcs->identity.vm_ip_address;
  RWTRACE_INFO(instance->rwtasklet_info->rwtrace_instance,
               RWTRACE_CATEGORY_RWTASKLET,
               "RW.MsgBroker -- Tasklet [%d] is started on VM [%d] ip-addr [%s] multi_broker [%d]!\n",
               instance->rwtasklet_info->identity.rwtasklet_instance_id,
               rwvm_instance_id, ext_ip_address,
               multi_broker);

  int sid = 1;
  rwcal = ((rwvx_instance_t*)(instance->rwtasklet_info->rwvx))->rwcal_module;
  instance->broker = rwmsg_broker_create(sid,
                                         (multi_broker?rwvm_instance_id:0),
                                         ext_ip_address,
                                         instance->rwtasklet_info->rwsched_instance,
                                         instance->rwtasklet_info->rwsched_tasklet_info,
                                         rwcal,
                                         rwtasklet_info_is_collapse_thread(instance->rwtasklet_info), /* mainq */
                                         instance->rwtasklet_info->rwmsg_endpoint,
                                         instance->rwtasklet_info);

  RW_ASSERT(instance->broker);

  rw_status_t rs;
  rs = rwmsg_broker_dts_registration (instance);
  RW_ASSERT(rs == RW_STATUS_SUCCESS);
}
Esempio n. 2
0
static rw_status_t bootstrap_rwproc(struct rwmain_gi * rwmain)
{
  rw_status_t status;
  char * self_id = NULL;

  RWTRACE_INFO(
      rwmain->rwvx->rwtrace,
      RWTRACE_CATEGORY_RWMAIN,
      "Performing bootstrap of RWPROC %s",
      rwmain->component_name);

  status = RW_STATUS_SUCCESS;
  if (!rwmain->rwvx->rwvcs->pb_rwmanifest->bootstrap_phase->rwproc)
    goto done;

  self_id = to_instance_name(rwmain->component_name, rwmain->instance_id);

  for (size_t i = 0; i < rwmain->rwvx->rwvcs->pb_rwmanifest->bootstrap_phase->rwproc->n_instances; ++i) {
    vcs_manifest_action action;
    vcs_manifest_action_start start;

    vcs_manifest_action__init(&action);
    vcs_manifest_action_start__init(&start);

    action.start = &start;
    start.component_name = rwmain->rwvx->rwvcs->pb_rwmanifest->bootstrap_phase->rwproc->instances[i]->component_name;
    start.has_config_ready = rwmain->rwvx->rwvcs->pb_rwmanifest->bootstrap_phase->rwproc->instances[i]->has_config_ready;
    start.config_ready = rwmain->rwvx->rwvcs->pb_rwmanifest->bootstrap_phase->rwproc->instances[i]->config_ready;
#if 0
    start.has_recovery_action = true;
    start.recovery_action = RWVCS_TYPES_RECOVERY_TYPE_RESTART;
#else
    start.has_recovery_action = rwmain->rwvx->rwvcs->pb_rwmanifest->bootstrap_phase->rwproc->instances[i]->has_recovery_action;
    start.recovery_action = rwmain->rwvx->rwvcs->pb_rwmanifest->bootstrap_phase->rwproc->instances[i]->recovery_action;
#endif

    status = rwmain_action_run(rwmain, self_id, &action);

    action.start = NULL;
    start.component_name = NULL;
    protobuf_free_stack(action);
    protobuf_free_stack(start);
  }

done:
  if (self_id)
    free(self_id);

  RWTRACE_INFO(
      rwmain->rwvx->rwtrace,
      RWTRACE_CATEGORY_RWMAIN,
      "Bootstrap of RWPROC complete");

  return status;
}
Esempio n. 3
0
rw_status_t
rwvcs_variable_list_evaluate(rwvcs_instance_ptr_t instance,
                             size_t n_variable,
                             char **variable)
{
  int i;
  char *expression;
  rw_status_t status = RW_STATUS_SUCCESS;

  // Validate input parameters
  RW_CF_TYPE_VALIDATE(instance, rwvcs_instance_ptr_t);

  // Evaluate each variable in the list
  for (i = 0 ; i < n_variable ; i++) {
    expression = variable[i];
    RWTRACE_INFO(instance->rwvx->rwtrace,
                 RWTRACE_CATEGORY_RWVCS,
                 "Variable list evaluate - expression = %s\n",
                 expression);
    status = instance->rwpython_util.iface->python_run_string(
        instance->rwpython_util.cls,
        expression);
    RW_ASSERT(status == RW_STATUS_SUCCESS);
  }

  // The variable list evaluation was successful
  return RW_STATUS_SUCCESS;
}
Esempio n. 4
0
rw_status_t
rwdts_api_appconf_group_create(rwdts_api_t*            apih,
                               rwdts_xact_t*           xact,
                               appconf_xact_init       init,
                               appconf_xact_deinit     deinit,
                               appconf_config_validate validate,
                               appconf_config_apply    apply,
                               void*                   user_data,
                               rwdts_appconf_t**       appconf) {
  RW_ASSERT(appconf);
  if (!appconf) {
    return RW_STATUS_FAILURE;
  }
  rwdts_appconf_cbset_t cb = {
    .xact_init       = init,
    .xact_deinit     = deinit,
    .config_validate = validate,
    .config_apply    = apply,
    .ctx             = user_data,
  };

  *appconf = rwdts_appconf_group_create(apih, xact, &cb);

  if (*appconf == NULL) {
    RWTRACE_INFO(apih->rwtrace_instance,
                 RWTRACE_CATEGORY_RWTASKLET,
                 "%s: Invoking state change callback", apih->client_path);
    return (RW_STATUS_FAILURE);
  }

  return (RW_STATUS_SUCCESS);
}
Esempio n. 5
0
/*
 * Initializes the RW.CLI controller.
 */
static void controller_init(rwcli_controller_t* inst)
{
  memset(inst, 0, sizeof(rwcli_controller_t));

  // Initialize the trace module and set appropriate severity
  controller_init_trace(inst);

  // Allocate the receive buffer
  inst->recv_buf = (uint8_t*)calloc(sizeof(uint8_t), RW_CLI_MAX_BUF);
  inst->recv_buf_len = RW_CLI_MAX_BUF;

  if (!getenv("RIFT_VAR_ROOT")) {
    if (rift_cmdargs.use_rift_var_root == -1) {
      char *rift_var_root = NULL;
      asprintf(&rift_var_root, "%s/var/rift", getenv("RIFT_INSTALL"));
      setenv("RIFT_VAR_ROOT", rift_var_root, true);
      free(rift_var_root);
    } else {
      setenv("RIFT_VAR_ROOT", rift_cmdargs.rift_var_root, true);
    }
  }

  RWTRACE_INFO(inst->trace_ctxt, RWTRACE_CATEGORY_RWCLI,
          "RIFT_VAR_ROOT=%s", getenv("RIFT_VAR_ROOT"));

  // Decide the RW.CLI communication mode with RW.MgmtAgent
  if (rift_cmdargs.use_netconf == -1) {
    const char* agent_mode = rw_getenv("RWMGMT_AGENT_MODE");
    if (agent_mode && strcmp(agent_mode, "XML") == 0) {
      // If the agent mode is XML only RW.MSG mode is possible. Override the
      // command line option for netconf and opt for RW.MSG mode.
      inst->agent_type = RWCLI_TRANSPORT_MODE_RWMSG;
    } else {
      // Transport mode not chosen in command line and not XML mode. Choose
      // Netconf mode by default.
      inst->agent_type = RWCLI_TRANSPORT_MODE_NETCONF;
    }
  } else if (rift_cmdargs.use_netconf) {
    inst->agent_type = RWCLI_TRANSPORT_MODE_NETCONF;
  } else {
    inst->agent_type = RWCLI_TRANSPORT_MODE_RWMSG;
  }

  inst->is_netconf_agent_loaded = false;

  // To support background processes and job control, there should
  // be multiple channels available

  // Create two agent channels one for RWMSG and the other for Netconf
  controller_agent_channel_init(inst, RWCLI_TRANSPORT_MODE_RWMSG);
  controller_agent_channel_init(inst, RWCLI_TRANSPORT_MODE_NETCONF);
}
Esempio n. 6
0
rw_status_t
rwvcs_variable_evaluate_int(
    rwvcs_instance_ptr_t instance,
    char * variable,
    int * result)
{
  rw_status_t status;
  char expression[1024];
  char * match_string = "$python(";
  char copied_string[1024];
  int len;

  // Validate input parameters
  RW_CF_TYPE_VALIDATE(instance, rwvcs_instance_ptr_t);
  RW_ASSERT(variable);

  if (variable[0] != '$') {
    *result = atoi(variable);
    return RW_STATUS_SUCCESS;
  }
  else {
    if (0 != strncmp(variable, match_string, 8) ) {
      variable++;
      sprintf(expression, "int(%s)", variable);
    } else {
      variable += 8;
      strcpy(copied_string,variable);
      len = strlen(copied_string);
      if (copied_string[len - 1] == ')') {
        copied_string[len - 1] = '\0';
        sprintf(expression, "int(%s)", copied_string);
      } else {
        RWTRACE_INFO(instance->rwvx->rwtrace,
                     RWTRACE_CATEGORY_RWVCS,
                    "Error evaluating int variable\n");
        return RW_STATUS_FAILURE;
      }
    }
  }

  status = instance->rwpython_util.iface->python_eval_integer(
      instance->rwpython_util.cls,
      expression,
      result);

  return status;
}
Esempio n. 7
0
rw_status_t
rwdts_api_appconf_group_create_gi(rwdts_api_t*            apih,
                                  rwdts_xact_t*           xact,
                                  appconf_xact_init_gi    init,
                                  appconf_xact_deinit_gi  deinit,
                                  appconf_config_validate_gi validate,
                                  appconf_config_apply_gi    apply,
                                  void*                 user_data,
                                  rwdts_appconf_t**       appconf,
                                  GDestroyNotify xact_init_dtor,
                                  GDestroyNotify xact_deinit_dtor,
                                  GDestroyNotify config_validate_dtor,
                                  GDestroyNotify config_apply_dtor) {
  RW_ASSERT(appconf);
  if (!appconf) {
    return RW_STATUS_FAILURE;
  }
  rwdts_appconf_cbset_t cb = {
    .xact_init_gi    = init,
    .xact_deinit_gi  = deinit,
    .config_validate_gi = validate,
    .config_apply_gi    = apply,
    .ctx             = user_data,
    .xact_init_dtor =  xact_init_dtor,
    .xact_deinit_dtor =  xact_deinit_dtor,
    .config_validate_dtor = config_validate_dtor,
    .config_apply_dtor = config_apply_dtor
  };

  if (init) {
    if (!xact_init_dtor && !deinit) {
      RWDTS_API_LOG_EVENT(apih, AppconfDeinitMissing, "rwdts_api_appconf_group_create_gi: Use a managed langauge or provide a xact_deinit callback");
      RW_ASSERT(deinit);
    }
  }

  *appconf = rwdts_appconf_group_create(apih, xact, &cb);

  if (*appconf == NULL) {
    RWTRACE_INFO(apih->rwtrace_instance,
                 RWTRACE_CATEGORY_RWTASKLET,
                 "%s: Invoking state change callback", apih->client_path);
    return (RW_STATUS_FAILURE);
  }

  return (RW_STATUS_SUCCESS);
}
Esempio n. 8
0
rw_status_t
rwvcs_evaluate_python_loop_variables(rwvcs_instance_ptr_t instance,
          char *variable)
{
  rw_status_t status = RW_STATUS_SUCCESS;

  // Validate input parameters
  RW_CF_TYPE_VALIDATE(instance, rwvcs_instance_ptr_t);
  RW_ASSERT(variable);

  RWTRACE_INFO(instance->rwvx->rwtrace,
               RWTRACE_CATEGORY_RWVCS,
               "Variable evaluate python loop variable - expression = %s\n",
               variable);
  status = instance->rwpython_util.iface->python_run_string(
                instance->rwpython_util.cls,
                variable);

  return status;
}
Esempio n. 9
0
rw_status_t
rwvcs_variable_evaluate_str(
    struct rwvcs_instance_s *instance,
    const char * variable,
    char * result,
    int result_len)
{
  rw_status_t status;
  char expression[1024];
  char * match_string = "$python(";
  char copied_string[1024];
  int len;
  char * c_result = NULL;

  // Validate input parameters
  RW_CF_TYPE_VALIDATE(instance, rwvcs_instance_ptr_t);
  RW_ASSERT(variable);

  if (variable[0] != '$') {
    strcpy(result, variable);
    return RW_STATUS_SUCCESS;
  }
  else {
    if (0 != strncmp(variable, match_string, 8) ) {
      variable++;
      sprintf(expression, "str(%s)", variable);
    } else {
      variable += 8;
      strcpy(copied_string,variable);
      len = strlen(copied_string);
      if (copied_string[len - 1] == ')') {
        copied_string[len - 1] = '\0';
        sprintf(expression, "str(%s)", copied_string);
      } else {
        RWTRACE_INFO(instance->rwvx->rwtrace,
                     RWTRACE_CATEGORY_RWVCS,
                     "Error evaluating string variable\n");
        return RW_STATUS_FAILURE;
      }
    }
  }

  // Evaluate a "result = variable" expression and extract the value of "result"
  RWTRACE_INFO(instance->rwvx->rwtrace,
               RWTRACE_CATEGORY_RWVCS,
               "Variable evaluate str - expression = %s\n",
               expression);
  status = instance->rwpython_util.iface->python_eval_string(
              instance->rwpython_util.cls,
              expression,
              &c_result);

  if (status != RW_STATUS_SUCCESS) {
    strncpy(result, "", result_len);
  } else {
    strncpy(result, c_result, result_len);
    result[result_len-1] = '\0';
  }

  if (c_result)
    free(c_result);

  return status;
}
Esempio n. 10
0
void rwlogd_start_tasklet(rwlogd_instance_ptr_t instance, bool dts_register,char *rwlog_filename,char *filter_shm_name,
                          const char *schema_name)
{
  rwlogd_tasklet_instance_ptr_t rwlogd_instance_data;
  rwlogd_instance_data = (rwlogd_tasklet_instance_ptr_t) RW_MALLOC0(sizeof(struct rwlogd_tasklet_instance_s));
  rwlogd_instance_data->file_status.fd = -1;
  rwlogd_instance_data->log_buffer_size = CIRCULAR_BUFFER_SIZE;
  rwlogd_instance_data->rwlogd_instance = (void *)instance;

  rwlogd_instance_data->bootstrap_time = BOOTSTRAP_TIME;
  rwlogd_instance_data->bootstrap_severity = RW_LOG_LOG_SEVERITY_ERROR;
  rwlogd_instance_data->default_console_severity = RW_LOG_LOG_SEVERITY_ERROR;

  struct rwvcs_instance_s* vcs_inst = (struct rwvcs_instance_s*)(instance->rwtasklet_info->rwvcs);

  if(vcs_inst && vcs_inst->pb_rwmanifest &&
     vcs_inst->pb_rwmanifest->bootstrap_phase && 
     vcs_inst->pb_rwmanifest->bootstrap_phase->log &&
     vcs_inst->pb_rwmanifest->bootstrap_phase->log->has_enable) {

    if(vcs_inst->pb_rwmanifest->bootstrap_phase->log->has_bootstrap_time) {
      rwlogd_instance_data->bootstrap_time = vcs_inst->pb_rwmanifest->bootstrap_phase->log->bootstrap_time*RWLOGD_TICKS_PER_SEC;
    }
    if(vcs_inst->pb_rwmanifest->bootstrap_phase->log->has_severity &&
       vcs_inst->pb_rwmanifest->bootstrap_phase->log->severity < RW_LOG_LOG_SEVERITY_MAX_VALUE) {
      rwlogd_instance_data->bootstrap_severity = vcs_inst->pb_rwmanifest->bootstrap_phase->log->severity;
    }
    if(vcs_inst->pb_rwmanifest->bootstrap_phase->log->has_console_severity &&
       vcs_inst->pb_rwmanifest->bootstrap_phase->log->console_severity < RW_LOG_LOG_SEVERITY_MAX_VALUE) {
      rwlogd_instance_data->default_console_severity = vcs_inst->pb_rwmanifest->bootstrap_phase->log->console_severity;
    }
  }


  rwlogd_instance_data->log_buffer = RW_MALLOC0(rwlogd_instance_data->log_buffer_size);
  rwlogd_instance_data->curr_offset = 0;
  rwlogd_instance_data->curr_used_offset = rwlogd_instance_data->log_buffer_size;  /* Point this to end of buffer to indicate full buffer is free */

  instance->rwlogd_info = rwlogd_instance_data;
 
  instance->rwlogd_info->rwlogd_list_ring =  rwlogd_create_consistent_hash_ring(RWLOGD_DEFAULT_NODE_REPLICA); 
  /* Create List to maintains peer RwLogd list */
  RW_SKLIST_PARAMS_DECL(rwlogd_list_, rwlogd_peer_node_entry_t,rwtasklet_instance_id, rw_sklist_comp_int, element);
  RW_SKLIST_INIT(&(instance->rwlogd_info->peer_rwlogd_list),&rwlogd_list_);

  instance->dynschema_app_state = RW_MGMT_SCHEMA_APPLICATION_STATE_INITIALIZING;

  if (dts_register)
  {
    rwlog_dts_registration(instance);  
  }
  RWTRACE_INFO(instance->rwtasklet_info->rwtrace_instance,
	       RWTRACE_CATEGORY_RWTASKLET,
	       "\n================================================================================\n\n"
	       "RW.Logd -- Tasklet is started (%d) !\n\n"
	       "================================================================================\n",
         instance->rwtasklet_info->identity.rwtasklet_instance_id);

  rwlogd_create_client_endpoint(instance);
  rwlogd_create_server_endpoint(instance);
  rwlogd_start(instance,rwlog_filename,filter_shm_name,schema_name);

  if(schema_name) {
    instance->dynschema_app_state = RW_MGMT_SCHEMA_APPLICATION_STATE_READY;
  }

}