Example #1
0
/*
** process instance info query reply
**
** the is the reply of instance info query through node request
*/
static int __instance_info_update(xmlDoc * doc, xmlNode * node,
                                  int ent_id, int * j_status)
{
    logdebug(_("%s called\n"), __func__);

    /* Create xpath evaluation context */
    xmlXPathContextPtr xpathCtx = xmlXPathNewContext(doc);
    if (xpathCtx == NULL) {
        logerror(_("unable to create new XPath context %s, %d\n"),
                 __func__, __LINE__);
        goto failed;
    }

    InstanceInfo ii;
    char *str;
    str = xml_xpath_text_from_ctx(xpathCtx,
                         "/" LYXML_ROOT "/response/data/id");
    if (str == NULL)
        goto failed;
    ii.id = atoi(str);
    free(str);
    str = xml_xpath_text_from_ctx(xpathCtx,
                         "/" LYXML_ROOT "/response/data/status");
    if (str == NULL)
        goto failed;
    ii.status = atoi(str);
    free(str);
    ii.ip = xml_xpath_text_from_ctx(xpathCtx,
                         "/" LYXML_ROOT "/response/data/ip");

    logdebug(_("update info for instance %d: status %d, ip %s\n"),
                ii.id, ii.status, ii.ip);

    /* the ent_id passed to the routine is for node, not usefult */
    ent_id = ly_entity_find_by_db(LY_ENTITY_OSM, ii.id);
    if (!ly_entity_is_registered(ent_id) &&
        db_instance_update_status(ii.id, &ii, -1) < 0) {
        logerror(_("error in %s(%d)\n"), __func__, __LINE__);
        if (ii.ip)
            free(ii.ip);
        goto failed;
    }

    if (ii.ip)
        free(ii.ip);
    return 0;

failed:
    *j_status = LY_S_FINISHED_FAILURE;
    return 0;
}
Example #2
0
/* process xml response */
static int __process_node_xml_response(xmlDoc * doc, xmlNode * node,
                                       int ent_id)
{
    logdebug(_("node response for entity %d\n"), ent_id);
    char * str = (char *) xmlGetProp(node, (const xmlChar *) "id");
    if (str)
        logdebug("node response id(job id) = %s\n", str);
    else {
        logerror(_("error in %s(%d)\n"), __func__, __LINE__);
        return -1;
    }
    int id = atoi(str);
    free(str);

    str = (char *) xmlGetProp(node, (const xmlChar *) "status");
    if (str)
        logdebug("node response status = %s\n", str);
    else {
        logerror(_("error in %s(%d)\n"), __func__, __LINE__);
        return -1;
    }
    int status = atoi(str);
    free(str);

    int data_type = -1;
    node = node->children;
    for (; node; node = node->next) {
        if (node->type == XML_ELEMENT_NODE) {
            if (strcmp((char *)node->name, "result") == 0) {
                xmlNode * n = node->children;
                if (n && n->type == XML_TEXT_NODE && n->content)
                    loginfo(_("response result: %s\n"), n->content);
                else
                    loginfo(_("response no result message\n"));
            }
            else if (strcmp((char *)node->name, "data") == 0) {
                str = (char *) xmlGetProp(node, (const xmlChar *) "type");
                if (str) {
                    logdebug("node response data type = %s\n", str);
                    data_type = atoi(str);
                    free(str);
                }
                else
                    logwarn(_("response data no type\n"));
            }
        }
    }

    if (id != 0) {
        LYJobInfo * job = job_find(id);
        if (job == NULL) {
            logwarn(_("job(%d) not found waiting for node reply\n"), id);
            return 0;
        }
        if (job_update_status(job, status)) {
            logerror(_("error in %s(%d)\n"), __func__, __LINE__);
            return -1;
        }
        /* hack to release entity during instance shutting down */
        if (((job->j_action == LY_A_NODE_STOP_INSTANCE) ||
            (job->j_action == LY_A_NODE_FULLREBOOT_INSTANCE) ||
            (job->j_action == LY_A_NODE_ACPIREBOOT_INSTANCE)) && 
            status == LY_S_RUNNING_STOPPED) {
                int ins_id = ly_entity_find_by_db(LY_ENTITY_OSM, job->j_target_id);
                if (ins_id > 0)
                    ly_entity_release(ins_id);
            }
         /* continue processing for data */
    }

    int ent_type = ly_entity_type(ent_id);
    if (ent_type == LY_ENTITY_NODE && data_type == DATA_INSTANCE_INFO) { 
        if ( __instance_info_update(doc, node)) {
            logerror(_("error in %s(%d)\n"), __func__, __LINE__);
            return -1;
        }
    }
   
    if (ent_type == LY_ENTITY_NODE && data_type == DATA_NODE_INFO) { 
        if ( __node_info_update(doc, node, ent_id, &status)) {
            logerror(_("error in %s(%d)\n"), __func__, __LINE__);
            return -1;
        }
    }
 
    return 0;
}
Example #3
0
/*
** process instance info data,
** either from internal query or from xml response
**
*/
static int __instance_info_update(xmlDoc * doc, xmlNode * node)
{
    int ret;
    logdebug(_("%s called\n"), __func__);

    /* Create xpath evaluation context */
    xmlXPathContextPtr xpathCtx = xmlXPathNewContext(doc);
    if (xpathCtx == NULL) {
        logerror(_("unable to create new XPath context %s, %d\n"),
                 __func__, __LINE__);
        return -1;
    }

    InstanceInfo ii;
    bzero(&ii, sizeof(InstanceInfo));
    char *str;
    str = xml_xpath_text_from_ctx(xpathCtx,
                         "/" LYXML_ROOT "/response/data/id");
    if (str == NULL)
        goto failed;
    ii.id = atoi(str);
    free(str);
    str = xml_xpath_text_from_ctx(xpathCtx,
                         "/" LYXML_ROOT "/response/data/status");
    if (str == NULL)
        goto failed;
    ii.status = atoi(str);
    free(str);
    ii.ip = xml_xpath_text_from_ctx(xpathCtx,
                         "/" LYXML_ROOT "/response/data/ip");
    str = xml_xpath_text_from_ctx(xpathCtx,
                         "/" LYXML_ROOT "/response/data/gport");
    if (str == NULL)
        goto failed;
    ii.gport = atoi(str);
    free(str);
    str = xml_xpath_text_from_ctx(xpathCtx,
                         "/" LYXML_ROOT "/response/data/netstat0");
    if (str)
        sscanf(str, "%ld %ld %ld %ld", &ii.netstat[0].rx_bytes, &ii.netstat[0].rx_pkts,
                                       &ii.netstat[0].tx_bytes, &ii.netstat[0].tx_pkts);
    else
        goto failed;
    free(str);

    logdebug(_("update info for instance %d:"), ii.id);
    luoyun_instance_info_print(&ii);

    int ent_id = ly_entity_find_by_db(LY_ENTITY_OSM, ii.id);
    if (ly_entity_is_registered(ent_id))
        ii.status = DOMAIN_S_UNKNOWN; /* don't update status */
    if (db_instance_update_status(ii.id, &ii, -1) < 0) {
        logerror(_("error in %s(%d)\n"), __func__, __LINE__);
        if (ii.ip)
            free(ii.ip);
        goto failed;
    }

    if (ii.ip)
        free(ii.ip);
    ret = 0;
    goto done;

failed:
    ret = -1;
done:
    xmlXPathFreeContext(xpathCtx);
    return ret;
}