Пример #1
0
 /// <summary>
 /// Check if the IQl result and its members are not null.
 /// Such a case can happen if there is an error with the confluence route of the service due to uncorrect relationships between Inisght objects.
 /// </summary>
 /// <param name="result"></param>
 /// <returns></returns>
 public static bool IsValidIqlResult(IqlApiResult result)
 {
     return(result != null && (result.objectEntries != null) && (result.objectTypeAttributes != null));
 }
Пример #2
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;
            }
        }
Пример #3
0
        /// <summary> </summary>
        public Service(IqlApiResult service, NLog.Logger logger, string originalUUID)

        {
            if (service != null && service.objectEntries != null && service.objectEntries.Count > 0)
            {
                ObjectEntry selectedEntry = service.objectEntries[0];
                if (service.objectEntries.Count > 1)
                {
                    foreach (var entry in service.objectEntries)
                    {
                        string name = entry.label;
                        if (name.Length - originalUUID.Length >= 0 && name.Length - originalUUID.Length <= 0)
                        {
                            selectedEntry = entry;
                        }
                    }
                }
                AttributeNamesByIds = new Dictionary <string, int>();
                AttributeByIds      = new Dictionary <int, ObjectAttribute>();
                AttributeIdsByNames = new Dictionary <int, string>();
                AttributeTypesByIds = new Dictionary <int, ObjectTypeAttribute>();
                foreach (var attribute in selectedEntry.attributes)
                {
                    AttributeByIds.Add(attribute.objectTypeAttributeId, attribute);
                }
                foreach (var typeAttribute in service.objectTypeAttributes)
                {
                    AttributeNamesByIds.Add(typeAttribute.name, typeAttribute.id);
                    AttributeIdsByNames.Add(typeAttribute.id, typeAttribute.name);
                    AttributeTypesByIds.Add(typeAttribute.id, typeAttribute);
                    bool                        hasThisAttribute = AttributeByIds.ContainsKey(typeAttribute.id);
                    ObjectAttribute             attribute        = AttributeByIds[typeAttribute.id];
                    List <ObjectAttributeValue> attributeValues  = attribute.ObjectAttributeValues;

                    // if all above values are valid then set fields
                    if (typeAttribute != null && AttributeByIds != null && hasThisAttribute && attribute != null &&
                        attributeValues != null && attributeValues.Count > 0 && attributeValues[0] != null)
                    {
                        switch (typeAttribute.name)
                        {
                        case "Key":
                            Key = AttributeByIds[typeAttribute.id].ObjectAttributeValues[0].displayValue;
                            break;

                        case "Name":
                            Name = AttributeByIds[typeAttribute.id].ObjectAttributeValues[0].displayValue;
                            break;

                        case "Service Confluence URL":
                            ConfluenceURL = AttributeByIds[typeAttribute.id].ObjectAttributeValues[0].displayValue;
                            break;

                        case "Status":
                            Status = AttributeByIds[typeAttribute.id].ObjectAttributeValues[0].displayValue;
                            break;

                        case "Broadcast Time":
                            BroadcastTime = AttributeByIds[typeAttribute.id].ObjectAttributeValues[0].displayValue;
                            break;

                        case "Client VPN":
                            ClientVPN = Convert.ToBoolean(typeAttribute.Label);
                            break;

                        case "UUID/TKSID":
                            UUID = AttributeByIds[typeAttribute.id].ObjectAttributeValues[0].displayValue;
                            break;

                        case "Service Owner":
                            ServiceOwner = AttributeByIds[typeAttribute.id].ObjectAttributeValues[0].displayValue;
                            break;

                        case "Content Type":
                            ContentType = AttributeByIds[typeAttribute.id].ObjectAttributeValues[0].displayValue;
                            break;

                        case "Service Category":
                            ServiceCategory = AttributeByIds[typeAttribute.id].ObjectAttributeValues[0].displayValue;
                            break;

                        case "Distribution Channel":
                            DistributionChannel = AttributeByIds[typeAttribute.id].ObjectAttributeValues[0].displayValue;
                            break;

                        case "Service Role":
                            ServiceRole = AttributeByIds[typeAttribute.id].ObjectAttributeValues[0].displayValue;
                            break;

                        case "Service Remarks(Customer Service)":
                            ServiceRemarks = AttributeByIds[typeAttribute.id].ObjectAttributeValues[0].displayValue;
                            break;

                        case "Start of Service":
                            StartofService = AttributeByIds[typeAttribute.id].ObjectAttributeValues[0].displayValue;
                            break;

                        case "End of Service":
                            EndofService = AttributeByIds[typeAttribute.id].ObjectAttributeValues[0].displayValue;
                            break;

                        case "Service Documentation Approved":
                            EndofService = AttributeByIds[typeAttribute.id].ObjectAttributeValues[0].displayValue;
                            break;

                        default:
                            break;
                        }
                    }
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Constructs a graph containing raw and parsed information of the insight API result
        /// </summary>
        /// <param name="root"> the element list API result</param>
        /// <param name="service">the service get API result</param>
        /// <param name="_debug"> indicated whether the program should run in debug mode</param>
        /// <param name="uuid"> the name of the service to build a graph for</param>
        public ServiceGraph(IqlApiResult root, IqlApiResult service, bool _debug, string uuid)
        {
            debug        = _debug;
            logger       = NLog.LogManager.GetCurrentClassLogger();
            this.Service = new Service(service, logger, uuid);
            if (root == null || service.objectEntries == null || service.objectTypeAttributes == null)
            {
                return;
            }
            if (root.objectEntries == null || root.objectTypeAttributes == null)
            {
                ElementMemberIsNull = true;
                return;
            }
            this.RouteElements                 = root.objectEntries;
            this.RouteTypeAttributes           = root.objectTypeAttributes;
            this.ElementIncomingElementIndexes = new HashSet <int> [root.objectEntries.Count];
            this.ServiceElementNameList        = new Dictionary <string, int>();
            this.ObjectAttributeTypesById      = new Dictionary <int, string>();
            this.IqlApiResult = root;
            bool initSuccess           = true;
            bool incominElementSuccess = true;
            bool soureSetSuccess       = true;
            bool buildGraphSuccess     = true;

            try
            {
                logger.Debug("Starting the data initialization......");
                InitData();
                logger.Debug("Data initialization completed");
            }
            catch (Exception e)
            {
                logger.Error("initialization failed " + Service.Name + "\n" + e.Message);
                initSuccess = false;
            }
            try
            {
                logger.Debug("Setting Incoming elements......");
                FindIncomingElements();
                logger.Debug("Incoming elements setting completed");
            }
            catch (Exception e)
            {
                logger.Error("Setting Incoming elements failed " + Service.Name + "\n" + e.Message);
                incominElementSuccess = false;
            }
            try
            {
                logger.Debug("Setting sources......");
                this.Sources = FindSources();
                logger.Debug("source setting completed");
            }
            catch (Exception e)
            {
                logger.Error("Setting sources failed" + "\n" + e.Message);
                soureSetSuccess = false;
            }
            try
            {
                logger.Debug("Starting the graph build......");
                BuildServiceGraph();
                logger.Debug("graph build completed");
            }
            catch (Exception e)
            {
                logger.Error("graph build failed" + "\n" + e.Message);
                buildGraphSuccess = false;
            }

            this.constructorSuceeded = initSuccess && incominElementSuccess && soureSetSuccess && buildGraphSuccess;
        }