Ejemplo n.º 1
0
        internal static FragmentEventType GetFragmentEventTypeForField(
            Schema fieldSchema,
            EventAdapterService eventAdapterService)
        {
            Schema recordSchema;
            bool   indexed = false;

            if (fieldSchema.Tag == Schema.Type.Record)
            {
                recordSchema = fieldSchema;
            }
            else if (fieldSchema.Tag == Schema.Type.Array && fieldSchema.GetElementType().Tag == Schema.Type.Record)
            {
                recordSchema = fieldSchema.GetElementType();
                indexed      = true;
            }
            else
            {
                return(null);
            }

            // See if there is an existing type
            EventType existing = eventAdapterService.GetEventTypeByName(recordSchema.Name);

            if (existing != null && existing is AvroEventType)
            {
                return(new FragmentEventType(existing, indexed, false));
            }

            EventType fragmentType = eventAdapterService.AddAvroType(
                recordSchema.Name, new ConfigurationEventTypeAvro().SetAvroSchema(recordSchema), false, false, false,
                false, false);

            return(new FragmentEventType(fragmentType, indexed, false));
        }
Ejemplo n.º 2
0
 public void AddEventTypeAvro(string eventTypeName, ConfigurationEventTypeAvro avro)
 {
     CheckTableExists(eventTypeName);
     try {
         _eventAdapterService.AddAvroType(eventTypeName, avro, false, true, true, false, false);
     } catch (EventAdapterException t) {
         throw new ConfigurationException(t.Message, t);
     }
 }
Ejemplo n.º 3
0
        public static SelectExprProcessor Create(
            ICollection <int> assignedTypeNumberStack,
            int statementId,
            string statementName,
            string[] streamNames,
            EventType[] streamTypes,
            EventAdapterService eventAdapterService,
            InsertIntoDesc insertIntoDesc,
            SelectExprEventTypeRegistry selectExprEventTypeRegistry,
            EngineImportService engineImportService,
            Attribute[] annotations,
            ConfigurationInformation configuration,
            TableService tableService,
            string engineURI)

        {
            if ((streamNames.Length < 2) || (streamTypes.Length < 2) || (streamNames.Length != streamTypes.Length))
            {
                throw new ArgumentException(
                          "Stream names and types parameter length is invalid, expected use of this class is for join statements");
            }

            // Create EventType of result join events
            var  selectProperties   = new LinkedHashMap <string, Object>();
            var  streamTypesWTables = new EventType[streamTypes.Length];
            bool hasTables          = false;

            for (int i = 0; i < streamTypes.Length; i++)
            {
                streamTypesWTables[i] = streamTypes[i];
                string tableName = TableServiceUtil.GetTableNameFromEventType(streamTypesWTables[i]);
                if (tableName != null)
                {
                    hasTables             = true;
                    streamTypesWTables[i] = tableService.GetTableMetadata(tableName).PublicEventType;
                }
                selectProperties.Put(streamNames[i], streamTypesWTables[i]);
            }

            // If we have a name for this type, add it
            EventUnderlyingType representation = EventRepresentationUtil.GetRepresentation(
                annotations, configuration, AssignedType.NONE);
            EventType resultEventType;

            SelectExprProcessor processor = null;

            if (insertIntoDesc != null)
            {
                EventType existingType = eventAdapterService.GetEventTypeByName(insertIntoDesc.EventTypeName);
                if (existingType != null)
                {
                    processor = SelectExprInsertEventBeanFactory.GetInsertUnderlyingJoinWildcard(
                        eventAdapterService, existingType, streamNames, streamTypesWTables, engineImportService,
                        statementName, engineURI);
                }
            }

            if (processor == null)
            {
                if (insertIntoDesc != null)
                {
                    try
                    {
                        if (representation == EventUnderlyingType.MAP)
                        {
                            resultEventType = eventAdapterService.AddNestableMapType(
                                insertIntoDesc.EventTypeName, selectProperties, null, false, false, false, false, true);
                        }
                        else if (representation == EventUnderlyingType.OBJECTARRAY)
                        {
                            resultEventType = eventAdapterService.AddNestableObjectArrayType(
                                insertIntoDesc.EventTypeName, selectProperties, null, false, false, false, false, true,
                                false, null);
                        }
                        else if (representation == EventUnderlyingType.AVRO)
                        {
                            resultEventType = eventAdapterService.AddAvroType(
                                insertIntoDesc.EventTypeName, selectProperties, false, false, false, false, true,
                                annotations, null, statementName, engineURI);
                        }
                        else
                        {
                            throw new IllegalStateException("Unrecognized code " + representation);
                        }
                        selectExprEventTypeRegistry.Add(resultEventType);
                    }
                    catch (EventAdapterException ex)
                    {
                        throw new ExprValidationException(ex.Message, ex);
                    }
                }
                else
                {
                    if (representation == EventUnderlyingType.MAP)
                    {
                        resultEventType =
                            eventAdapterService.CreateAnonymousMapType(
                                statementId + "_join_" + CollectionUtil.ToString(assignedTypeNumberStack, "_"),
                                selectProperties, true);
                    }
                    else if (representation == EventUnderlyingType.OBJECTARRAY)
                    {
                        resultEventType =
                            eventAdapterService.CreateAnonymousObjectArrayType(
                                statementId + "_join_" + CollectionUtil.ToString(assignedTypeNumberStack, "_"),
                                selectProperties);
                    }
                    else if (representation == EventUnderlyingType.AVRO)
                    {
                        resultEventType =
                            eventAdapterService.CreateAnonymousAvroType(
                                statementId + "_join_" + CollectionUtil.ToString(assignedTypeNumberStack, "_"),
                                selectProperties, annotations, statementName, engineURI);
                    }
                    else
                    {
                        throw new IllegalStateException("Unrecognized enum " + representation);
                    }
                }
                if (resultEventType is ObjectArrayEventType)
                {
                    processor = new SelectExprJoinWildcardProcessorObjectArray(
                        streamNames, resultEventType, eventAdapterService);
                }
                else if (resultEventType is MapEventType)
                {
                    processor = new SelectExprJoinWildcardProcessorMap(
                        streamNames, resultEventType, eventAdapterService);
                }
                else if (resultEventType is AvroSchemaEventType)
                {
                    processor = eventAdapterService.EventAdapterAvroHandler.GetOutputFactory().MakeJoinWildcard(
                        streamNames, resultEventType, eventAdapterService);
                }
            }

            if (!hasTables)
            {
                return(processor);
            }
            return(new SelectExprJoinWildcardProcessorTableRows(streamTypes, processor, tableService));
        }
        /// <summary>
        /// Initialize event adapter service for config snapshot.
        /// </summary>
        /// <param name="eventAdapterService">is events adapter</param>
        /// <param name="configSnapshot">is the config snapshot</param>
        /// <param name="engineImportService">engine import service</param>
        /// <param name="resourceManager">The resource manager.</param>
        /// <exception cref="ConfigurationException">
        /// Error configuring engine: " + ex.Message
        /// or
        /// Error configuring engine: " + ex.Message
        /// or
        /// or
        /// Error configuring engine: " + ex.Message
        /// or
        /// Error configuring engine, dependency graph between map type names is circular: " + e.Message
        /// or
        /// Error configuring engine: " + ex.Message
        /// or
        /// Error configuring engine, dependency graph between object array type names is circular: " +
        ///                     e.Message
        /// or
        /// Error configuring engine: " + ex.Message
        /// or
        /// Failed to load plug-in event representation class '" + className + "'
        /// or
        /// Failed to instantiate plug-in event representation class '" + className +
        ///                         "' via default constructor
        /// or
        /// Failed to instantiate plug-in event representation class '" + className +
        ///                         "' via default constructor
        /// or
        /// Illegal access to instantiate plug-in event representation class '" + className +
        ///                         "' via default constructor
        /// or
        /// Illegal access to instantiate plug-in event representation class '" + className +
        ///                         "' via default constructor
        /// or
        /// Plug-in event representation class '" + className +
        ///                         "' does not implement the required interface " + typeof (PlugInEventRepresentation).Name
        /// or
        /// Plug-in event representation class '" + className + "' and URI '" + eventRepURI +
        ///                         "' did not initialize correctly : " + e.Message
        /// </exception>
        internal static void Init(
            EventAdapterService eventAdapterService,
            ConfigurationInformation configSnapshot,
            EngineImportService engineImportService,
            IResourceManager resourceManager)
        {
            // Extract legacy event type definitions for each event type name, if supplied.
            //
            // We supply this information as setup information to the event adapter service
            // to allow discovery of superclasses and interfaces during event type construction for bean events,
            // such that superclasses and interfaces can use the legacy type definitions.
            var classLegacyInfo = new Dictionary <string, ConfigurationEventTypeLegacy>();

            foreach (var entry in configSnapshot.EventTypeNames)
            {
                var typeName  = entry.Key;
                var className = entry.Value;
                var legacyDef = configSnapshot.EventTypesLegacy.Get(typeName);
                if (legacyDef != null)
                {
                    classLegacyInfo.Put(className, legacyDef);
                }
            }
            eventAdapterService.TypeLegacyConfigs = classLegacyInfo;
            eventAdapterService.DefaultPropertyResolutionStyle =
                configSnapshot.EngineDefaults.EventMeta.ClassPropertyResolutionStyle;
            eventAdapterService.DefaultAccessorStyle = configSnapshot.EngineDefaults.EventMeta.DefaultAccessorStyle;

            foreach (var typeNamespace in configSnapshot.EventTypeAutoNamePackages)
            {
                eventAdapterService.AddAutoNamePackage(typeNamespace);
            }

            // Add from the configuration the event class names
            var typeNames = configSnapshot.EventTypeNames;

            foreach (var entry in typeNames)
            {
                // Add class
                try
                {
                    var typeName = entry.Key;
                    eventAdapterService.AddBeanType(typeName, entry.Value, false, true, true, true);
                }
                catch (EventAdapterException ex)
                {
                    throw new ConfigurationException("Error configuring engine: " + ex.Message, ex);
                }
            }

            // Add from the configuration the Java event class names
            var avroNames = configSnapshot.EventTypesAvro;

            foreach (var entry in avroNames)
            {
                try
                {
                    eventAdapterService.AddAvroType(entry.Key, entry.Value, true, true, true, false, false);
                }
                catch (EventAdapterException ex)
                {
                    throw new ConfigurationException("Error configuring engine: " + ex.Message, ex);
                }
            }

            // Add from the configuration the XML DOM names and type def
            var xmlDOMNames = configSnapshot.EventTypesXMLDOM;

            foreach (var entry in xmlDOMNames)
            {
                SchemaModel schemaModel = null;
                if ((entry.Value.SchemaResource != null) || (entry.Value.SchemaText != null))
                {
                    try
                    {
                        schemaModel = XSDSchemaMapper.LoadAndMap(
                            entry.Value.SchemaResource,
                            entry.Value.SchemaText,
                            engineImportService,
                            resourceManager);
                    }
                    catch (Exception ex)
                    {
                        throw new ConfigurationException(ex.Message, ex);
                    }
                }

                // Add XML DOM type
                try
                {
                    eventAdapterService.AddXMLDOMType(entry.Key, entry.Value, schemaModel, true);
                }
                catch (EventAdapterException ex)
                {
                    throw new ConfigurationException("Error configuring engine: " + ex.Message, ex);
                }
            }

            // Add maps in dependency order such that supertypes are added before subtypes
            ICollection <string> dependentMapOrder;

            try
            {
                var typesReferences = ToTypesReferences(configSnapshot.MapTypeConfigurations);
                dependentMapOrder = GraphUtil.GetTopDownOrder(typesReferences);
            }
            catch (GraphCircularDependencyException e)
            {
                throw new ConfigurationException(
                          "Error configuring engine, dependency graph between map type names is circular: " + e.Message, e);
            }

            var mapNames         = configSnapshot.EventTypesMapEvents;
            var nestableMapNames = configSnapshot.EventTypesNestableMapEvents;

            dependentMapOrder.AddAll(mapNames.Keys);
            dependentMapOrder.AddAll(nestableMapNames.Keys);
            try
            {
                foreach (var mapName in dependentMapOrder)
                {
                    var mapConfig          = configSnapshot.MapTypeConfigurations.Get(mapName);
                    var propertiesUnnested = mapNames.Get(mapName);
                    if (propertiesUnnested != null)
                    {
                        var propertyTypes         = CreatePropertyTypes(propertiesUnnested, engineImportService);
                        var propertyTypesCompiled = EventTypeUtility.CompileMapTypeProperties(
                            propertyTypes, eventAdapterService);
                        eventAdapterService.AddNestableMapType(
                            mapName, propertyTypesCompiled, mapConfig, true, true, true, false, false);
                    }

                    var propertiesNestable = nestableMapNames.Get(mapName);
                    if (propertiesNestable != null)
                    {
                        var propertiesNestableCompiled = EventTypeUtility.CompileMapTypeProperties(
                            propertiesNestable, eventAdapterService);
                        eventAdapterService.AddNestableMapType(
                            mapName, propertiesNestableCompiled, mapConfig, true, true, true, false, false);
                    }
                }
            }
            catch (EventAdapterException ex)
            {
                throw new ConfigurationException("Error configuring engine: " + ex.Message, ex);
            }

            // Add object-array in dependency order such that supertypes are added before subtypes
            ICollection <string> dependentObjectArrayOrder;

            try
            {
                var typesReferences = ToTypesReferences(configSnapshot.ObjectArrayTypeConfigurations);
                dependentObjectArrayOrder = GraphUtil.GetTopDownOrder(typesReferences);
            }
            catch (GraphCircularDependencyException e)
            {
                throw new ConfigurationException(
                          "Error configuring engine, dependency graph between object array type names is circular: " +
                          e.Message, e);
            }
            var nestableObjectArrayNames = configSnapshot.EventTypesNestableObjectArrayEvents;

            dependentObjectArrayOrder.AddAll(nestableObjectArrayNames.Keys);
            try
            {
                foreach (var objectArrayName in dependentObjectArrayOrder)
                {
                    var objectArrayConfig = configSnapshot.ObjectArrayTypeConfigurations.Get(objectArrayName);
                    var propertyTypes     = nestableObjectArrayNames.Get(objectArrayName);
                    propertyTypes = ResolveClassesForStringPropertyTypes(propertyTypes, engineImportService);
                    var propertyTypesCompiled = EventTypeUtility.CompileMapTypeProperties(
                        propertyTypes, eventAdapterService);
                    eventAdapterService.AddNestableObjectArrayType(
                        objectArrayName, propertyTypesCompiled, objectArrayConfig, true, true, true, false, false, false,
                        null);
                }
            }
            catch (EventAdapterException ex)
            {
                throw new ConfigurationException("Error configuring engine: " + ex.Message, ex);
            }

            // Add plug-in event representations
            var plugInReps = configSnapshot.PlugInEventRepresentation;

            foreach (var entry in plugInReps)
            {
                String className = entry.Value.EventRepresentationTypeName;
                Type   eventRepClass;
                try
                {
                    eventRepClass = TypeHelper.ResolveType(className);
                }
                catch (TypeLoadException ex)
                {
                    throw new ConfigurationException(
                              "Failed to load plug-in event representation class '" + className + "'", ex);
                }

                Object pluginEventRepObj;
                try
                {
                    pluginEventRepObj = Activator.CreateInstance(eventRepClass);
                }
                catch (TypeInstantiationException ex)
                {
                    throw new ConfigurationException(
                              "Failed to instantiate plug-in event representation class '" + className +
                              "' via default constructor", ex);
                }
                catch (TargetInvocationException ex)
                {
                    throw new ConfigurationException(
                              "Failed to instantiate plug-in event representation class '" + className +
                              "' via default constructor", ex);
                }
                catch (MethodAccessException ex)
                {
                    throw new ConfigurationException(
                              "Illegal access to instantiate plug-in event representation class '" + className +
                              "' via default constructor", ex);
                }
                catch (MemberAccessException ex)
                {
                    throw new ConfigurationException(
                              "Illegal access to instantiate plug-in event representation class '" + className +
                              "' via default constructor", ex);
                }

                if (!(pluginEventRepObj is PlugInEventRepresentation))
                {
                    throw new ConfigurationException(
                              "Plug-in event representation class '" + className +
                              "' does not implement the required interface " + typeof(PlugInEventRepresentation).Name);
                }

                var eventRepURI    = entry.Key;
                var pluginEventRep = (PlugInEventRepresentation)pluginEventRepObj;
                var initializer    = entry.Value.Initializer;
                var context        = new PlugInEventRepresentationContext(eventAdapterService, eventRepURI, initializer);

                try
                {
                    pluginEventRep.Init(context);
                    eventAdapterService.AddEventRepresentation(eventRepURI, pluginEventRep);
                }
                catch (Exception e)
                {
                    throw new ConfigurationException(
                              "Plug-in event representation class '" + className + "' and URI '" + eventRepURI +
                              "' did not initialize correctly : " + e.Message, e);
                }
            }

            // Add plug-in event type names
            var plugInNames = configSnapshot.PlugInEventTypes;

            foreach (var entry in plugInNames)
            {
                var name   = entry.Key;
                var config = entry.Value;
                eventAdapterService.AddPlugInEventType(
                    name, config.EventRepresentationResolutionURIs, config.Initializer);
            }
        }