Exemple #1
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;
}
Exemple #2
0
/* process xml response */
static int __process_node_xml_response(xmlDoc * doc, xmlNode * node,
                                       int ent_id)
{
    loginfo(_("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;
        }
        if (status != LY_S_FINISHED_SUCCESS || data_type < 0)
            return 0;
    }

    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, ent_id, &status)) {
            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;
}