Example #1
0
        public IActionResult GetGraphsInfos([FromBody] Graph[] raw)
        {
            try
            {
                List <object> infos = new List <object>();

                raw.ToList().ForEach(x =>
                {
                    var graph = GraphsContainer.GetRunningGraphByHash(x.UniqueHash);
                    if (graph == null)
                    {
                        return;
                    }
                    infos.Add(new
                    {
                        hostedApi = graph?.graph.HasHostedAPI(),
                        hash      = x.UniqueHash,
                        state     = graph.currentGraphState,
                        loadedAt  = graph.LoadedAt,
                        stoppedAt = graph.StoppedAt
                    });
                });

                return(Ok(infos));
            }
            catch (Exception error)
            {
                logger.Error(error);
                return(StatusCode(500));
            }
        }
Example #2
0
        public IActionResult GetGraphInfos([FromBody] Graph raw)
        {
            try
            {
                GraphContextWrapper graph = null;
                if (raw.Debug)
                {
                    graph = GraphsContainer.GetWalletDebugGraph(raw.WalletIdentifier);
                }
                else
                {
                    graph = GraphsContainer.GetRunningGraphByHash(raw.UniqueHash);
                }


                if (graph == null)
                {
                    return(StatusCode(404));
                }
                return(Ok(new
                {
                    state = graph.currentGraphState,
                    loadedAt = graph.LoadedAt,
                    stoppedAt = graph.StoppedAt
                }));
            }
            catch (Exception error)
            {
                logger.Error(error);
                return(StatusCode(500));
            }
        }
Example #3
0
        static void Main(string[] args)
        {
            DotNetEnv.Env.Load();

            NodeBlockExporter.ExportNodesSchema(Environment.GetEnvironmentVariable("node_schema_path"));
            try
            {
                // init graphs cost database updater
                //GraphsContainer.InitConsumingGraphCosts();

                // init graphs that was live on last run
                if (Environment.GetEnvironmentVariable("relaunch_last_graph") == "true")
                {
                    GraphsContainer.InitActiveGraphs();
                }

                new InternalApi(new string[] { }, "0.0.0.0", 1337).InitApi();
            }
            catch (Exception error)
            {
                Console.WriteLine("Unable to init GraphLinq Engine API: {0}", error.Message);
            }

            Console.ReadLine();
        }
Example #4
0
        public async Task <IActionResult> RequestHostedGraphAPI(string graphId, string graphEndpoint)
        {
            try
            {
                var graphContext = GraphsContainer.GetRunningGraphByHash(graphId);
                if (graphContext == null)
                {
                    return(BadRequest(new { success = false, message = string.Format("Graph {0} not loaded in the GraphLinq engine", graphId) }));
                }

                if (!graphContext.graph.HasHostedAPI())
                {
                    return(BadRequest(new { success = false, message = string.Format("Graph {0} doesn't have a hosted API", graphId) }));
                }

                var graphHostedApi = graphContext.graph.GetHostedAPI().HostedAPI;
                if (!graphHostedApi.Endpoints.ContainsKey(graphEndpoint))
                {
                    return(BadRequest(new { success = false, message = string.Format("Graph {0} doesn't have this endpoint available", graphId) }));
                }

                var endpoint = graphHostedApi.Endpoints[graphEndpoint];
                var rawBody  = "";
                using (StreamReader reader = new StreamReader(Request.Body, System.Text.Encoding.UTF8))
                {
                    rawBody = await reader.ReadToEndAsync();
                }

                var context = await endpoint.OnRequest(HttpContext, rawBody);

                if (context == null)
                {
                    return(BadRequest());
                }

                switch (context.ResponseFormatType)
                {
                case HostedAPI.RequestContext.ResponseFormatTypeEnum.JSON:
                    return(Content(context.Body, "application/json"));

                default:
                    return(Ok(context.Body));
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                return(BadRequest("Unknown error"));
            }
        }
Example #5
0
        public IActionResult UpdateGraphState([FromBody] Graph graph)
        {
            var graphContext = GraphsContainer.GetRunningGraphByHash(graph.UniqueHash);

            if (graphContext == null)
            {
                return(Ok(new { success = false, message = string.Format("Graph {0} not loaded in the GraphLinq engine", graph.UniqueHash) }));
            }

            GraphsContainer.UpdateStorageStateGraph(graphContext, graph.DeployedState);
            if (graph.DeployedState == Enums.GraphStateEnum.STARTING || graph.DeployedState == Enums.GraphStateEnum.RESTARTING)
            {
                var decompressedRaw = GraphCompression.DecompressGraphData(graphContext.graph.CompressedRaw);
                var reloadedGraph   = BlockGraph.LoadGraph(decompressedRaw, graph.UniqueHash, graphContext.graph.CompressedRaw);

                GraphsContainer.AddNewGraph(reloadedGraph, graphContext.graph.currentContext.walletIdentifier, graph.DeployedState);
            }
            return(Ok(new { success = true }));
        }
Example #6
0
        public async Task <IActionResult> DeployAndInitGraph([FromBody] Graph graph)
        {
            if (graph.Debug)
            {
                var debugGraph = GraphsContainer.GetWalletDebugGraph(graph.WalletIdentifier);
                if (debugGraph != null)
                {
                    graph.UniqueHash = debugGraph.graph.UniqueHash;
                    RedisStorage.RemoveGraphLogs(graph.UniqueHash);
                }
            }

            BlockGraph loadedGraph = await _graphService.InitGraph(graph);

            if (loadedGraph == null)
            {
                return(StatusCode(500));
            }
            GraphsContainer.AddNewGraph(loadedGraph, graph.WalletIdentifier, graph.DeployedState);

            return(Ok(new { hash = loadedGraph.UniqueHash }));
        }