Exemplo n.º 1
0
        /// <summary>
        /// The insight client will search for the elemets related to the uuid.
        /// </summary>
        /// <param name="uuid"> The uuid that we want to get a graph/route for</param>
        /// <returns>Grapgh which represents the service element route</returns>
        public ServiceGraph GetServiceGraph(string uuid)
        {
            string originalUUID = uuid;

            try
            {
                bool modified = false;;
                // check if the uuid contains illegal characters and remove them
                uuid = Tools.ModifyUnspportedInsightNameConvention(uuid, forbiddenInsightApiQuerySymbols);
                if (uuid[0] == '"')
                {
                    string tmp = uuid.Substring(1, uuid.Length - 2);
                    modified = !tmp.Equals(originalUUID);
                }
                else
                {
                    modified = !uuid.Equals(originalUUID);
                }
                logger.Debug("The original uuid provided for this build: {0}", originalUUID);
                logger.Debug("The modified uuid created for this build: {0}", uuid);

                // Check if the IQL result are legal
                IqlApiResult serviceResult = GetInsightObjectByName(uuid, "Root", "Service", modified);
                IqlApiResult elementResult = GetInsightOutBoundByObjectName(uuid, "Element", modified);
                if (!Tools.IsValidIqlResult(serviceResult) || !Tools.IsValidIqlResult(elementResult) || serviceResult.objectEntries.Count == 0)
                {
                    throw new CorruptedInsightDataException(uuid);
                }
                // if there is more than one service or none that are matching the given uuid,
                // it must mean that the uuid contains an illegal naming conevtion, which gave false positive results after the name modification
                if (serviceResult.objectEntries.Count > 1)
                {
                    Tools.UniquenessLostFix(originalUUID, ref serviceResult, ref elementResult);
                    //throw new IllegalNameException(uuid + " Uniquness lost!!");
                }

                // From here the code logic starts
                ServiceGraph graph = new ServiceGraph(elementResult, serviceResult, debug, originalUUID, modified);
                if (graph != null && graph.constructorSuceeded)
                {
                    return(graph);
                }
                else
                {
                    logger.Error("graph construction failed");
                    return(null);
                }
            }
            catch (IllegalNameException e)
            {
                logger.Error(e.Message + "|" + e.StackTrace);
                throw e;
            }
            catch (InsighClientLibraryUnknownErrorException e)
            {
                logger.Fatal(e.Message + "|" + e.StackTrace);
                throw e;
            }
            catch (CorruptedInsightDataException e)
            {
                logger.Error(e.Message + "|" + e.StackTrace);
                throw e;
            }
            catch (Exception e)
            {
                logger.Fatal("Unknwon error: \n" + e.Message + "|" + e.StackTrace);
                throw e;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Goes over all the elements in the graph, for each element check the incoming elements in Insight database and in the built graph route.
        /// If every grapgh element has the same incoming elements in both the graph route and Insight database, we can deduct that the graph is valid
        /// </summary>
        /// <param name="graph">the graph to check for a valid route</param>
        /// <returns>true if the graph route is valid, false otherwise</returns>
        public bool VerifyValidRoute(ServiceGraph graph)
        {
            bool          ans = true;
            List <string> graphElementNames                = new List <string>(graph.ServiceElementNameList.Keys);
            List <string> insightIncomingElementNames      = new List <string>();
            List <string> graphElementIncomingElementNames = new List <string>();

            // gather all name of the graph element list
            foreach (GraphElement graphElement in graph.graphElements)
            {
                insightIncomingElementNames      = new List <string>();
                graphElementIncomingElementNames = new List <string>();
                bool   modified            = false;
                var    modifiedElementName = Tools.ModifyUnspportedInsightNameConvention(graphElement.CurrentElement.name, forbiddenInsightApiQuerySymbols);
                string nameEqualizer       = "=";
                if (!modifiedElementName.Equals(graphElement.CurrentElement.name))
                {
                    nameEqualizer = "LIKE";
                }
                string equalizer = "=";
                if (graph.modifiedUUID)
                {
                    equalizer = "LIKE";
                }

                string   modifiedServiceName = Tools.ModifyUnspportedInsightNameConvention(graph.Service.Name, forbiddenInsightApiQuerySymbols);
                string[] getGroups           = new string[2] {
                    "", ""
                };
                string             groups = InsightGetByIqlObjectIdGroup(getGroups, "Element", "", modified);
                string             query  = "object HAVING outboundReferences(Name " + equalizer + " " + modifiedServiceName + ") AND " + groups + "object HAVING inboundReferences(Name " + nameEqualizer + " " + modifiedElementName + ")";
                var                InsightIncomingElements = InsightGetByGeneralIqlQuery(query);
                List <ObjectEntry> elementEntries          = new List <ObjectEntry>();
                foreach (var entry in InsightIncomingElements.objectEntries)
                {
                    if (!entry.name.Equals(graphElement.CurrentElement.name))
                    {
                        foreach (var attribute in entry.attributes)
                        {
                            if (attribute.objectTypeAttributeId == 1781 && attribute.ObjectAttributeValues != null && attribute.ObjectAttributeValues.Count > 0)
                            {
                                foreach (var attributeValue in attribute.ObjectAttributeValues)
                                {
                                    if (attributeValue.displayValue.Equals(graph.Service.Name))
                                    {
                                        elementEntries.Add(entry);
                                    }
                                }
                            }
                        }
                    }
                }


                InsightIncomingElements.objectEntries = elementEntries;
                var GraphRouteIncomingElements = graphElement.IncomingElements;
                if (!Tools.IsValidIqlResult(InsightIncomingElements))
                {
                    logger.Debug("Error in the insight response received, assuming valid graph build");
                    return(true);
                }
                else if (InsightIncomingElements.objectEntries.Count != GraphRouteIncomingElements.Count)
                {
                    logger.Fatal("The graph element: " + graphElement.CurrentElement.name + " has " + InsightIncomingElements.objectEntries.Count + " incoming elements, while the insight has " + GraphRouteIncomingElements.Count + " incoming elements");
                    return(false);
                }
                else
                {
                    // gather all name of the insight incoming element list and graph incoming element list
                    foreach (var entry in InsightIncomingElements.objectEntries)
                    {
                        insightIncomingElementNames.Add(entry.name);
                    }
                    foreach (var incomingGraphElement in graphElement.IncomingElements)
                    {
                        graphElementIncomingElementNames.Add(incomingGraphElement.CurrentElement.name);
                    }

                    // According to the Discreet mathematics law of equality, if two sets A,B where A<=b and b<=A then A=B.
                    // this is checked below for the incoming element found in inisght in comparison to the realtionship built in the graph route
                    foreach (var incomingGraphElementName in graphElementIncomingElementNames)
                    {
                        if (insightIncomingElementNames.Count > 0 && !insightIncomingElementNames.Contains(incomingGraphElementName))
                        {
                            logger.Error("The graph element: {0} has an extra element: {1}", graphElement.CurrentElement.name, incomingGraphElementName);
                            return(false);
                        }
                    }
                    foreach (var incomingInsightElementName in insightIncomingElementNames)
                    {
                        if (graphElementIncomingElementNames.Count > 0 && !graphElementIncomingElementNames.Contains(incomingInsightElementName))
                        {
                            logger.Error("The graph element: {0} has a missing element: {1}", graphElement.CurrentElement.name, incomingInsightElementName);
                            return(false);
                        }
                    }
                }
            }
            return(ans);
        }