rw_status_t process_init_phase(struct rwmain_gi * rwmain) { rw_status_t status; rwvcs_instance_ptr_t rwvcs; rwvcs = rwmain->rwvx->rwvcs; if (rwvcs->pb_rwmanifest->init_phase->settings->rwvcs->no_autostart == false) { vcs_manifest_component *m_component; char * instance_name = NULL; instance_name = to_instance_name(rwmain->component_name, rwmain->instance_id); RW_ASSERT(*instance_name); // Lookup the component to start status = rwvcs_manifest_component_lookup(rwvcs, rwmain->component_name, &m_component); rwmain_trace_info(rwmain, "rwvcs_manifest_component_lookup %s", rwmain->component_name); RW_ASSERT(status == RW_STATUS_SUCCESS); if (m_component->component_type == RWVCS_TYPES_COMPONENT_TYPE_RWVM) { RWVCS_LATENCY_CHK_PRE(rwmain->rwvx->rwsched); rwmain_rwvm_init( rwmain, m_component->rwvm, rwmain->component_name, rwmain->instance_id, instance_name, rwmain->parent_id); RWVCS_LATENCY_CHK_POST(rwmain->rwvx->rwtrace, RWTRACE_CATEGORY_RWMAIN, rwmain_rwvm_init, "rwmain_rwvm_init:%s", instance_name); } else if (m_component->component_type == RWVCS_TYPES_COMPONENT_TYPE_RWPROC) { RWVCS_LATENCY_CHK_PRE(rwmain->rwvx->rwsched); rwmain_rwproc_init( rwmain, m_component->rwproc, rwmain->component_name, rwmain->instance_id, instance_name, rwmain->parent_id); RWVCS_LATENCY_CHK_POST(rwmain->rwvx->rwtrace, RWTRACE_CATEGORY_RWMAIN, rwmain_rwproc_init, "rwmain_rwproc_init:%s", instance_name); } else { rwmain_trace_crit( rwmain, "rwmain cannot start a component which is not a vm or process (%s)", m_component->component_name); RW_CRASH(); } } return RW_STATUS_SUCCESS; }
/* * Initialize the zookeeper with a node for this component. Used when the * component does not have a parent and therefore no one created the zookeeper * node yet. */ rw_status_t update_zk(struct rwmain_gi * rwmain) { rw_status_t status; vcs_manifest_component * mdef; rwvcs_instance_ptr_t rwvcs; char * id = NULL; rw_component_info * ci = NULL; rwvcs = rwmain->rwvx->rwvcs; RW_ASSERT(!rwmain->parent_id); id = to_instance_name(rwmain->component_name, rwmain->instance_id); // As we only hit this point when the parent_id is NULL, we are pretty much // guaranteed that the definition has to be in the static manifest. status = rwvcs_manifest_component_lookup(rwvcs, rwmain->component_name, &mdef); if (status != RW_STATUS_SUCCESS) { RW_CRASH(); goto done; } if (mdef->component_type == RWVCS_TYPES_COMPONENT_TYPE_RWVM) { ci = rwvcs_rwvm_alloc( rwmain->rwvx->rwvcs, rwmain->parent_id, rwmain->component_name, rwmain->instance_id, id); if (!ci) { RW_CRASH(); status = RW_STATUS_FAILURE; goto done; } ci->vm_info->vm_ip_address = strdup(rwmain->vm_ip_address); ci->vm_info->has_pid = true; ci->vm_info->pid = getpid(); ci->has_state = true; ci->state = RW_BASE_STATE_TYPE_STARTING; if (mdef->rwvm && mdef->rwvm->has_leader) { ci->vm_info->has_leader = true; ci->vm_info->leader= mdef->rwvm->leader; } } else if (mdef->component_type == RWVCS_TYPES_COMPONENT_TYPE_RWPROC) { ci = rwvcs_rwproc_alloc( rwvcs, rwmain->parent_id, rwmain->component_name, rwmain->instance_id, id); if (!ci) { RW_CRASH(); status = RW_STATUS_FAILURE; goto done; } ci->proc_info->has_pid = true; ci->proc_info->pid = getpid(); ci->has_state = true; ci->proc_info->has_native = true; ci->proc_info->native = false; ci->state = RW_BASE_STATE_TYPE_STARTING; } else { RW_CRASH(); status = RW_STATUS_FAILURE; goto done; } status = rwvcs_rwzk_node_update(rwmain->rwvx->rwvcs, ci); if (status != RW_STATUS_SUCCESS) { RW_CRASH(); goto done; } done: if (id) free(id); if (ci) protobuf_free(ci); return status; }