Skip to content
Snippets Groups Projects
Commit 905d99ae authored by Eric Vidal's avatar Eric Vidal :speech_balloon:
Browse files

adapt to new functions, some function need improvement

parent c725de2d
No related branches found
No related tags found
No related merge requests found
graph_add_deps.o
graph_build_g.o
graph_build_service.o
graph_build_service_bytree.o
graph_build_service_bytree_from_src.o
graph_build_service_from_list.o
graph_build_tree.o
graph_compute_dependencies.o
graph_remove_deps.o
ss_resolve_graph.o
-loblibs
-lskarnet
/*
* graph_add_deps.c
*
* Copyright (c) 2018-2021 Eric Vidal <eric@obarun.org>
*
* All rights reserved.
*
* This file is part of Obarun. It is subject to the license terms in
* the LICENSE file found in the top-level directory of this
* distribution.
* This file may not be copied, modified, propagated, or distributed
* except according to the terms contained in the LICENSE file./
*/
#include <stdint.h>
#include <oblibs/graph.h>
#include <oblibs/log.h>
#include <oblibs/sastr.h>
#include <skalibs/stralloc.h>
int graph_add_deps(graph_t *g, char const *vertex, char const *edge, uint8_t requiredby)
{
log_flow() ;
stralloc sa = STRALLOC_ZERO ;
int e = 0 ;
if (!sastr_clean_string(&sa, edge)) {
log_warnu("rebuild dependencies list") ;
goto freed ;
}
if (!requiredby) {
if (!graph_vertex_add_with_nedge(g, vertex, &sa)) {
log_warnu("add edges at vertex: ", vertex) ;
goto freed ;
}
} else {
if (!graph_vertex_add_with_nrequiredby(g, vertex, &sa)) {
log_warnu("add requiredby at vertex: ", vertex) ;
goto freed ;
}
}
e = 1 ;
freed:
stralloc_free(&sa) ;
return e ;
}
......@@ -12,29 +12,23 @@
* except according to the terms contained in the LICENSE file./
*/
#include <stdint.h>
#include <oblibs/graph.h>
#include <oblibs/log.h>
#include <66/service.h>
#include <66/tree.h>
#include <66/resolve.h>
#include <66/graph.h>
#include <66/ssexec.h>
int graph_build_g(graph_t *g, char const *base, char const *treename, uint8_t data_type, uint8_t general)
void graph_build_g(graph_t *graph, resolve_service_t *ares, unsigned int *areslen, ssexec_t *info)
{
log_flow() ;
if (data_type == DATA_SERVICE) {
if (data_type == DATA_SERVICE)
if (!graph_build_service(g, base, treename, general))
return 0 ;
graph_build_service(graph, ares, areslen, info) ;
} else if (data_type == DATA_TREE) {
else if (data_type == DATA_TREE)
if (!graph_build_tree(g, base))
return 0 ;
}
return 1 ;
graph_build_tree(g, info->base.s) ;
}
......@@ -12,8 +12,8 @@
* except according to the terms contained in the LICENSE file./
*/
#include <stdint.h>
#include <string.h>
#include <stdint.h>
#include <oblibs/log.h>
#include <oblibs/string.h>
......@@ -22,49 +22,24 @@
#include <skalibs/stralloc.h>
#include <66/constants.h>
#include <66/tree.h>
#include <66/resolve.h>
#include <66/service.h>
#include <66/graph.h>
#include <66/state.h>
/**
* @general has only effect for DATA_SERVICE type
* !general -> all services from @treename
* general -> all services from all trees of the system
*
* */
int graph_build_service(graph_t *g, char const *base, char const *treename, uint8_t general)
void graph_build_service(graph_t *graph, resolve_service_t *ares, unsigned int *areslen, ssexec_t *info, uint32_t flag)
{
log_flow() ;
int e = 0 ;
size_t pos = 0, baselen = strlen(base) ;
stralloc sa = STRALLOC_ZERO ;
char const *exclude[1] = { 0 } ;
char solve[info->base.len + SS_SYSTEM_LEN + SS_RESOLVE_LEN + 1 + SS_SERVICE_LEN + 1] ;
char solve[baselen + SS_SYSTEM_LEN + 1 + SS_MAX_TREENAME + SS_SVDIRS_LEN + 1] ;
if (general) {
if (!resolve_get_field_tosa_g(&sa, base, treename, SS_MASTER + 1, DATA_TREE_MASTER, E_RESOLVE_TREE_MASTER_CONTENTS))
goto err ;
FOREACH_SASTR(&sa, pos) {
auto_strings(solve + baselen + SS_SYSTEM_LEN + 1, sa.s + pos, SS_SVDIRS) ;
if (!graph_build_service_bytree(g, solve, 2))
goto err ;
}
} else {
auto_strings(solve, info->base.s, SS_SYSTEM, SS_RESOLVE, "/", SS_SERVICE) ;
auto_strings(solve, base, SS_SYSTEM, "/", treename, SS_SVDIRS) ;
if (!sastr_dir_get_recursive(&sa, solve, exclude, S_IFREG, 0))
log_dieu(LOG_EXIT_SYS, "get resolve files") ;
if (!graph_build_service_bytree(g, solve, 2))
goto err ;
}
service_graph_g(sa.s, sa.len, graph, ares, areslen, info, flag) ;
e = 1 ;
err:
stralloc_free(&sa) ;
return e ;
stralloc_free(&sa) ;
}
......@@ -27,12 +27,18 @@
#include <66/service.h>
#include <66/enum.h>
#include <66/graph.h>
#include <66/state.h>
/*
*
* Need to be review entirely
*
* */
/** @tree: absolute path of the tree including SS_SVDIRS
* what = 0 -> classic
* what = 1 -> atomic and bundle
* what > 1 -> module */
int graph_build_service_bytree(graph_t *g, char const *tree, uint8_t what)
int graph_build_service_bytree(graph_t *g, char const *tree, uint8_t what, uint8_t is_supervised)
{
log_flow() ;
......@@ -44,32 +50,46 @@ int graph_build_service_bytree(graph_t *g, char const *tree, uint8_t what)
resolve_service_master_t mres = RESOLVE_SERVICE_MASTER_ZERO ;
resolve_wrapper_t_ref mwres = resolve_set_struct(DATA_SERVICE_MASTER, &mres) ;
if (!resolve_read_g(mwres, tree, SS_MASTER + 1)) {
log_warnu("read resolve Master file of trees") ;
if (!resolve_read(mwres, tree, SS_MASTER + 1)) {
log_warnu("read resolve Master service file of tree: ", tree) ;
goto err ;
}
/**
*
*
* a revoir ici les checks en fonction des appels qui sont fait
* notamment par 66-inservice, 66-intree
*
*
*
* */
if (what == 2)
if (mres.ncontents)
if (!auto_stra(&sa, mres.sa.s + mres.contents))
goto err ;
if (mres.nclassic)
if (!auto_stra(&sa, mres.sa.s + mres.classic))
goto err ;
if (!what)
if (mres.nclassic)
if (!auto_stra(&sa, mres.sa.s + mres.classic))
goto err ;
if (mres.nmodule)
if (!auto_stra(&sa, mres.sa.s + mres.module))
goto err ;
if (what > 1)
if (mres.nmodule)
if (!auto_stra(&sa, mres.sa.s + mres.module))
goto err ;
if (mres.nbundle)
if (!auto_stra(&sa, mres.sa.s + mres.bundle))
goto err ;
if (what == 1) {
if (mres.nlongrun)
if (!auto_stra(&sa, mres.sa.s + mres.longrun))
goto err ;
if (mres.nbundle)
if (!auto_stra(&sa, mres.sa.s + mres.bundle))
goto err ;
if (mres.noneshot)
if (!auto_stra(&sa, mres.sa.s + mres.oneshot))
goto err ;
if (mres.noneshot)
if (!auto_stra(&sa, mres.sa.s + mres.oneshot))
goto err ;
}
if (!sastr_clean_string_g(&sa, sa.s))
if (!sastr_clean_string_flush_sa(&sa, sa.s))
goto err ;
FOREACH_SASTR(&sa, pos) {
......@@ -79,6 +99,14 @@ int graph_build_service_bytree(graph_t *g, char const *tree, uint8_t what)
if (!resolve_read(wres, tree, service))
goto err ;
if (is_supervised) {
char atree[strlen(res.sa.s + res.treename) + 1] ;
if (!service_is_g(atree, service, STATE_FLAGS_ISSUPERVISED))
continue ;
}
char *str = res.sa.s ;
if (!graph_vertex_add(g, service)) {
......@@ -86,29 +114,17 @@ int graph_build_service_bytree(graph_t *g, char const *tree, uint8_t what)
goto err ;
}
if (res.ndepends) {
if (res.dependencies.ndepends) {
if (res.type == TYPE_MODULE || res.type == TYPE_BUNDLE) {
uint32_t depends = res.type == TYPE_MODULE ? what > 1 ? res.contents : res.depends : res.depends ;
if (!graph_add_deps(g, service, str + depends, 0)) {
log_warnu("add dependencies of service: ",service) ;
goto err ;
}
} else {
if (!graph_add_deps(g, service,str + res.depends, 0)) {
log_warnu("add dependencies of service: ",service) ;
goto err ;
}
if (!graph_compute_dependencies(g, service,str + res.dependencies.depends, 0)) {
log_warnu("add dependencies of service: ",service) ;
goto err ;
}
}
if (res.nrequiredby) {
if (res.dependencies.nrequiredby) {
if (!graph_add_deps(g, service, str + res.requiredby, 1)) {
if (!graph_compute_dependencies(g, service, str + res.dependencies.requiredby, 1)) {
log_warnu("add requiredby of service: ", service) ;
goto err ;
}
......
......@@ -70,29 +70,17 @@ int graph_build_service_bytree_from_src(graph_t *g, char const *src, uint8_t wha
goto err ;
}
if (res.ndepends) {
if (res.dependencies.ndepends) {
if (res.type == TYPE_MODULE || res.type == TYPE_BUNDLE) {
uint32_t depends = res.type == TYPE_MODULE ? what > 1 ? res.contents : res.depends : res.depends ;
if (!graph_add_deps(g, service, str + depends, 0)) {
log_warnu("add dependencies of service: ",service) ;
goto err ;
}
} else {
if (!graph_add_deps(g, service,str + res.depends, 0)) {
log_warnu("add dependencies of service: ",service) ;
goto err ;
}
if (!graph_compute_dependencies(g, service,str + res.dependencies.depends, 0)) {
log_warnu("add dependencies of service: ",service) ;
goto err ;
}
}
if (res.nrequiredby) {
if (res.dependencies.nrequiredby) {
if (!graph_add_deps(g, service, str + res.requiredby, 1)) {
if (!graph_compute_dependencies(g, service, str + res.dependencies.requiredby, 1)) {
log_warnu("add requiredby of service: ", service) ;
goto err ;
}
......
/*
* graph_build_service_from_list.c
*
* Copyright (c) 2018-2022 Eric Vidal <eric@obarun.org>
*
* All rights reserved.
*
* This file is part of Obarun. It is subject to the license terms in
* the LICENSE file found in the top-level directory of this
* distribution.
* This file may not be copied, modified, propagated, or distributed
* except according to the terms contained in the LICENSE file./
*/
#include <string.h>
#include <stdlib.h>
#include <oblibs/log.h>
#include <oblibs/string.h>
#include <oblibs/graph.h>
#include <skalibs/genalloc.h>
#include <66/config.h>
#include <66/graph.h>
#include <66/service.h>
#include <66/resolve.h>
#include <66/constants.h>
#include <66/state.h>
int graph_build_service_from_list(char const *const *list, char const *base, graph_t *graph, resolve_service_t *ares, uint8_t requiredby)
{
log_flow() ;
unsigned int areslen = 0, e = 0 ;
char atree[SS_MAX_TREENAME + 1] ;
for (; *list ; list++) {
int found = 0 ;
unsigned int pos = 0, ndeps = 0 ;
unsigned int alist[graph->mlen] ;
char const *name = *list ;
resolve_service_t res = RESOLVE_SERVICE_ZERO ;
resolve_wrapper_t_ref wres = resolve_set_struct(DATA_SERVICE, &res) ;
graph_array_init_single(alist, graph->mlen) ;
resolve_service_t cp = RESOLVE_SERVICE_ZERO ;
if (!resolve_read_g(wres, base, name))
goto err ;
if (!service_resolve_copy(&cp, &res))
goto err ;
if (service_resolve_array_search(ares, areslen, name) < 0)
ares[areslen++] = cp ;
ndeps = graph_matrix_get_edge_g_list(alist, graph, name, requiredby, 1) ;
if (ndeps < 0)
goto err ;
for (; pos < ndeps ; pos++) {
char *name = graph->data.s + genalloc_s(graph_hash_t, &graph->hash)[alist[pos]].vertex ;
if (service_resolve_array_search(ares, areslen, name) < 0) {
resolve_service_t cp = RESOLVE_SERVICE_ZERO ;
found = service_is_g(atree, name, STATE_FLAGS_ISPARSED) ;
if (found <= 0)
goto err ;
if (!resolve_read_g(wres, base, name))
goto err ;
if (!service_resolve_copy(&cp, &res))
goto err ;
ares[areslen++] = cp ;
}
}
resolve_free(wres) ;
}
e = areslen ;
err:
return e ;
}
......@@ -25,47 +25,49 @@
#include <66/constants.h>
#include <66/resolve.h>
#include <66/tree.h>
#include <66/graph.h>
int graph_build_tree(graph_t *g, char const *base)
void graph_build_tree(graph_t *g, char const *base)
{
log_flow() ;
int e = 0 ;
size_t baselen = strlen(base), pos = 0 ;
char solve[baselen + SS_SYSTEM_LEN + 1] ;
size_t pos = 0 ;
stralloc sa = STRALLOC_ZERO ;
resolve_tree_t tres = RESOLVE_TREE_ZERO ;
resolve_wrapper_t_ref wres = resolve_set_struct(DATA_TREE, &tres) ;
if (!resolve_get_field_tosa_g(&sa, base, 0, SS_MASTER + 1, DATA_TREE_MASTER, TREE_ENUM_MASTER_CONTENTS))
goto err ;
auto_strings(solve, base, SS_SYSTEM) ;
if (!resolve_get_field_tosa_g(&sa, base, SS_MASTER + 1, DATA_TREE_MASTER, E_RESOLVE_TREE_MASTER_CONTENTS))
log_dieu(LOG_EXIT_SYS, "get resolve Master file of trees") ;
FOREACH_SASTR(&sa, pos) {
char *name = sa.s + pos ;
if (!resolve_read(wres, solve, name))
goto err ;
if (!resolve_read_g(wres, base, name))
log_dieu(LOG_EXIT_SYS, "read resolve file of: ", name) ;
if (!graph_vertex_add(g, name))
goto err ;
log_dieu(LOG_EXIT_SYS, "add vertex of: ", name) ;
if (tres.ndepends)
if (!graph_add_deps(g, name, tres.sa.s + tres.depends, 0))
goto err ;
if (!graph_compute_dependencies(g, name, tres.sa.s + tres.depends, 0))
log_dieu(LOG_EXIT_SYS, "compute dependencies of: ", name) ;
if (tres.nrequiredby)
if (!graph_add_deps(g, name, tres.sa.s + tres.requiredby, 1))
goto err ;
if (!graph_compute_dependencies(g, name, tres.sa.s + tres.requiredby, 1))
log_dieu(LOG_EXIT_SYS, "compute requiredby of: ", name) ;
}
e = 1 ;
if (!graph_matrix_build(g))
log_dieu(LOG_EXIT_SYS, "build the graph") ;
if (!graph_matrix_analyze_cycle(g))
log_dieu(LOG_EXIT_SYS, "found cycle") ;
if (!graph_matrix_sort(g))
log_dieu(LOG_EXIT_SYS, "sort the graph") ;
err:
resolve_free(wres) ;
stralloc_free(&sa) ;
return e ;
resolve_free(wres) ;
stralloc_free(&sa) ;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment