Search in sources :

Example 46 with TeiidRuntimeException

use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.

the class AliasGenerator method recontextGroup.

/**
 * @param symbol
 */
private String recontextGroup(GroupSymbol symbol, boolean virtual) {
    String newAlias = null;
    while (true) {
        if (virtual) {
            newAlias = view_prefix + viewIndex++;
        } else {
            newAlias = table_prefix + groupIndex++;
        }
        if (correlationGroups == null || !correlationGroups.contains(newAlias)) {
            break;
        }
    }
    if (this.aliasMapping != null && symbol.getDefinition() != null) {
        String oldAlias = this.aliasMapping.get(symbol.getName());
        if (oldAlias != null) {
            newAlias = oldAlias;
            if (newAlias.startsWith(table_prefix) || newAlias.startsWith(view_prefix)) {
                try {
                    Integer.parseInt(newAlias.substring(2, newAlias.length()));
                    throw new TeiidRuntimeException(new QueryPlannerException(QueryPlugin.Event.TEIID31127, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31127, newAlias)));
                } catch (NumberFormatException e) {
                }
            }
        }
    }
    visitor.namingContext.groupNames.put(symbol.getName(), newAlias);
    return newAlias;
}
Also used : TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) QueryPlannerException(org.teiid.api.exception.query.QueryPlannerException)

Example 47 with TeiidRuntimeException

use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.

the class JGroupsObjectReplicator method replicate.

@Override
public <T, S> T replicate(String mux_id, Class<T> iface, final S object, long startTimeout) throws Exception {
    Channel channel = channelFactory.createChannel(mux_id);
    // To keep the order of methods same at all the nodes.
    TreeMap<String, Method> methods = new TreeMap<String, Method>();
    for (Method method : iface.getMethods()) {
        if (method.getAnnotation(Replicated.class) == null) {
            continue;
        }
        methods.put(method.toGenericString(), method);
    }
    final HashMap<Method, Short> methodMap = new HashMap<Method, Short>();
    final ArrayList<Method> methodList = new ArrayList<Method>();
    for (String method : methods.keySet()) {
        methodList.add(methods.get(method));
        methodMap.put(methods.get(method), (short) (methodList.size() - 1));
    }
    Method hasState = ReplicatedObject.class.getMethod(HAS_STATE, new Class<?>[] { Serializable.class });
    methodList.add(hasState);
    methodMap.put(hasState, (short) (methodList.size() - 1));
    Method sendState = JGroupsObjectReplicator.Streaming.class.getMethod(SEND_STATE, new Class<?>[] { Serializable.class, Address.class });
    methodList.add(sendState);
    methodMap.put(sendState, (short) (methodList.size() - 1));
    // add in streaming methods
    Method createState = JGroupsObjectReplicator.Streaming.class.getMethod(CREATE_STATE, new Class<?>[] { Serializable.class });
    methodList.add(createState);
    methodMap.put(createState, (short) (methodList.size() - 1));
    Method buildState = JGroupsObjectReplicator.Streaming.class.getMethod(BUILD_STATE, new Class<?>[] { Serializable.class, byte[].class });
    methodList.add(buildState);
    methodMap.put(buildState, (short) (methodList.size() - 1));
    Method finishState = JGroupsObjectReplicator.Streaming.class.getMethod(FINISH_STATE, new Class<?>[] { Serializable.class });
    methodList.add(finishState);
    methodMap.put(finishState, (short) (methodList.size() - 1));
    ReplicatedInvocationHandler<S> proxy = new ReplicatedInvocationHandler<S>(object, methodMap);
    /*
         * TODO: could have an object implement streaming
         * Override the normal handle method to support streaming
         */
    ReplicatorRpcDispatcher disp = new ReplicatorRpcDispatcher<S>(channel, proxy, proxy, object, object, methodMap, methodList);
    proxy.setDisp(disp);
    disp.setMethodLookup(new MethodLookup() {

        public Method findMethod(short id) {
            return methodList.get(id);
        }
    });
    T replicatedProxy = (T) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class[] { iface }, proxy);
    boolean success = false;
    try {
        channel.connect(mux_id);
        if (object instanceof ReplicatedObject) {
            ((ReplicatedObject) object).setAddress(channel.getAddress());
            proxy.pullState(null, null, null, startTimeout, startTimeout != 0 ? STATE_TIMEOUT : 0);
        }
        success = true;
        return replicatedProxy;
    } catch (Throwable e) {
        if (e instanceof Exception) {
            throw (Exception) e;
        }
        throw new TeiidRuntimeException(RuntimePlugin.Event.TEIID40104, e);
    } finally {
        if (!success) {
            channel.close();
        } else {
            synchronized (disp) {
                // mark as initialized so that state can be pulled if needed
                disp.initialized = true;
            }
        }
    }
}
Also used : Replicated(org.teiid.Replicated) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ArrayList(java.util.ArrayList) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) MethodLookup(org.jgroups.blocks.MethodLookup) Channel(org.jgroups.Channel) Method(java.lang.reflect.Method) TreeMap(java.util.TreeMap) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ReplicatedObject(org.teiid.query.ReplicatedObject)

Example 48 with TeiidRuntimeException

use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.

the class EmbeddedConfiguration method getCacheFactory.

public CacheFactory getCacheFactory() {
    if (this.cacheFactory == null) {
        try {
            cacheManager = new DefaultCacheManager(this.infinispanConfigFile, true);
            for (String cacheName : cacheManager.getCacheNames()) {
                if (getTransactionManager() != null) {
                    setCacheTransactionManger(cacheName);
                }
                cacheManager.startCache(cacheName);
            }
            this.cacheFactory = new InfinispanCacheFactory(cacheManager, this.getClass().getClassLoader());
        } catch (IOException e) {
            throw new TeiidRuntimeException(RuntimePlugin.Event.TEIID40100, e);
        }
    }
    return this.cacheFactory;
}
Also used : DefaultCacheManager(org.infinispan.manager.DefaultCacheManager) InfinispanCacheFactory(org.teiid.cache.infinispan.InfinispanCacheFactory) IOException(java.io.IOException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException)

Example 49 with TeiidRuntimeException

use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.

the class EmbeddedServer method start.

public synchronized void start(@SuppressWarnings("hiding") EmbeddedConfiguration config) {
    if (running != null) {
        throw new IllegalStateException();
    }
    this.dqp.setLocalProfile(this.embeddedProfile);
    this.shutdownListener.setBootInProgress(true);
    this.config = config;
    System.setProperty("jboss.node.name", config.getNodeName() == null ? "localhost" : config.getNodeName());
    this.cmr.setProvider(this);
    this.eventDistributorFactoryService = new EmbeddedEventDistributorFactoryService();
    this.eventDistributorFactoryService.start();
    this.dqp.setEventDistributor(this.eventDistributorFactoryService.getReplicatedEventDistributor());
    // $NON-NLS-1$
    this.scheduler = Executors.newScheduledThreadPool(config.getMaxAsyncThreads(), new NamedThreadFactory("Asynch Worker"));
    this.replicator = config.getObjectReplicator();
    if (this.replicator == null && config.getJgroupsConfigFile() != null) {
        channelFactory = new SimpleChannelFactory(config);
        this.replicator = new JGroupsObjectReplicator(channelFactory, this.scheduler);
        try {
            this.nodeTracker = new NodeTracker(channelFactory.createChannel("teiid-node-tracker"), config.getNodeName()) {

                @Override
                public ScheduledExecutorService getScheduledExecutorService() {
                    return scheduler;
                }
            };
        } catch (Exception e) {
            LogManager.logError(LogConstants.CTX_RUNTIME, e, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40089));
        }
    }
    this.eventDistributorFactoryService = new EmbeddedEventDistributorFactoryService();
    // must be called after the replicator is set
    this.eventDistributorFactoryService.start();
    this.dqp.setEventDistributor(this.eventDistributorFactoryService.getReplicatedEventDistributor());
    if (config.getTransactionManager() == null) {
        LogManager.logInfo(LogConstants.CTX_RUNTIME, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40089));
        this.transactionService.setTransactionManager((TransactionManager) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class<?>[] { TransactionManager.class }, new InvocationHandler() {

            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                throw new UnsupportedOperationException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40089));
            }
        }));
    } else {
        this.transactionService.setDetectTransactions(true);
        this.transactionService.setTransactionManager(config.getTransactionManager());
    }
    if (config.getSecurityHelper() != null) {
        this.sessionService.setSecurityHelper(config.getSecurityHelper());
    } else {
        this.sessionService.setSecurityHelper(new DoNothingSecurityHelper());
    }
    if (config.getSecurityDomain() != null) {
        this.sessionService.setSecurityDomain(config.getSecurityDomain());
    } else {
        // $NON-NLS-1$
        this.sessionService.setSecurityDomain("teiid-security");
    }
    this.sessionService.setVDBRepository(repo);
    setBufferManagerProperties(config);
    BufferService bs = getBufferService();
    this.dqp.setBufferManager(bs.getBufferManager());
    startVDBRepository();
    // $NON-NLS-1$
    rs = new SessionAwareCache<CachedResults>("resultset", config.getCacheFactory(), SessionAwareCache.Type.RESULTSET, config.getMaxResultSetCacheStaleness());
    // $NON-NLS-1$
    ppc = new SessionAwareCache<PreparedPlan>("preparedplan", config.getCacheFactory(), SessionAwareCache.Type.PREPAREDPLAN, 0);
    rs.setTupleBufferCache(bs.getTupleBufferCache());
    this.dqp.setResultsetCache(rs);
    ppc.setTupleBufferCache(bs.getTupleBufferCache());
    this.dqp.setPreparedPlanCache(ppc);
    this.dqp.setTransactionService((TransactionService) LogManager.createLoggingProxy(LogConstants.CTX_TXN_LOG, this.transactionService, new Class[] { TransactionService.class }, MessageLevel.DETAIL, Thread.currentThread().getContextClassLoader()));
    this.dqp.start(config);
    this.sessionService.setDqp(this.dqp);
    this.services.setSecurityHelper(this.sessionService.getSecurityHelper());
    if (this.config.getAuthenticationType() != null) {
        this.services.setAuthenticationType(this.config.getAuthenticationType());
        this.sessionService.setAuthenticationType(this.config.getAuthenticationType());
    }
    this.sessionService.start();
    this.services.setVDBRepository(this.repo);
    this.materializationMgr = getMaterializationManager();
    this.repo.addListener(this.materializationMgr);
    this.repo.setAllowEnvFunction(this.config.isAllowEnvFunction());
    if (this.nodeTracker != null) {
        this.nodeTracker.addNodeListener(this.materializationMgr);
    }
    this.logon = new LogonImpl(sessionService, null);
    services.registerClientService(ILogon.class, logon, LogConstants.CTX_SECURITY);
    DQP dqpProxy = DQP.class.cast(Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class[] { DQP.class }, new SessionCheckingProxy(dqp, LogConstants.CTX_DQP, MessageLevel.TRACE)));
    services.registerClientService(DQP.class, dqpProxy, LogConstants.CTX_DQP);
    initDriver();
    List<SocketConfiguration> transports = config.getTransports();
    if (transports != null && !transports.isEmpty()) {
        for (SocketConfiguration socketConfig : transports) {
            SocketListener socketConnection = startTransport(socketConfig, bs.getBufferManager(), config.getMaxODBCLobSizeAllowed());
            if (socketConfig.getSSLConfiguration() != null) {
                try {
                    socketConfig.getSSLConfiguration().getServerSSLEngine();
                } catch (Exception e) {
                    throw new TeiidRuntimeException(e);
                }
            }
            this.transports.add(socketConnection);
        }
    }
    this.shutdownListener.setBootInProgress(false);
    this.shutdownListener.started();
    running = true;
}
Also used : TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) JGroupsObjectReplicator(org.teiid.replication.jgroups.JGroupsObjectReplicator) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) DQP(org.teiid.client.DQP) NamedThreadFactory(org.teiid.core.util.NamedThreadFactory) BufferService(org.teiid.dqp.service.BufferService) Method(java.lang.reflect.Method) InvocationHandler(java.lang.reflect.InvocationHandler) ConnectorManagerException(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository.ConnectorManagerException) InvalidSessionException(org.teiid.client.security.InvalidSessionException) XMLStreamException(javax.xml.stream.XMLStreamException) TeiidSQLException(org.teiid.jdbc.TeiidSQLException) ConnectionException(org.teiid.net.ConnectionException) SQLException(java.sql.SQLException) TranslatorException(org.teiid.translator.TranslatorException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) URISyntaxException(java.net.URISyntaxException) TeiidException(org.teiid.core.TeiidException) SAXException(org.xml.sax.SAXException) VirtualDatabaseException(org.teiid.deployers.VirtualDatabaseException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) CachedResults(org.teiid.dqp.internal.process.CachedResults) PreparedPlan(org.teiid.dqp.internal.process.PreparedPlan)

Example 50 with TeiidRuntimeException

use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.

the class TranslatorUtil method convert.

private static Object convert(Object instance, Method method, TranslatorProperty prop) {
    Class<?> type = method.getReturnType();
    String[] allowedValues = null;
    Method getter = null;
    boolean readOnly = prop.readOnly();
    if (type == Void.TYPE) {
        // check for setter
        Class<?>[] types = method.getParameterTypes();
        if (types.length != 1) {
            throw new TeiidRuntimeException(RuntimePlugin.Event.TEIID40029, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40029, method));
        }
        type = types[0];
        try {
            // $NON-NLS-1$
            getter = instance.getClass().getMethod("get" + method.getName(), (Class[]) null);
        } catch (Exception e) {
            try {
                // $NON-NLS-1$
                getter = instance.getClass().getMethod("get" + method.getName().substring(3), (Class[]) null);
            } catch (Exception e1) {
            // can't find getter, won't set the default value
            }
        }
    } else if (method.getParameterTypes().length != 0) {
        throw new TeiidRuntimeException(RuntimePlugin.Event.TEIID40029, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40029, method));
    } else {
        getter = method;
        try {
            TranslatorUtil.getSetter(instance.getClass(), method);
        } catch (Exception e) {
            if (!readOnly) {
                throw new TeiidRuntimeException(RuntimePlugin.Event.TEIID40146, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40146, method));
            }
        }
    }
    Object defaultValue = null;
    if (prop.required()) {
        if (prop.advanced()) {
            throw new TeiidRuntimeException(RuntimePlugin.Event.TEIID40031, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40031, method));
        }
    } else if (getter != null) {
        try {
            defaultValue = getter.invoke(instance, (Object[]) null);
        } catch (Exception e) {
        // no simple default value
        }
    }
    if (type.isEnum()) {
        Object[] constants = type.getEnumConstants();
        allowedValues = new String[constants.length];
        for (int i = 0; i < constants.length; i++) {
            allowedValues[i] = ((Enum<?>) constants[i]).name();
        }
        type = String.class;
        if (defaultValue != null) {
            defaultValue = ((Enum<?>) defaultValue).name();
        }
    }
    if (!(defaultValue instanceof Serializable)) {
        // TODO
        defaultValue = null;
    }
    return defaultValue;
}
Also used : Serializable(java.io.Serializable) Method(java.lang.reflect.Method) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) ConnectorManagerException(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository.ConnectorManagerException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) TeiidException(org.teiid.core.TeiidException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)103 IOException (java.io.IOException)27 TeiidComponentException (org.teiid.core.TeiidComponentException)22 TeiidException (org.teiid.core.TeiidException)22 ArrayList (java.util.ArrayList)20 TeiidProcessingException (org.teiid.core.TeiidProcessingException)17 SQLException (java.sql.SQLException)11 ObjectInputStream (java.io.ObjectInputStream)9 HashMap (java.util.HashMap)9 InputStream (java.io.InputStream)7 Map (java.util.Map)7 Test (org.junit.Test)7 QueryMetadataException (org.teiid.api.exception.query.QueryMetadataException)7 ObjectOutputStream (java.io.ObjectOutputStream)6 List (java.util.List)6 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)6 XMLStreamException (javax.xml.stream.XMLStreamException)5 QueryPlannerException (org.teiid.api.exception.query.QueryPlannerException)5 JsonObject (com.couchbase.client.java.document.json.JsonObject)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4